isValidSemanticRoleName function
Whether name is a legal semantic role name: an ASCII identifier
([A-Za-z][A-Za-z0-9_]*). Role names are embedded in positional semantic
ids, so the id separators (/, ~, :) and whitespace are excluded.
Implementation
bool isValidSemanticRoleName(String name) {
if (name.isEmpty) return false;
for (var i = 0; i < name.length; i++) {
final c = name.codeUnitAt(i);
final isLetter = (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A);
final isDigit = c >= 0x30 && c <= 0x39;
if (isLetter || (c == 0x5F && i > 0)) continue;
if (isDigit && i > 0) continue;
return false;
}
return true;
}