countUtf8Bytes function

int countUtf8Bytes(
  1. String message
)

Number of bytes message takes when encoded as UTF-8.

Lone surrogates are encoded as U+FFFD (3 bytes), the same as the JavaScript TextEncoder.

Implementation

int countUtf8Bytes(String message) => utf8.encode(message).length;