Skip to content

Commit b5214c7

Browse files
committed
std::u16string and Unicode characters across C++ standards.
Signed-off-by: Tomoya Fujita <[email protected]>
1 parent 30877f5 commit b5214c7

File tree

1 file changed

+6
-0
lines changed
  • rosidl_runtime_cpp/include/rosidl_runtime_cpp

1 file changed

+6
-0
lines changed

rosidl_runtime_cpp/include/rosidl_runtime_cpp/traits.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,20 @@ inline void value_to_yaml(const std::string & value, std::ostream & out)
129129
inline void value_to_yaml(const std::u16string & value, std::ostream & out)
130130
{
131131
out << "\"";
132+
#if __cplusplus < 201703L
132133
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
134+
#endif
133135
auto flags = out.flags();
134136
size_t index = 0;
135137
while (index < value.size()) {
136138
uint_least16_t character = static_cast<uint_least16_t>(value[index]);
137139
if (!(character & 0xff80)) { // ASCII
140+
#if __cplusplus < 201703L
138141
std::string character_as_string = convert.to_bytes(character);
139142
out << std::hex << character_as_string.c_str();
143+
#else
144+
out << static_cast<char>(character);
145+
#endif
140146
} else if (!(character & 0xff00)) { // only 1 byte set
141147
out << "\\x" << std::hex << std::setw(2) << std::setfill('0') << \
142148
character;

0 commit comments

Comments
 (0)