diff options
-rw-r--r-- | common/str.cpp | 25 | ||||
-rw-r--r-- | common/str.h | 2 |
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; |