Lines 74-84
std::string StringViewToUtf8(const StringView& view) {
Link Here
|
74 |
|
74 |
|
75 |
size_t result_length = view.length() * sizeof(*source); |
75 |
size_t result_length = view.length() * sizeof(*source); |
76 |
std::string result(result_length, '\0'); |
76 |
std::string result(result_length, '\0'); |
77 |
UnicodeString utf16(unicodeSource, view.length()); |
77 |
icu::UnicodeString utf16(unicodeSource, view.length()); |
78 |
// ICU components for std::string compatibility are not enabled in build... |
78 |
// ICU components for std::string compatibility are not enabled in build... |
79 |
bool done = false; |
79 |
bool done = false; |
80 |
while (!done) { |
80 |
while (!done) { |
81 |
CheckedArrayByteSink sink(&result[0], result_length); |
81 |
icu::CheckedArrayByteSink sink(&result[0], result_length); |
82 |
utf16.toUTF8(sink); |
82 |
utf16.toUTF8(sink); |
83 |
result_length = sink.NumberOfBytesAppended(); |
83 |
result_length = sink.NumberOfBytesAppended(); |
84 |
result.resize(result_length); |
84 |
result.resize(result_length); |
Lines 111-118
void ReleasePairOnAsyncClose(uv_handle_t* async) {
Link Here
|
111 |
} // namespace |
111 |
} // namespace |
112 |
|
112 |
|
113 |
std::unique_ptr<StringBuffer> Utf8ToStringView(const std::string& message) { |
113 |
std::unique_ptr<StringBuffer> Utf8ToStringView(const std::string& message) { |
114 |
UnicodeString utf16 = |
114 |
icu::UnicodeString utf16 = |
115 |
UnicodeString::fromUTF8(StringPiece(message.data(), message.length())); |
115 |
icu::UnicodeString::fromUTF8(icu::StringPiece(message.data(), |
|
|
116 |
message.length())); |
116 |
StringView view(reinterpret_cast<const uint16_t*>(utf16.getBuffer()), |
117 |
StringView view(reinterpret_cast<const uint16_t*>(utf16.getBuffer()), |
117 |
utf16.length()); |
118 |
utf16.length()); |
118 |
return StringBuffer::create(view); |
119 |
return StringBuffer::create(view); |