Skip to content

Commit af05268

Browse files
committed
unicode : cleanup
1 parent c68d259 commit af05268

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

unicode.cpp

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,22 @@ static uint32_t unicode_cpt_from_utf8(const std::string & utf8, size_t & offset)
5656
offset += 4;
5757
return result;
5858
}
59-
throw std::invalid_argument("invalid string");
59+
throw std::invalid_argument("failed to convert utf8 to codepoint");
6060
}
6161

62-
static std::vector<uint16_t> unicode_cpt_to_utf16(uint32_t cp) {
63-
std::vector<uint16_t> result;
64-
if (/* 0x0000 <= cp && */ cp <= 0xffff) {
65-
result.emplace_back(cp);
66-
}
67-
else if (0x10000 <= cp && cp <= 0x10ffff) {
68-
result.emplace_back(0xd800 | ((cp - 0x10000) >> 10));
69-
result.emplace_back(0xdc00 | ((cp - 0x10000) & 0x03ff));
70-
}
71-
else {
72-
throw std::invalid_argument("invalid cpt");
73-
}
74-
return result;
75-
}
62+
//static std::vector<uint16_t> unicode_cpt_to_utf16(uint32_t cp) {
63+
// std::vector<uint16_t> result;
64+
// if (/* 0x0000 <= cp && */ cp <= 0xffff) {
65+
// result.emplace_back(cp);
66+
// return result;
67+
// }
68+
// if (0x10000 <= cp && cp <= 0x10ffff) {
69+
// result.emplace_back(0xd800 | ((cp - 0x10000) >> 10));
70+
// result.emplace_back(0xdc00 | ((cp - 0x10000) & 0x03ff));
71+
// return result;
72+
// }
73+
// throw std::invalid_argument("failed to convert codepoint to utf16");
74+
//}
7675

7776
//static std::vector<uint16_t> unicode_cpts_to_utf16(const std::vector<uint32_t> & cps) {
7877
// std::vector<uint16_t> result;
@@ -83,28 +82,28 @@ static std::vector<uint16_t> unicode_cpt_to_utf16(uint32_t cp) {
8382
// return result;
8483
//}
8584

86-
static uint32_t cpt_from_utf16(const std::vector<uint16_t> & utf16, size_t & offset) {
87-
assert(offset < utf16.size());
88-
if (((utf16[0] >> 10) << 10) != 0xd800) {
89-
auto result = utf16[offset + 0];
90-
offset += 1;
91-
return result;
92-
}
93-
94-
if (offset + 1 >= utf16.size() || !((utf16[1] & 0xdc00) == 0xdc00)) {
95-
throw std::invalid_argument("invalid character");
96-
}
97-
98-
auto result = 0x10000 + (((utf16[0] & 0x03ff) << 10) | (utf16[1] & 0x03ff));
99-
offset += 2;
100-
return result;
101-
}
85+
//static uint32_t unicode_cpt_from_utf16(const std::vector<uint16_t> & utf16, size_t & offset) {
86+
// assert(offset < utf16.size());
87+
// if (((utf16[0] >> 10) << 10) != 0xd800) {
88+
// auto result = utf16[offset + 0];
89+
// offset += 1;
90+
// return result;
91+
// }
92+
//
93+
// if (offset + 1 >= utf16.size() || !((utf16[1] & 0xdc00) == 0xdc00)) {
94+
// throw std::invalid_argument("invalid character");
95+
// }
96+
//
97+
// auto result = 0x10000 + (((utf16[0] & 0x03ff) << 10) | (utf16[1] & 0x03ff));
98+
// offset += 2;
99+
// return result;
100+
//}
102101

103102
//static std::vector<uint32_t> unicode_cpts_from_utf16(const std::vector<uint16_t> & utf16) {
104103
// std::vector<uint32_t> result;
105104
// size_t offset = 0;
106105
// while (offset < utf16.size()) {
107-
// result.push_back(cpt_from_utf16(utf16, offset));
106+
// result.push_back(unicode_cpt_from_utf16(utf16, offset));
108107
// }
109108
// return result;
110109
//}

0 commit comments

Comments
 (0)