aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorEugene Sandulenko2019-10-18 00:28:36 +0200
committerEugene Sandulenko2019-10-18 00:28:36 +0200
commiteb72d6b479e8b5b29b1662f9c4711ad2dd7a5c20 (patch)
tree77a43bcbfd0a3aae58af978d97e2eb950227db12 /common
parent3ae526dfed510c33a55a9f19b8ccba8e97d13f79 (diff)
downloadscummvm-rg350-eb72d6b479e8b5b29b1662f9c4711ad2dd7a5c20.tar.gz
scummvm-rg350-eb72d6b479e8b5b29b1662f9c4711ad2dd7a5c20.tar.bz2
scummvm-rg350-eb72d6b479e8b5b29b1662f9c4711ad2dd7a5c20.zip
COMMON: Added String::find()
Diffstat (limited to 'common')
-rw-r--r--common/str.cpp25
-rw-r--r--common/str.h2
2 files changed, 27 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp
index aecbbf2574..383a61a687 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -605,6 +605,31 @@ void String::replace(uint32 posOri, uint32 countOri, const char *str,
}
+uint32 String::find(const String &str, uint32 pos) const {
+ if (pos >= _size) {
+ return npos;
+ }
+
+ const char *strP = str.c_str();
+
+ for (const_iterator cur = begin() + pos; *cur; ++cur) {
+ uint i = 0;
+ while (true) {
+ if (!strP[i]) {
+ return cur - begin();
+ }
+
+ if (cur[i] != strP[i]) {
+ break;
+ }
+
+ ++i;
+ }
+ }
+
+ return npos;
+}
+
// static
String String::format(const char *fmt, ...) {
String output;
diff --git a/common/str.h b/common/str.h
index 54044cfac0..92cbc8952b 100644
--- a/common/str.h
+++ b/common/str.h
@@ -168,6 +168,8 @@ public:
bool contains(const char *x) const;
bool contains(char x) const;
+ uint32 find(const String &str, uint32 pos = 0) const;
+
/** Return uint64 corrensponding to String's contents. */
uint64 asUint64() const;