MCPcopy Create free account
hub / github.com/NativeScript/android / to_unicode

Function to_unicode

test-app/runtime/src/main/cpp/ada/ada.cpp:9779–9831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9777
9778namespace ada::idna {
9779std::string to_unicode(std::string_view input) {
9780 std::string output;
9781 output.reserve(input.size());
9782
9783 size_t label_start = 0;
9784 while (label_start < input.size()) {
9785 size_t loc_dot = input.find('.', label_start);
9786 bool is_last_label = (loc_dot == std::string_view::npos);
9787 size_t label_size =
9788 is_last_label ? input.size() - label_start : loc_dot - label_start;
9789 auto label_view = std::string_view(input.data() + label_start, label_size);
9790
9791 if (label_view.starts_with("xn--") && ada::idna::is_ascii(label_view)) {
9792 label_view.remove_prefix(4);
9793 if (ada::idna::verify_punycode(label_view)) {
9794 std::u32string tmp_buffer;
9795 if (ada::idna::punycode_to_utf32(label_view, tmp_buffer)) {
9796#ifdef ADA_USE_SIMDUTF
9797 auto utf8_size = simdutf::utf8_length_from_utf32(tmp_buffer.data(),
9798 tmp_buffer.size());
9799 std::string final_utf8(utf8_size, '\0');
9800 simdutf::convert_utf32_to_utf8(tmp_buffer.data(), tmp_buffer.size(),
9801 final_utf8.data());
9802#else
9803 auto utf8_size = ada::idna::utf8_length_from_utf32(tmp_buffer.data(),
9804 tmp_buffer.size());
9805 std::string final_utf8(utf8_size, '\0');
9806 ada::idna::utf32_to_utf8(tmp_buffer.data(), tmp_buffer.size(),
9807 final_utf8.data());
9808#endif
9809 output.append(final_utf8);
9810 } else {
9811 // ToUnicode never fails. If any step fails, then the original input
9812 // sequence is returned immediately in that step.
9813 output.append(
9814 std::string_view(input.data() + label_start, label_size));
9815 }
9816 } else {
9817 output.append(std::string_view(input.data() + label_start, label_size));
9818 }
9819 } else {
9820 output.append(label_view);
9821 }
9822
9823 if (!is_last_label) {
9824 output.push_back('.');
9825 }
9826
9827 label_start += label_size + 1;
9828 }
9829
9830 return output;
9831}
9832} // namespace ada::idna
9833/* end file src/to_unicode.cpp */
9834/* begin file src/identifier.cpp */

Callers 1

ada_idna_to_unicodeFunction · 0.85

Calls 10

is_asciiFunction · 0.85
verify_punycodeFunction · 0.85
punycode_to_utf32Function · 0.85
utf8_length_from_utf32Function · 0.85
utf32_to_utf8Function · 0.85
appendMethod · 0.65
reserveMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected