Skip to content

Commit 1fd1d8b

Browse files
committed
Rename Unicode to UnicodeTranscoder (#25)
Review follow-up. The class transcodes between UTF-8, UTF-16 and code points; "Unicode" names a domain that also covers normalization, case mapping and collation, none of which this does. UnicodeTranscoder states the actual responsibility and keeps the scope from drifting. Identifier rename only, with no behavior change: the four method names, their signatures, the validation rules and the file layout are untouched. The header stays internal. Verified locally on Linux GCC at C++11 and C++20: 124/124 tests pass in both, clang-format clean on the changed files. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLXHcZjrnrdhRZAgqDh6kd
1 parent 2dd7c5b commit 1fd1d8b

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎src/internal/unicode.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace sqlite_reflection {
5151
/// wchar_t is 16 bits, no longer reads back. That data was stored ill-formed; because encoding
5252
/// and decoding were wrong in the same way it used to survive a round trip on Windows, so the
5353
/// break surfaces only now. See the text encoding section of README.md.
54-
class REFLECTION_EXPORT Unicode {
54+
class REFLECTION_EXPORT UnicodeTranscoder {
5555
public:
5656
/// Encodes Unicode code points as UTF-8
5757
static std::string Utf8FromCodePoints(const char32_t* code_points, size_t count);

‎src/string_utilities.cc‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace {
3232
// Copies a string of code units into a string of a different unit type, one unit at a time. The
3333
// casts are value-preserving in the directions used below, except for a negative wchar_t on a
3434
// platform where it is signed, which widens to a value above U+10FFFF and is then rejected by
35-
// the validation in Unicode.
35+
// the validation in UnicodeTranscoder.
3636
template <typename To, typename From>
3737
To cast_each(const From& source) {
3838
To result;
@@ -54,11 +54,11 @@ template <>
5454
struct WideCodec<2> {
5555
static std::u32string ToCodePoints(const std::wstring& wide_string) {
5656
const auto code_units = cast_each<std::u16string>(wide_string);
57-
return Unicode::CodePointsFromUtf16(code_units.data(), code_units.size());
57+
return UnicodeTranscoder::CodePointsFromUtf16(code_units.data(), code_units.size());
5858
}
5959

6060
static std::wstring FromCodePoints(const std::u32string& code_points) {
61-
const auto code_units = Unicode::Utf16FromCodePoints(code_points.data(), code_points.size());
61+
const auto code_units = UnicodeTranscoder::Utf16FromCodePoints(code_points.data(), code_points.size());
6262
return cast_each<std::wstring>(code_units);
6363
}
6464
};
@@ -97,11 +97,11 @@ std::string StringUtilities::FromDouble(double value) {
9797

9898
std::string StringUtilities::ToUtf8(const std::wstring& wide_string) {
9999
const auto code_points = PlatformWideCodec::ToCodePoints(wide_string);
100-
return Unicode::Utf8FromCodePoints(code_points.data(), code_points.size());
100+
return UnicodeTranscoder::Utf8FromCodePoints(code_points.data(), code_points.size());
101101
}
102102

103103
std::wstring StringUtilities::FromUtf8(const char* utf8_string, size_t byte_count) {
104-
const auto code_points = Unicode::CodePointsFromUtf8(utf8_string, byte_count);
104+
const auto code_points = UnicodeTranscoder::CodePointsFromUtf8(utf8_string, byte_count);
105105
return PlatformWideCodec::FromCodePoints(code_points);
106106
}
107107

‎src/unicode.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void reject_if_invalid_second_byte(unsigned char lead, unsigned char second) {
9999
}
100100
} // namespace
101101

102-
std::string Unicode::Utf8FromCodePoints(const char32_t* code_points, size_t count) {
102+
std::string UnicodeTranscoder::Utf8FromCodePoints(const char32_t* code_points, size_t count) {
103103
std::string utf8_string;
104104
utf8_string.reserve(count);
105105

@@ -127,7 +127,7 @@ std::string Unicode::Utf8FromCodePoints(const char32_t* code_points, size_t coun
127127
return utf8_string;
128128
}
129129

130-
std::u32string Unicode::CodePointsFromUtf8(const char* utf8_string, size_t byte_count) {
130+
std::u32string UnicodeTranscoder::CodePointsFromUtf8(const char* utf8_string, size_t byte_count) {
131131
std::u32string code_points;
132132
code_points.reserve(byte_count);
133133

@@ -179,7 +179,7 @@ std::u32string Unicode::CodePointsFromUtf8(const char* utf8_string, size_t byte_
179179
return code_points;
180180
}
181181

182-
std::u16string Unicode::Utf16FromCodePoints(const char32_t* code_points, size_t count) {
182+
std::u16string UnicodeTranscoder::Utf16FromCodePoints(const char32_t* code_points, size_t count) {
183183
std::u16string utf16_string;
184184
utf16_string.reserve(count);
185185

@@ -200,7 +200,7 @@ std::u16string Unicode::Utf16FromCodePoints(const char32_t* code_points, size_t
200200
return utf16_string;
201201
}
202202

203-
std::u32string Unicode::CodePointsFromUtf16(const char16_t* utf16_string, size_t count) {
203+
std::u32string UnicodeTranscoder::CodePointsFromUtf16(const char16_t* utf16_string, size_t count) {
204204
std::u32string code_points;
205205
code_points.reserve(count);
206206

‎tests/unicode_test.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,19 @@ TEST(UnicodeTest, SupplementaryCodePointSurvivesLengthAndContent) {
136136

137137
namespace {
138138
std::u32string CodePoints(const std::string& utf8) {
139-
return Unicode::CodePointsFromUtf8(utf8.data(), utf8.size());
139+
return UnicodeTranscoder::CodePointsFromUtf8(utf8.data(), utf8.size());
140140
}
141141

142142
std::string Utf8From(const std::u32string& code_points) {
143-
return Unicode::Utf8FromCodePoints(code_points.data(), code_points.size());
143+
return UnicodeTranscoder::Utf8FromCodePoints(code_points.data(), code_points.size());
144144
}
145145

146146
std::u16string Utf16From(const std::u32string& code_points) {
147-
return Unicode::Utf16FromCodePoints(code_points.data(), code_points.size());
147+
return UnicodeTranscoder::Utf16FromCodePoints(code_points.data(), code_points.size());
148148
}
149149

150150
std::u32string FromUtf16(const std::u16string& code_units) {
151-
return Unicode::CodePointsFromUtf16(code_units.data(), code_units.size());
151+
return UnicodeTranscoder::CodePointsFromUtf16(code_units.data(), code_units.size());
152152
}
153153
} // namespace
154154

0 commit comments

Comments
 (0)