mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00

- 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
67 lines
2.4 KiB
Dart
67 lines
2.4 KiB
Dart
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;
|
||
}
|
||
}
|
||
}
|