From c99b24c16d1111a701d915832f24ac457aef697d Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Fri, 10 Jun 2016 14:06:06 +0600 Subject: COMMON: Add String::asUint64() Instead of all these atoull() I've added everywhere. --- common/str.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'common/str.cpp') diff --git a/common/str.cpp b/common/str.cpp index 3ff49a90c6..326b4a80d1 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -335,6 +335,15 @@ bool String::contains(char x) const { return strchr(c_str(), x) != NULL; } +uint64 String::asUint64() const { + uint64 result = 0; + for (uint32 i = 0; i < _size; ++i) { + if (_str[i] < '0' || _str[i] > '9') break; + result = result * 10L + (_str[i] - '0'); + } + return result; +} + bool String::matchString(const char *pat, bool ignoreCase, bool pathMode) const { return Common::matchString(c_str(), pat, ignoreCase, pathMode); } -- cgit v1.2.3 From 627bda9d82c178641e5b5253379c21ce556eb3c2 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 6 Jul 2016 15:37:13 +0600 Subject: COMMON: Add replace(String, String, String) Searches for a substring in the string and replaces it with the other string. --- common/str.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'common/str.cpp') diff --git a/common/str.cpp b/common/str.cpp index 326b4a80d1..90bd539790 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -838,6 +838,15 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod } } +void replace(Common::String &source, const Common::String &what, const Common::String &with) { + const char *cstr = source.c_str(); + const char *position = strstr(cstr, what.c_str()); + if (position) { + uint32 index = position - cstr; + source.replace(index, what.size(), with); + } +} + String tag2string(uint32 tag) { char str[5]; str[0] = (char)(tag >> 24); -- cgit v1.2.3