1717#include < unicode/grapheme_segmenter.h>
1818#include < unicode/ucd.h>
1919#include < unicode/ucd_enums.h>
20- #include < unicode/ucd_fmt .h>
20+ #include < unicode/ucd_ostream .h>
2121#include < unicode/utf8_grapheme_segmenter.h>
2222
23- #include < fmt/format.h>
24-
2523#include < cassert>
2624#include < charconv>
25+ #include < iomanip>
2726#include < iostream>
2827#include < optional>
28+ #include < sstream>
2929#include < string>
3030
3131using namespace std ;
@@ -35,16 +35,17 @@ namespace
3535
3636std::string quotedAndEscaped (std::string const & text)
3737{
38- auto result = " \" " s;
38+ auto result = stringstream {};
39+ result << ' "' ;
3940 for (char const ch: text)
4041 {
4142 if (std::isprint (ch) && ch != ' "' )
42- result += ch;
43+ result << ch;
4344 else
44- result += fmt::format ( " \\ x{:02X} " , uint8_t ( ch));
45+ result << " \\ x" << setw ( 2 ) << std::hex << ( unsigned ( ch) & 0xFF );
4546 }
46- result += " \" " ;
47- return result;
47+ result << " \" " ;
48+ return result. str () ;
4849}
4950
5051int printUsage (int exitCode)
@@ -86,7 +87,9 @@ vector<char32_t> parseChars(std::string_view text)
8687
8788string prettyAge (unicode::Age age)
8889{
89- string str = fmt::format (" {}" , age);
90+ // clang-format off
91+ string str = [=]() { auto s = ostringstream (); s << age; return s.str (); }();
92+ // clang-format on
9093 assert (str.at (0 ) == ' V' );
9194 str = str.substr (1 );
9295 replace (str.begin (), str.end (), ' _' , ' .' );
@@ -98,20 +101,20 @@ void showCodepointProperties(char32_t codepoint)
98101 auto const properties = unicode::codepoint_properties::get (codepoint);
99102
100103 // clang-format off
101- cout << fmt::format ( " Name : {} \n " , unicode::codepoint_properties::name (codepoint)) ;
102- cout << fmt::format ( " Unicode Version : {} \n " , prettyAge (properties.age )) ;
103- cout << fmt::format ( " Codepoint : U+{:X} \n " , uint32_t (codepoint)) ;
104- cout << fmt::format ( " UTF-8 : {} \n " , quotedAndEscaped (unicode::convert_to<char >(codepoint))) ;
104+ cout << " Name : " << unicode::codepoint_properties::name (codepoint) << ' \n ' ;
105+ cout << " Unicode Version : " << prettyAge (properties.age ) << ' \n ' ;
106+ cout << " Codepoint : U+" << hex << uint32_t (codepoint) << ' \n ' ;
107+ cout << " UTF-8 : " << quotedAndEscaped (unicode::convert_to<char >(codepoint)) << ' \n ' ;
105108 if (properties.general_category != unicode::General_Category::Control)
106- cout << fmt::format ( " Display : {} \n " , unicode::convert_to<char >(codepoint)) ;
107- cout << fmt::format ( " Plane : {} \n " , unicode::plane (codepoint)) ;
108- cout << fmt::format ( " Block : {} \n " , unicode::block (codepoint)) ;
109- cout << fmt::format ( " Script : {} \n " , unicode::script (codepoint)) ;
110- cout << fmt::format ( " General Category : {} \n " , properties.general_category ) ;
111- cout << fmt::format ( " East Asian Width : {} \n " , properties.east_asian_width ) ;
112- cout << fmt::format ( " Character width : {} \n " , properties.char_width ) ;
113- cout << fmt::format ( " Emoji Segmentation Category : {} \n " , properties.emoji_segmentation_category ) ;
114- cout << fmt::format ( " Grapheme Cluster Break : {} \n " , properties.grapheme_cluster_break ) ;
109+ cout << " Display : " << unicode::convert_to<char >(codepoint) << ' \n ' ;
110+ cout << " Plane : " << unicode::plane (codepoint) << ' \n ' ;
111+ cout << " Block : " << unicode::block (codepoint) << ' \n ' ;
112+ cout << " Script : " << unicode::script (codepoint) << ' \n ' ;
113+ cout << " General Category : " << properties.general_category << ' \n ' ;
114+ cout << " East Asian Width : " << properties.east_asian_width << ' \n ' ;
115+ cout << " Character width : " << properties.char_width << ' \n ' ;
116+ cout << " Emoji Segmentation Category : " << properties.emoji_segmentation_category << ' \n ' ;
117+ cout << " Grapheme Cluster Break : " << properties.grapheme_cluster_break << ' \n ' ;
115118 cout << " \n " ;
116119 // clang-format off
117120}
0 commit comments