diff --git a/common/punycode.cpp b/common/punycode.cpp index b79e6f2964d..b1e294773e9 100644 --- a/common/punycode.cpp +++ b/common/punycode.cpp @@ -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 diff --git a/common/punycode.h b/common/punycode.h index 0fa1e949dd5..63838657bb6 100644 --- a/common/punycode.h +++ b/common/punycode.h @@ -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);