mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-19 00:15:30 +00:00
COMMON: Move punycode_*codepath to path.cpp
This allows to reduce access to DIR_SEPARATOR from outside of Common::Path
This commit is contained in:
parent
387dd08f5d
commit
af7d9cb850
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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") {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user