COMMON: Added auxiliary methods for punycode

This commit is contained in:
Eugene Sandulenko 2021-07-23 23:59:00 +02:00
parent 56f7af8d2e
commit a655cff203
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
2 changed files with 18 additions and 1 deletions

View File

@ -73,7 +73,7 @@ static uint32_t adapt_bias(uint32_t delta, unsigned n_points, int is_first) {
static char encode_digit(int c) {
assert(c >= 0 && c <= BASE - TMIN);
if (c > 25) {
return c + 22; /* '0'..'9' */
return c + 26; /* '0'..'9' */
} else {
return c + 'a'; /* 'a'..'z' */
}
@ -191,6 +191,20 @@ fail:
return si;
}
bool punycode_hasprefix(const String src) {
return src.hasPrefix("xn--");
}
bool punycode_needEncode(const String src) {
for (int si = 0; si < src.size(); si++) {
if (src[si] & 0x80 || src[si] < 0x20) {
return true;
}
}
return false;
}
String punycode_decode(const String src1) {
if (!src1.hasPrefix("xn--"))
return src1;

View File

@ -63,6 +63,9 @@ String punycode_decode(const String src);
*/
String punycode_decodefilename(const String src1);
bool punycode_hasprefix(const String src);
bool punycode_needEncode(const String src);
} // end of namespace Common