add Encoding::beginning_of_code_point()

This commit is contained in:
Josh Holtrop 2016-08-11 23:13:32 -04:00
parent 1aa9fb0c41
commit b2bed71ee4
2 changed files with 16 additions and 0 deletions

View File

@ -81,3 +81,18 @@ uint8_t Encoding::num_bytes_in_code_point(Type type, const uint8_t * encoded)
}
return 0u;
}
const uint8_t * Encoding::beginning_of_code_point(Type type, const uint8_t * encoded)
{
switch (type)
{
case UTF_8:
while ((*encoded & 0xC0u) == 0x80u)
encoded--;
return encoded;
case CP_1252:
return encoded;
}
return nullptr;
}

View File

@ -15,6 +15,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);
static const uint8_t * beginning_of_code_point(Type type, const uint8_t * encoded);
};
#endif