add Encoding::num_bytes_in_code_point()
This commit is contained in:
parent
490505faa1
commit
1aa9fb0c41
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user