aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2004-03-04 11:50:12 +0000
committernyamatongwe <unknown>2004-03-04 11:50:12 +0000
commitdce322d98d293baa17d155807746fbdd83ae81ee (patch)
tree43ab2370417e15544a8f99a72afc135d9bd46c7f
parent065aa54f7abd9b055c9fa50eeb0c4e808b94d8f9 (diff)
downloadscintilla-mirror-dce322d98d293baa17d155807746fbdd83ae81ee.tar.gz
Added startswith and endswith methods to SString.
-rw-r--r--include/SString.h4
-rw-r--r--src/PropSet.cxx16
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);