inBytesLength static method

int inBytesLength(
  1. String s
)

The number of UTF-8 bytes s would encode to, without actually allocating/writing them - useful for sizing a buffer you're writing into yourself.

Implementation

static int inBytesLength(String s) {
  var length = 0;
  var i = 0;
  while (i < s.length) {
    final (codePoint, next) = _nextCodePoint(s, i);
    length += _utf8ByteLengthFor(codePoint);
    i = next;
  }
  return length;
}