normalizeSuiNSName function
Implementation
String normalizeSuiNSName(String name, [SuiNSType format = SuiNSType.at]) {
final lowerCase = name.toLowerCase();
List<String> parts;
if (lowerCase.contains("@")) {
if (!RegExp(SUI_NS_NAME_REGEX, caseSensitive: false).hasMatch(lowerCase)) {
throw ArgumentError("Invalid SuiNS name $name");
}
final [labels, domain] = lowerCase.split('@');
parts = [...(labels.isNotEmpty ? labels.split('.') : []), domain];
} else {
if (!RegExp(SUI_NS_DOMAIN_REGEX, caseSensitive: false).hasMatch(lowerCase)) {
throw ArgumentError("Invalid SuiNS name $name");
}
final tmp = lowerCase.split('.');
parts = tmp.sublist(0, tmp.length - 1);
}
if (format == SuiNSType.dot) {
return "${parts.join('.')}.sui";
}
return "${parts.sublist(0, parts.length - 1).join('.')}@${parts[parts.length - 1]}";
}