add Encoding::num_bytes_in_code_point()

This commit is contained in:
josh committed 2016-08-11 23:08:21 -04:00
1 parent 490505faa1
commit 1aa9fb0c41
2 files changed
+22

No files matched your search

+21
View File
@@ -60,3 +60,24 @@ Encoding::Type Encoding::detect_encoding(const uint8_t * buffer, size_t length)
return UTF_8; 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;
}
+1
View File
@@ -14,6 +14,7 @@ public:
}; };
static Type detect_encoding(const uint8_t * buffer, size_t length); 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 #endif