getFirstNonAsciiCharIndex function Null safety

int? getFirstNonAsciiCharIndex(
  1. String string
)

Returns, if any, the index of the first non-ASCII character in the string. If the string is either empty or all-ASCII, null is returned.

Implementation

int? getFirstNonAsciiCharIndex(String string) {
  for (var i = 0; i < string.length; i++) {
    final c = string.codeUnitAt(i);
    if (!isValidAsciiChar(c)) {
      return i;
    }
  }
  return null;
}