diff options
author | Vincent Bénony | 2015-12-01 18:57:39 +0100 |
---|---|---|
committer | Vincent Bénony | 2016-01-06 15:35:30 +0100 |
commit | bbf3785bbadd42536ad6a266ae4dc082351f87d5 (patch) | |
tree | a4e23fe6575638a49ae2ef7381feb909b038f537 /common | |
parent | 108ce38443eda81032b72e81202237da53f922e8 (diff) | |
download | scummvm-rg350-bbf3785bbadd42536ad6a266ae4dc082351f87d5.tar.gz scummvm-rg350-bbf3785bbadd42536ad6a266ae4dc082351f87d5.tar.bz2 scummvm-rg350-bbf3785bbadd42536ad6a266ae4dc082351f87d5.zip |
IOS: Adds two helper functions on strings
Diffstat (limited to 'common')
-rw-r--r-- | common/str.cpp | 12 | ||||
-rw-r--r-- | common/str.h | 6 |
2 files changed, 18 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp index faf84d722f..ad02bfdaf8 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -665,6 +665,18 @@ String lastPathComponent(const String &path, const char sep) { return String(first, last); } +String String::stringByAppendingPathComponent(String component, char sep) const { + if (lastChar() == sep && component.firstChar() == sep) { + return String::format("%s%s", c_str(), component.c_str() + 1); + } + + if (lastChar() == sep || component.firstChar() == sep) { + return String::format("%s%s", c_str(), component.c_str()); + } + + return String::format("%s%c%s", c_str(), sep, component.c_str()); +} + String normalizePath(const String &path, const char sep) { if (path.empty()) return path; diff --git a/common/str.h b/common/str.h index dede87a005..f156290e94 100644 --- a/common/str.h +++ b/common/str.h @@ -180,6 +180,7 @@ public: inline uint size() const { return _size; } inline bool empty() const { return (_size == 0); } + char firstChar() const { return (_size > 0) ? _str[0] : 0; } char lastChar() const { return (_size > 0) ? _str[_size - 1] : 0; } char operator[](int idx) const { @@ -217,6 +218,11 @@ public: */ void trim(); + /** + * Add a path component + */ + String stringByAppendingPathComponent(String component, char sep = '/') const; + uint hash() const; /** |