diff --git a/src/core/Encoding.cc b/src/core/Encoding.cc index b026861..f8e1fb9 100644 --- a/src/core/Encoding.cc +++ b/src/core/Encoding.cc @@ -156,3 +156,41 @@ uint32_t Encoding::decode(Type type, const uint8_t * encoded) return 0u; } + +uint8_t Encoding::num_bytes_to_encode_code_point(uint32_t code_point, Type type) +{ + switch (type) + { + case UTF_8: + if (code_point <= 0x7Fu) + { + return 1u; + } + else if (code_point <= 0x7FFu) + { + return 2u; + } + else if (code_point <= 0xFFFFu) + { + return 3u; + } + else if (code_point <= 0x1FFFFFu) + { + return 4u; + } + else if (code_point <= 0x3FFFFFFu) + { + return 5u; + } + else + { + return 6u; + } + break; + case CP_1252: + return 1u; + break; + } + + return 0u; +} diff --git a/src/core/Encoding.h b/src/core/Encoding.h index 3b5761a..f85defc 100644 --- a/src/core/Encoding.h +++ b/src/core/Encoding.h @@ -17,6 +17,8 @@ public: 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); static uint32_t decode(Type type, const uint8_t * encoded); + static uint8_t num_bytes_to_encode_code_point(uint32_t code_point, Type type); + static uint8_t encode(uint32_t code_point, Type type, uint8_t * buffer); }; #endif