COMMON: Added more auxiliary method to Punycode

This commit is contained in:
Eugene Sandulenko 2021-07-27 14:25:34 +02:00
parent f3145d0fb6
commit 96bb4d2d53
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
2 changed files with 33 additions and 0 deletions

View File

@ -44,6 +44,7 @@
#include "common/punycode.h"
#include "common/debug.h"
#include "common/tokenizer.h"
#include "common/util.h"
namespace Common {
@ -311,6 +312,19 @@ String punycode_encodefilename(const String src) {
return punycode_encode(dst);
}
String punycode_encodepath(const String src) {
StringTokenizer tok(src, "/");
String res;
while (!tok.empty()) {
res += punycode_encodefilename(tok.nextToken());
if (!tok.empty())
res += '/';
}
return res;
}
String punycode_decodefilename(const String src1) {
String dst;
String src = punycode_decode(src1);
@ -335,4 +349,17 @@ String punycode_decodefilename(const String src1) {
return dst;
}
String punycode_decodepath(const String src) {
StringTokenizer tok(src, "/");
String res;
while (!tok.empty()) {
res += punycode_decodefilename(tok.nextToken());
if (!tok.empty())
res += '/';
}
return res;
}
} // end of namespace Common

View File

@ -59,12 +59,18 @@ String punycode_encode(const String src);
String punycode_decode(const String src);
String punycode_encodefilename(const String src1);
String punycode_encodepath(const String src);
/**
* Convert Punycode filename to Binary using special 0x81 escape character. Returns the decoded string
*/
String punycode_decodefilename(const String src1);
/**
* Convert path with '/' as separators from Punycode
*/
String punycode_decodepath(const String src);
bool punycode_hasprefix(const String src);
bool punycode_needEncode(const String src);