Skip to content

Instantly share code, notes, and snippets.

@irrationalRock
Created April 18, 2018 02:41
Show Gist options
  • Save irrationalRock/ce307470c06ffaa8cb9572b33bd08001 to your computer and use it in GitHub Desktop.
Save irrationalRock/ce307470c06ffaa8cb9572b33bd08001 to your computer and use it in GitHub Desktop.
BrotliIsMostlyUTF8(25.06)
BROTLI_BOOL BrotliIsMostlyUTF8(
const uint8_t* data, const size_t pos, const size_t mask,
const size_t length, const double min_fraction) {
size_t size_utf8 = 0;
size_t i = 0;
while (i < length) {
int symbol;
size_t bytes_read =
BrotliParseAsUTF8(&symbol, &data[(pos + i) & mask], length - i);
i += bytes_read;
if (symbol < 0x110000) size_utf8 += bytes_read;
}
return TO_BROTLI_BOOL(size_utf8 > min_fraction * (double)length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment