getTruncatedFilenameWithDots method
String
getTruncatedFilenameWithDots(
)
Implementation
String getTruncatedFilenameWithDots() {
final uri = Uri.parse(this);
final segments = uri.pathSegments;
if (segments.isEmpty) {
return '';
}
String filenameWithExtension = segments.last.toLowerCase();
if (filenameWithExtension.length > 22) {
String extension = filenameWithExtension.split('.').last;
String baseName = filenameWithExtension.split('.').first;
// Calculate max length for base name to keep total length within 10 including ".."
int maxBaseLength = 22 - extension.length - 2; // Subtract 2 for ".."
// Ensure base name doesn't exceed calculated max length
if (maxBaseLength > 0) {
baseName = baseName.substring(0, maxBaseLength);
filenameWithExtension = '$baseName..$extension';
} else {
// If extension itself is too long or base name can't fit, truncate entire name to 10
filenameWithExtension = filenameWithExtension.substring(0, 22);
}
}
return filenameWithExtension;
}