diff --git a/common/path.cpp b/common/path.cpp index e152fa3f80b..459fea5389b 100644 --- a/common/path.cpp +++ b/common/path.cpp @@ -20,6 +20,8 @@ */ #include "common/path.h" +#include "common/tokenizer.h" +#include "common/punycode.h" namespace Common { @@ -53,7 +55,7 @@ Path Path::getParent() const { if (_str.size() < 2) return Path(); size_t separatorPos = _str.findLastOf(DIR_SEPARATOR, _str.size() - 2); - if (separatorPos == Common::String::npos) + if (separatorPos == String::npos) return Path(); return Path(_str.substr(0, separatorPos + 1), DIR_SEPARATOR); } @@ -62,7 +64,7 @@ Path Path::getLastComponent() const { if (_str.size() < 2) return *this; size_t separatorPos = _str.findLastOf(DIR_SEPARATOR, _str.size() - 2); - if (separatorPos == Common::String::npos) + if (separatorPos == String::npos) return *this; return Path(_str.substr(separatorPos + 1), DIR_SEPARATOR); } @@ -182,4 +184,35 @@ Path Path::join(const char *str, char separator) const { return temp; } +Path Path::punycodeDecode() const { + StringTokenizer tok(rawString(), String(DIR_SEPARATOR)); + String res; + + while (!tok.empty()) { + res += punycode_decodefilename(tok.nextToken()); + if (!tok.empty()) + res += DIR_SEPARATOR; + } + + return Path(res, DIR_SEPARATOR); +} + +Path Path::punycodeEncode() const { + StringTokenizer tok(rawString(), String(DIR_SEPARATOR)); + String res; + + while (!tok.empty()) { + String part = tok.nextToken(); + if (punycode_needEncode(part)) + res += punycode_encodefilename(part); + else + res += part; + + if (!tok.empty()) + res += DIR_SEPARATOR; + } + + return Path(res, DIR_SEPARATOR); +} + } // End of namespace Common diff --git a/common/path.h b/common/path.h index cc5b214d394..1c9c2941c09 100644 --- a/common/path.h +++ b/common/path.h @@ -175,6 +175,16 @@ public: /** @overload */ Path join(const char *str, char separator = '/') const; + + /** + * Convert path from Punycode + */ + Path punycodeDecode() const; + + /** + * Convert path to Punycode + */ + Path punycodeEncode() const; }; /** @} */ diff --git a/common/punycode.cpp b/common/punycode.cpp index 76ff100b0fa..c894db4c002 100644 --- a/common/punycode.cpp +++ b/common/punycode.cpp @@ -43,7 +43,6 @@ #include "common/punycode.h" #include "common/debug.h" -#include "common/tokenizer.h" #include "common/util.h" namespace Common { @@ -412,35 +411,4 @@ U32String punycode_decodefilename(const String &src1) { return dst; } -Path punycode_decodepath(const Path &src) { - StringTokenizer tok(src.rawString(), Common::String(DIR_SEPARATOR)); - String res; - - while (!tok.empty()) { - res += punycode_decodefilename(tok.nextToken()); - if (!tok.empty()) - res += DIR_SEPARATOR; - } - - return Path(res, DIR_SEPARATOR); -} - -Path punycode_encodepath(const Path &src) { - StringTokenizer tok(src.rawString(), Common::String(DIR_SEPARATOR)); - String res; - - while (!tok.empty()) { - String part = tok.nextToken(); - if (punycode_needEncode(part)) - res += punycode_encodefilename(part); - else - res += part; - - if (!tok.empty()) - res += DIR_SEPARATOR; - } - - return Path(res, DIR_SEPARATOR); -} - } // end of namespace Common diff --git a/common/punycode.h b/common/punycode.h index 822a11b5a54..cad4f32408b 100644 --- a/common/punycode.h +++ b/common/punycode.h @@ -65,16 +65,6 @@ String punycode_encodefilename(const U32String &src1); */ U32String punycode_decodefilename(const String &src1); -/** - * Convert path from Punycode - */ -Path punycode_decodepath(const Path &src); - -/** - * Convert path to Punycode - */ -Path punycode_encodepath(const Path &src); - bool punycode_hasprefix(const String &src); bool punycode_needEncode(const String &src); diff --git a/engines/director/director.cpp b/engines/director/director.cpp index 2f4f74a6caa..9c3c7ce8273 100644 --- a/engines/director/director.cpp +++ b/engines/director/director.cpp @@ -323,7 +323,7 @@ void DirectorEngine::parseOptions() { _options.startMovie.startFrame = atoi(tail.c_str()); } - _options.startMovie.startMovie = Common::punycode_decodepath(_options.startMovie.startMovie).toString(_dirSeparator); + _options.startMovie.startMovie = Common::Path(_options.startMovie.startMovie).punycodeDecode().toString(_dirSeparator); debug(2, "parseOptions(): Movie is: %s, frame is: %d", _options.startMovie.startMovie.c_str(), _options.startMovie.startFrame); } else if (key == "startup") { diff --git a/engines/director/util.cpp b/engines/director/util.cpp index 464b963681a..acb4d0376f6 100644 --- a/engines/director/util.cpp +++ b/engines/director/util.cpp @@ -1015,7 +1015,7 @@ Common::u32char_type_t numToChar(int num) { } Common::String encodePathForDump(const Common::String &path) { - return punycode_encodepath(Common::Path(path, g_director->_dirSeparator)).toString(); + return Common::Path(path, g_director->_dirSeparator).punycodeEncode().toString(); } Common::String utf8ToPrintable(const Common::String &str) { diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp index 13837a1f53e..5fec12182c8 100644 --- a/engines/wage/wage.cpp +++ b/engines/wage/wage.cpp @@ -124,7 +124,7 @@ Common::Error WageEngine::run() { // Your main event loop should be (invoked from) here. _resManager = new Common::MacResManager(); - if (!_resManager->open(Common::punycode_decodepath(getGameFile()).toString('/'))) + if (!_resManager->open(Common::Path(getGameFile()).punycodeDecode().toString('/'))) error("Could not open %s as a resource fork", getGameFile()); _world = new World(this);