TF-3344 Handle separator when pasting list of mail addresses

This commit is contained in:
dab246
2024-12-24 14:14:52 +07:00
committed by Dat H. Pham
parent 6651d28d1e
commit 68b9291e68
3 changed files with 283 additions and 54 deletions
+33 -2
View File
@@ -1,10 +1,41 @@
import 'dart:convert';
import 'app_logger.dart';
class StringConvert {
static String? writeEmptyToNull(String text) {
static const String separatorPattern = r'[ ,;]+';
static String? writeEmptyToNull(String text) {
if (text.isEmpty) return null;
return text;
}
static String writeNullToEmpty(String? text) {
static String writeNullToEmpty(String? text) {
return text ?? '';
}
static List<String> extractStrings(String input) {
try {
// Check if the input is URL encoded
if (input.contains('%')) {
input = Uri.decodeComponent(input); // Decode URL encoding
}
// Check if the input is Base64 encoded
if (input.length % 4 == 0 && RegExp(r'^[A-Za-z0-9+/=]+$').hasMatch(input)) {
input = utf8.decode(base64.decode(input)); // Decode Base64 encoding
}
final RegExp separator = RegExp(separatorPattern);
final listStrings = input
.replaceAll('\n', ' ')
.split(separator)
.where((value) => value.trim().isNotEmpty)
.toList();
log('StringConvert::extractStrings:listStrings = $listStrings');
return listStrings;
} catch (e) {
return [];
}
}
}