108 lines
3.2 KiB
Dart
108 lines
3.2 KiB
Dart
typedef SCStringUtils = SCStringProcessor;
|
|
|
|
class SCStringProcessor {
|
|
static bool checkIfUrl(String str) {
|
|
if (str.startsWith("http://") || str.startsWith("https://")) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
///判断字符串是否为合法的Int
|
|
static bool validateInteger(String str) {
|
|
try {
|
|
int.parse(str);
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
///判断字符串是否为合法的Double
|
|
static bool validateDouble(String str) {
|
|
try {
|
|
double.parse(str);
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
///将文本转成数字
|
|
static int convertToInteger(String? str, {int defalut = -1}) {
|
|
if (str == null || str.isEmpty) {
|
|
return defalut;
|
|
}
|
|
var value = 0;
|
|
try {
|
|
value = int.parse(str);
|
|
// ignore: empty_catches
|
|
} catch (e) {}
|
|
return value;
|
|
}
|
|
|
|
static String formatNumericValue(num number) {
|
|
if (number >= 1000000) {
|
|
return '${(number / 1000000).toStringAsFixed(1)}M';
|
|
} else if (number >= 1000) {
|
|
return '${(number / 1000).toStringAsFixed(1)}K';
|
|
}
|
|
return number.toString();
|
|
}
|
|
|
|
static String formatCompactNumber(num number) {
|
|
final isNegative = number < 0;
|
|
final absValue = number.abs();
|
|
if (absValue < 10000) {
|
|
return '${isNegative ? '-' : ''}${absValue.toInt()}';
|
|
}
|
|
|
|
if (absValue >= 1000000000) {
|
|
return '${isNegative ? '-' : ''}${_trimCompactDecimal(absValue / 1000000000)}B';
|
|
}
|
|
if (absValue >= 1000000) {
|
|
return '${isNegative ? '-' : ''}${_trimCompactDecimal(absValue / 1000000)}M';
|
|
}
|
|
return '${isNegative ? '-' : ''}${_trimCompactDecimal(absValue / 1000)}K';
|
|
}
|
|
|
|
static String _trimCompactDecimal(num value) {
|
|
final fixed = value.toStringAsFixed(1);
|
|
return fixed.endsWith('.0') ? fixed.substring(0, fixed.length - 2) : fixed;
|
|
}
|
|
|
|
///检测文本是否有阿语
|
|
static bool containsArabicCharacters(String char) {
|
|
if (char.isEmpty) return false;
|
|
final code = char.runes.first;
|
|
|
|
// 阿拉伯语主要 Unicode 范围:
|
|
// 1. 阿拉伯语基本字符 (Arabic): U+0600 - U+06FF
|
|
// 2. 阿拉伯语补充 (Arabic Supplement): U+0750 - U+077F
|
|
// 3. 阿拉伯语扩展-A (Arabic Extended-A): U+08A0 - U+08FF
|
|
// 4. 阿拉伯语扩展-B (Arabic Extended-B): U+0870 - U+089F
|
|
// 5. 阿拉伯语表示形式-A (Arabic Presentation Forms-A): U+FB50 - U+FDFF
|
|
// 6. 阿拉伯语表示形式-B (Arabic Presentation Forms-B): U+FE70 - U+FEFF
|
|
|
|
return (
|
|
// 阿拉伯语基本字符
|
|
(code >= 0x0600 && code <= 0x06FF) ||
|
|
// 阿拉伯语补充
|
|
(code >= 0x0750 && code <= 0x077F) ||
|
|
// 阿拉伯语扩展-A
|
|
(code >= 0x08A0 && code <= 0x08FF) ||
|
|
// 阿拉伯语扩展-B
|
|
(code >= 0x0870 && code <= 0x089F) ||
|
|
// 阿拉伯语表示形式-A
|
|
(code >= 0xFB50 && code <= 0xFDFF) ||
|
|
// 阿拉伯语表示形式-B
|
|
(code >= 0xFE70 && code <= 0xFEFF));
|
|
}
|
|
|
|
/// 内部辅助方法,用于差异化代码结构
|
|
// ignore: unused_element
|
|
static void _di() {
|
|
// 空实现,仅用于差异化代码结构
|
|
}
|
|
}
|