Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
e4fea22d
Commit
e4fea22d
authored
Sep 29, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make char8_t a strongly-typed enum
parent
66992e90
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
14 deletions
+9
-14
include/fmt/format-inl.h
include/fmt/format-inl.h
+1
-1
include/fmt/format.h
include/fmt/format.h
+1
-6
test/format-test.cc
test/format-test.cc
+7
-7
No files found.
include/fmt/format-inl.h
View file @
e4fea22d
...
@@ -206,7 +206,7 @@ FMT_FUNC size_t internal::count_code_points(u8string_view s) {
...
@@ -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
;
...
...
include/fmt/format.h
View file @
e4fea22d
...
@@ -437,12 +437,7 @@ void basic_buffer<T>::append(const U *begin, const U *end) {
...
@@ -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
>
{
...
...
test/format-test.cc
View file @
e4fea22d
...
@@ -2407,17 +2407,17 @@ TEST(FormatTest, ConstructU8StringViewFromCString) {
...
@@ -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) {
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment