Files
syncrow-app/lib/utils/helpers/misc_string_helpers.dart
Mohammad Salameh 80d424f114 Refactor code for consistency and readability
- Removed unused imports and commented-out code
- Updated class inheritance for AuthState subclasses
- Reorganized code structure for better readability
- Cleaned up debug print statements and replaced with dart:developer logs
2024-04-15 12:03:25 +03:00

67 lines
2.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:developer' as developer;
import 'dart:io';
class StringHelpers {
// TODO ( to Mohammad Salameh): convert this to extension method
static String enhanceFileName(File file) {
var fileName = " ";
final filePath = file.path;
developer.log(filePath);
final fileStringArray = filePath.split("/");
fileName = fileStringArray.last;
if (fileName.length > 20) {
// crop the name and keep the extension
final firstPart = fileName.substring(0, 17);
fileName = "$firstPart...";
}
return fileName;
}
static String returnEnglishStringFromArabicNumber(String arabicString) {
var englishStringNumber = arabicString;
englishStringNumber = englishStringNumber.replaceAll("٠", "0");
englishStringNumber = englishStringNumber.replaceAll("١", "1");
englishStringNumber = englishStringNumber.replaceAll("٢", "2");
englishStringNumber = englishStringNumber.replaceAll("٣", "3");
englishStringNumber = englishStringNumber.replaceAll("٤", "4");
englishStringNumber = englishStringNumber.replaceAll("٥", "5");
englishStringNumber = englishStringNumber.replaceAll("٦", "6");
englishStringNumber = englishStringNumber.replaceAll("٧", "7");
englishStringNumber = englishStringNumber.replaceAll("٨", "8");
englishStringNumber = englishStringNumber.replaceAll("٩", "9");
return englishStringNumber;
}
static String returnTheFirstThreeWords(String completeString) {
// We use this method to return a nice readable word that is shorter than 26 characters
// split the string to substrings with the space as the pattern
final arrayOfSubStrings = completeString.split(" ");
String newString = "";
// keep adding the substrings until 26 is reached
var index = 0;
while (newString.length < 20 && index < arrayOfSubStrings.length) {
newString = "$newString + ${arrayOfSubStrings[index]} ";
index++;
}
return newString;
}
static int getIntFromString(String? numberString) {
if (numberString != null) {
final numberInt = int.tryParse(numberString);
if (numberInt != null) {
return numberInt;
} else {
final numberDouble = double.tryParse(numberString);
if (numberDouble != null) {
return numberDouble.toInt();
} else {
return 0;
}
}
} else {
return 0;
}
}
}