codePointBefore function

int codePointBefore(
  1. String text,
  2. int i
)

The code point that ends just before i, or -1 at the start.

Implementation

int codePointBefore(String text, int i) {
  if (i <= 0) {
    return -1;
  }
  final low = text.codeUnitAt(i - 1);
  if (low >= 0xDC00 && low <= 0xDFFF && i >= 2) {
    final high = text.codeUnitAt(i - 2);
    if (high >= 0xD800 && high <= 0xDBFF) {
      return 0x10000 + ((high - 0xD800) << 10) + (low - 0xDC00);
    }
  }
  return low;
}