2020-02-10 11:33:18 +00:00
|
|
|
extension MatrixIdExtension on String {
|
2020-03-30 09:08:38 +00:00
|
|
|
static const Set<String> VALID_SIGILS = {'@', '!', '#', '\$', '+'};
|
2020-02-10 11:33:18 +00:00
|
|
|
|
|
|
|
static const int MAX_LENGTH = 255;
|
|
|
|
|
|
|
|
bool get isValidMatrixId {
|
2020-03-30 09:08:38 +00:00
|
|
|
if (isEmpty ?? true) return false;
|
|
|
|
if (length > MAX_LENGTH) return false;
|
|
|
|
if (!VALID_SIGILS.contains(substring(0, 1))) {
|
2020-02-10 11:33:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-30 09:08:38 +00:00
|
|
|
final parts = substring(1).split(':');
|
2020-02-10 11:33:18 +00:00
|
|
|
if (parts.length != 2 || parts[0].isEmpty || parts[1].isEmpty) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
String get sigil => isValidMatrixId ? substring(0, 1) : null;
|
2020-02-10 11:33:18 +00:00
|
|
|
|
|
|
|
String get localpart =>
|
2020-03-30 09:08:38 +00:00
|
|
|
isValidMatrixId ? substring(1).split(':').first : null;
|
2020-02-10 11:33:18 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
String get domain => isValidMatrixId ? substring(1).split(':')[1] : null;
|
2020-02-10 11:33:18 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
bool equals(String other) => toLowerCase() == other?.toLowerCase();
|
2020-02-10 11:33:18 +00:00
|
|
|
}
|