2026-04-13 10:37:12 +02:00
|
|
|
extension MyStringExtensions on String? {
|
|
|
|
|
// Gestiamo anche il nullable per sicurezza
|
|
|
|
|
String myFormat() {
|
|
|
|
|
if (this == null || this!.trim().isEmpty) return '';
|
|
|
|
|
|
|
|
|
|
return this!
|
|
|
|
|
.trim()
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.split(' ')
|
|
|
|
|
.where((word) => word.isNotEmpty) // Evita problemi con doppi spazi
|
|
|
|
|
.map((word) {
|
|
|
|
|
if (word.contains('iphone') || word.contains('ipad')) {
|
|
|
|
|
return word.replaceFirst('ip', 'iP');
|
|
|
|
|
}
|
|
|
|
|
if (word.contains('imac')) {
|
|
|
|
|
return word.replaceFirst('im', 'iM');
|
|
|
|
|
}
|
|
|
|
|
return word[0].toUpperCase() + word.substring(1);
|
|
|
|
|
})
|
|
|
|
|
.join(' ');
|
|
|
|
|
}
|
2026-04-20 11:18:22 +02:00
|
|
|
|
|
|
|
|
String fileExtension() {
|
|
|
|
|
if (this == null || this!.trim().isEmpty) return '';
|
|
|
|
|
|
|
|
|
|
final parts = this!.split('.');
|
|
|
|
|
if (parts.length < 2) return ''; // Nessuna estensione trovata
|
|
|
|
|
|
|
|
|
|
return parts.last.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String fileNameWithoutExtension() {
|
|
|
|
|
if (this == null || this!.trim().isEmpty) return '';
|
2026-04-20 12:58:06 +02:00
|
|
|
this!.replaceAll(RegExp(r'[^a-zA-Z0-9\.\-]'), '_');
|
2026-04-20 11:18:22 +02:00
|
|
|
final parts = this!.split('.');
|
|
|
|
|
if (parts.length < 2) return this!; // Nessuna estensione trovata
|
|
|
|
|
|
|
|
|
|
return parts
|
|
|
|
|
.sublist(0, parts.length - 1)
|
|
|
|
|
.join('.'); // Ritorna tutto tranne l'ultima parte
|
|
|
|
|
}
|
2026-04-13 10:37:12 +02:00
|
|
|
}
|