mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 20:18:49 +00:00
Make char8_t a strongly-typed enum
This commit is contained in:
parent
66992e90d2
commit
e4fea22d15
@ -206,7 +206,7 @@ FMT_FUNC size_t internal::count_code_points(u8string_view s) {
|
|||||||
const char8_t *data = s.data();
|
const char8_t *data = s.data();
|
||||||
int num_code_points = 0;
|
int num_code_points = 0;
|
||||||
for (size_t i = 0, size = s.size(); i != size; ++i) {
|
for (size_t i = 0, size = s.size(); i != size; ++i) {
|
||||||
if ((data[i].value & 0xc0) != 0x80)
|
if ((data[i] & 0xc0) != 0x80)
|
||||||
++num_code_points;
|
++num_code_points;
|
||||||
}
|
}
|
||||||
return num_code_points;
|
return num_code_points;
|
||||||
|
@ -437,12 +437,7 @@ void basic_buffer<T>::append(const U *begin, const U *end) {
|
|||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
// A UTF-8 code unit type.
|
// A UTF-8 code unit type.
|
||||||
struct char8_t {
|
enum char8_t: unsigned char {};
|
||||||
char value;
|
|
||||||
FMT_CONSTEXPR FMT_EXPLICIT operator bool() const FMT_NOEXCEPT {
|
|
||||||
return value != 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// A UTF-8 string view.
|
// A UTF-8 string view.
|
||||||
class u8string_view : public basic_string_view<char8_t> {
|
class u8string_view : public basic_string_view<char8_t> {
|
||||||
|
@ -2407,17 +2407,17 @@ TEST(FormatTest, ConstructU8StringViewFromCString) {
|
|||||||
fmt::u8string_view s("ab");
|
fmt::u8string_view s("ab");
|
||||||
EXPECT_EQ(s.size(), 2u);
|
EXPECT_EQ(s.size(), 2u);
|
||||||
const fmt::char8_t *data = s.data();
|
const fmt::char8_t *data = s.data();
|
||||||
EXPECT_EQ(data[0].value, 'a');
|
EXPECT_EQ(data[0], 'a');
|
||||||
EXPECT_EQ(data[1].value, 'b');
|
EXPECT_EQ(data[1], 'b');
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatTest, ConstructU8StringViewFromDataAndSize) {
|
TEST(FormatTest, ConstructU8StringViewFromDataAndSize) {
|
||||||
fmt::u8string_view s("foobar", 3);
|
fmt::u8string_view s("foobar", 3);
|
||||||
EXPECT_EQ(s.size(), 3u);
|
EXPECT_EQ(s.size(), 3u);
|
||||||
const fmt::char8_t *data = s.data();
|
const fmt::char8_t *data = s.data();
|
||||||
EXPECT_EQ(data[0].value, 'f');
|
EXPECT_EQ(data[0], 'f');
|
||||||
EXPECT_EQ(data[1].value, 'o');
|
EXPECT_EQ(data[1], 'o');
|
||||||
EXPECT_EQ(data[2].value, 'o');
|
EXPECT_EQ(data[2], 'o');
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FMT_USE_USER_DEFINED_LITERALS
|
#if FMT_USE_USER_DEFINED_LITERALS
|
||||||
@ -2426,7 +2426,7 @@ TEST(FormatTest, U8StringViewLiteral) {
|
|||||||
fmt::u8string_view s = "ab"_u;
|
fmt::u8string_view s = "ab"_u;
|
||||||
EXPECT_EQ(s.size(), 2u);
|
EXPECT_EQ(s.size(), 2u);
|
||||||
const fmt::char8_t *data = s.data();
|
const fmt::char8_t *data = s.data();
|
||||||
EXPECT_EQ(data[0].value, 'a');
|
EXPECT_EQ(data[0], 'a');
|
||||||
EXPECT_EQ(data[1].value, 'b');
|
EXPECT_EQ(data[1], 'b');
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user