add Encoding::num_bytes_in_code_point()

This commit is contained in:
Josh Holtrop 2016-08-11 23:08:21 -04:00
parent 490505faa1
commit 1aa9fb0c41
2 changed files with 22 additions and 0 deletions

View File

@ -60,3 +60,24 @@ Encoding::Type Encoding::detect_encoding(const uint8_t * buffer, size_t length)
return UTF_8;
}
uint8_t Encoding::num_bytes_in_code_point(Type type, const uint8_t * encoded)
{
switch (type)
{
case UTF_8:
{
if ((*encoded & 0x80u) == 0u)
return 1u;
encoded++;
uint8_t n = 1u;
while ((*encoded++ & 0xC0u) == 0x80u)
n++;
return n;
}
break;
case CP_1252:
return 1u;
}
return 0u;
}

View File

@ -14,6 +14,7 @@ public:
};
static Type detect_encoding(const uint8_t * buffer, size_t length);
static uint8_t num_bytes_in_code_point(Type type, const uint8_t * encoded);
};
#endif