isLength function

bool isLength(
  1. String str,
  2. int min,
  3. [int? max]
)

check if the string's length falls in a range If no max is given then any length above min is ok.

Note: this function takes into account surrogate pairs.

Implementation

bool isLength(String str, int min, [int? max]) {
  final surrogatePairs = _surrogatePairsRegExp.allMatches(str).toList();
  int len = str.length - surrogatePairs.length;
  return len >= min && (max == null || len <= max);
}