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
b12033fd
Commit
b12033fd
authored
Sep 15, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle grapheme clusters when computing width
parent
e5ab813f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
6 deletions
+34
-6
include/fmt/format.h
include/fmt/format.h
+34
-6
No files found.
include/fmt/format.h
View file @
b12033fd
...
...
@@ -45,6 +45,13 @@
#include "core.h"
#ifndef FMT_USE_TEXT
# define FMT_USE_TEXT 0
#endif
#if FMT_USE_TEXT
# include <boost/text/grapheme_break.hpp>
#endif
#ifdef __clang__
# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
#else
...
...
@@ -415,11 +422,6 @@ class output_range {
sentinel
end
()
const
{
return
{};
}
// Sentinel is not used yet.
};
template
<
typename
Char
>
inline
size_t
count_code_points
(
basic_string_view
<
Char
>
s
)
{
return
s
.
size
();
}
// Counts the number of code points in a UTF-8 string.
inline
size_t
count_code_points
(
basic_string_view
<
char8_t
>
s
)
{
const
char8_t
*
data
=
s
.
data
();
...
...
@@ -912,6 +914,32 @@ inline It format_uint(It out, UInt value, int num_digits, bool upper = false) {
return
internal
::
copy_str
<
Char
>
(
buffer
,
buffer
+
num_digits
,
out
);
}
template
<
typename
Char
>
inline
size_t
compute_width
(
basic_string_view
<
Char
>
s
)
{
return
s
.
size
();
}
inline
size_t
compute_width
(
string_view
s
)
{
#if FMT_USE_TEXT
basic_memory_buffer
<
uint32_t
>
code_points
;
for
(
auto
cp
:
boost
::
text
::
make_to_utf32_range
(
s
))
code_points
.
push_back
(
cp
);
size_t
num_graphemes
=
0
;
for
(
auto
g
:
boost
::
text
::
graphemes
(
code_points
))
++
num_graphemes
;
return
num_graphemes
;
#else
return
s
.
size
();
#endif // FMT_USE_TEXT
}
inline
size_t
compute_width
(
basic_string_view
<
char8_t
>
s
)
{
#if FMT_USE_TEXT
return
compute_width
(
string_view
(
reinterpret_cast
<
const
char
*>
(
s
.
data
(),
s
.
size
())));
#else
return
count_code_points
(
s
);
#endif // FMT_USE_TEXT
}
#ifndef _WIN32
# define FMT_USE_WINDOWS_H 0
#elif !defined(FMT_USE_WINDOWS_H)
...
...
@@ -1583,7 +1611,7 @@ template <typename Range> class basic_writer {
size_t
size
()
const
{
return
size_
;
}
size_t
width
()
const
{
return
internal
::
co
unt_code_points
(
basic_string_view
<
Char
>
(
s
,
size_
));
return
internal
::
co
mpute_width
(
basic_string_view
<
Char
>
(
s
,
size_
));
}
template
<
typename
It
>
void
operator
()(
It
&&
it
)
const
{
...
...
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