@@ -30,7 +30,6 @@ namespace ErrorCodes
3030// / - idnaEncode(), tryIdnaEncode() and idnaDecode(), see https://en.wikipedia.org/wiki/Internationalized_domain_name#ToASCII_and_ToUnicode
3131// / and [3] https://www.unicode.org/reports/tr46/#ToUnicode
3232
33-
3433enum class ErrorHandling
3534{
3635 Throw, // / Throw exception
@@ -71,7 +70,7 @@ struct IdnaEncode
7170 {
7271 if constexpr (error_handling == ErrorHandling::Throw)
7372 {
74- throw Exception (ErrorCodes::BAD_ARGUMENTS, " '{}' cannot be converted to Punycode " , std::string_view (value, value_length) );
73+ throw Exception (ErrorCodes::BAD_ARGUMENTS, " '{}' cannot be converted to ASCII " , value_view );
7574 }
7675 else
7776 {
@@ -96,6 +95,7 @@ struct IdnaEncode
9695 }
9796};
9897
98+ // / Translates an ASII-encoded IDNA string back to its UTF-8 representation.
9999struct IdnaDecode
100100{
101101 // / As per the specification, invalid inputs are returned as is, i.e. there is no special error handling.
@@ -113,11 +113,11 @@ struct IdnaDecode
113113 std::string unicode;
114114 for (size_t row = 0 ; row < rows; ++row)
115115 {
116- const char * value = reinterpret_cast <const char *>(&data[prev_offset]);
117- const size_t value_length = offsets[row] - prev_offset - 1 ;
118- std::string_view value_view (value, value_length );
116+ const char * ascii = reinterpret_cast <const char *>(&data[prev_offset]);
117+ const size_t ascii_length = offsets[row] - prev_offset - 1 ;
118+ std::string_view ascii_view (ascii, ascii_length );
119119
120- unicode = ada::idna::to_unicode (value_view );
120+ unicode = ada::idna::to_unicode (ascii_view );
121121
122122 res_data.insert (unicode.c_str (), unicode.c_str () + unicode.size () + 1 );
123123 res_offsets.push_back (res_data.size ());
@@ -149,7 +149,7 @@ REGISTER_FUNCTION(Idna)
149149Computes an ASCII representation of an Internationalized Domain Name. Throws an exception in case of error.)" ,
150150 .syntax =" idnaEncode(str)" ,
151151 .arguments ={{" str" , " Input string" }},
152- .returned_value =" An Unicode -encoded domain name [String](/docs/en/sql-reference/data-types/string.md)." ,
152+ .returned_value =" An ASCII -encoded domain name [String](/docs/en/sql-reference/data-types/string.md)." ,
153153 .examples ={
154154 {" simple" ,
155155 " SELECT idnaEncode('straße.münchen.de') AS ascii;" ,
@@ -166,7 +166,7 @@ Computes an ASCII representation of an Internationalized Domain Name. Throws an
166166Computes a ASCII representation of an Internationalized Domain Name. Returns an empty string in case of error)" ,
167167 .syntax =" punycodeEncode(str)" ,
168168 .arguments ={{" str" , " Input string" }},
169- .returned_value =" An Unicode -encoded domain name [String](/docs/en/sql-reference/data-types/string.md)." ,
169+ .returned_value =" An ASCII -encoded domain name [String](/docs/en/sql-reference/data-types/string.md)." ,
170170 .examples ={
171171 {" simple" ,
172172 " SELECT idnaEncodeOrNull('München') AS ascii;" ,
@@ -180,7 +180,7 @@ Computes a ASCII representation of an Internationalized Domain Name. Returns an
180180
181181 factory.registerFunction <FunctionIdnaDecode>(FunctionDocumentation{
182182 .description =R"(
183- Computes a Unicode representation of an Internationalized Domain Name.)" ,
183+ Computes the Unicode representation of ASCII-encoded Internationalized Domain Name.)" ,
184184 .syntax =" idnaDecode(str)" ,
185185 .arguments ={{" str" , " Input string" }},
186186 .returned_value =" An Unicode-encoded domain name [String](/docs/en/sql-reference/data-types/string.md)." ,
0 commit comments