Files
flux/lib/core/utils/string_extensions.dart

43 lines
1.2 KiB
Dart
Raw Normal View History

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 '';
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
}