25 #include "common/scummsys.h" 26 #include "common/str.h" 27 #include "common/str-array.h" 29 #ifdef CXXTEST_RUNNING 53 #ifdef CXXTEST_RUNNING 54 friend class ::PathTestSuite;
59 static bool _shownSeparatorCollisionWarning;
63 static const char SEPARATOR =
'/';
65 static const char ESCAPE =
'|';
67 static const char ESCAPED_ESCAPE =
'|';
69 static const char ESCAPED_SEPARATOR =
'\\';
84 static void escape(
String &dst,
char srcSeparator,
const char *src,
const char *end =
nullptr);
97 static String unescape(
char dstSeparator,
const char *src,
const char *end =
nullptr);
107 static bool canUnescape(
bool willBeAtBegin,
bool wasAtBegin,
108 const char *begin,
const char *end =
nullptr);
116 static inline bool needsEncoding(
const char *str,
char separator) {
118 (separator != SEPARATOR ||
133 static String encode(
const char *str,
char separator);
143 Path extract(
const char *begin,
const char *end =
nullptr)
const;
146 size_t findLastSeparator(
size_t last = String::npos)
const;
156 T reduceComponents(T (*reducer)(T value,
const String &element,
bool last), T value)
const;
165 bool compareComponents(
bool (*comparator)(
const String &x,
const String &y),
const Path &other)
const;
167 static Path &punycode_decodefilename_helper(
Path &path,
const String &in,
bool last);
168 static Path &punycode_encodefilename_helper(
Path &path,
const String &in,
bool last);
173 inline bool isEscaped()
const {
175 return *_str.c_str() == ESCAPE;
198 static const char kNativeSeparator =
'/';
232 bool operator()(
const Path &x,
const Path &y)
const {
return x.
equals(y); }
236 uint operator()(
const Path &x)
const {
return x.
hash(); }
254 Path(
const char *str,
char separator =
'/') :
255 _str(needsEncoding(str, separator) ? encode(str, separator) : str) { }
267 _str(needsEncoding(str.c_str(), separator) ? encode(str.c_str(), separator) : str) { }
314 return _str == x._str;
319 return _str != x._str;
326 return _str.
equals(x._str);
353 bool operator<(
const Path &x)
const;
378 void set(
const char *str,
char separator =
'/') {
379 if (needsEncoding(str, separator)) {
380 _str = encode(str, separator);
413 return append(str.c_str(), separator);
417 WARN_UNUSED_RESULT
Path append(
const char *str,
char separator =
'/')
const {
460 return join(str.c_str(), separator);
464 WARN_UNUSED_RESULT
Path join(
const char *str,
char separator =
'/')
const {
static Path fromCommandLine(const String &value)
void toUppercase()
Definition: path.h:518
static const char kNoSeparator
Definition: path.h:189
WARN_UNUSED_RESULT Path join(const String &str, char separator='/') const
Definition: path.h:459
bool equals(const BaseString &x) const
Path getLastComponent() const
WARN_UNUSED_RESULT Path appendComponent(const char *str) const
void clear()
Definition: path.h:282
iterator end()
Definition: array.h:379
iterator begin()
Definition: array.h:374
Path(const char *str, char separator='/')
Definition: path.h:254
Path & joinInPlace(const String &str, char separator='/')
Definition: path.h:441
bool operator==(const Path &x) const
Definition: path.h:313
Path & appendInPlace(const Path &x)
Path & appendInPlace(const String &str, char separator='/')
Definition: path.h:393
static Path joinComponents(StringArray::const_iterator begin, StringArray::const_iterator end)
Path punycodeDecode() const
bool isRelativeTo(const Common::Path &other) const
Definition: path.h:483
static const char kNativeSeparator
Definition: path.h:198
static Path fromConfig(const String &value)
WARN_UNUSED_RESULT Path append(const String &str, char separator='/') const
Definition: path.h:412
bool equalsIgnoreCaseAndMac(const Path &x) const
Path & operator=(const Path &path)
Definition: path.h:361
int numComponents() const
bool empty() const
Definition: path.h:356
bool matchPattern(const Path &pattern) const
bool operator!=(const Path &x) const
Definition: path.h:318
bool equals(const Path &x) const
Definition: path.h:325
bool isSeparatorTerminated() const
Definition: path.h:478
void toLowercase()
Definition: path.h:507
bool equalsIgnoreCase(const Path &x) const
Definition: algorithm.h:29
uint hashIgnoreCase() const
String toString(char separator='/') const
Path()
Definition: path.h:240
Path relativeTo(const Common::Path &other) const
Path & operator=(const String &str)
Definition: path.h:373
WARN_UNUSED_RESULT Path append(const char *str, char separator='/') const
Definition: path.h:417
WARN_UNUSED_RESULT Path append(const Path &x) const
Definition: path.h:405
uint hashIgnoreCaseAndMac() const
WARN_UNUSED_RESULT Path join(const char *str, char separator='/') const
Definition: path.h:464
WARN_UNUSED_RESULT Path appendComponent(const String &x) const
Definition: path.h:430
Path(const Path &path)
Definition: path.h:243
Path & removeTrailingSeparators()
Path & joinInPlace(const Path &x)
Path punycodeEncode() const
Path & operator=(const char *str)
Definition: path.h:367
Path(const String &str, char separator='/')
Definition: path.h:266
WARN_UNUSED_RESULT Path join(const Path &x) const
Definition: path.h:452
String toConfig() const
Definition: path.h:560
StringArray splitComponents() const