diff options
-rw-r--r-- | include/SString.h | 4 | ||||
-rw-r--r-- | src/PropSet.cxx | 16 |
2 files changed, 19 insertions, 1 deletions
diff --git a/include/SString.h b/include/SString.h index 63930189c..3efb84a03 100644 --- a/include/SString.h +++ b/include/SString.h @@ -144,7 +144,7 @@ public: * starting at @a pos, the string is just truncated at @a pos. */ void remove(lenpos_t pos, lenpos_t len); - + SString &change(lenpos_t pos, char ch) { if (pos < sLen) { // character changed must be in string bounds *(s + pos) = ch; @@ -155,6 +155,8 @@ public: int value() const { return s ? atoi(s) : 0; } + bool startswith(const char *prefix); + bool endswith(const char *suffix); int search(const char *sFind, lenpos_t start=0) const; bool contains(const char *sFind) { return search(sFind) >= 0; diff --git a/src/PropSet.cxx b/src/PropSet.cxx index a1ed39da6..32ec59626 100644 --- a/src/PropSet.cxx +++ b/src/PropSet.cxx @@ -247,6 +247,22 @@ void SString::remove(lenpos_t pos, lenpos_t len) { } } +bool SString::startswith(const char *prefix) { + lenpos_t lenPrefix = strlen(prefix); + if (lenPrefix > sLen) { + return false; + } + return strncmp(s, prefix, lenPrefix) == 0; +} + +bool SString::endswith(const char *suffix) { + lenpos_t lenSuffix = strlen(suffix); + if (lenSuffix > sLen) { + return false; + } + return strncmp(s + sLen - lenSuffix, suffix, lenSuffix) == 0; +} + int SString::search(const char *sFind, lenpos_t start) const { if (start < sLen) { const char *sFound = strstr(s + start, sFind); |