public static bool IsUtf8(byte[] buffer, int limit = int.MaxValue) {
var position = 0;
var bytes = 0;
var length = buffer.Length;
while (position < length && position < limit) {
if (buffer[position] > 0x7F) {
if (!IsValid(buffer, position, length, ref bytes)) {
return false;
}
position += bytes;
} else {
position++;
}
}
return true;
}