[Scummvm-cvs-logs] CVS: scummvm/common str.cpp,1.34,1.35 str.h,1.25,1.26
Max Horn
fingolfin at users.sourceforge.net
Sun Feb 6 11:03:04 CET 2005
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15512
Modified Files:
str.cpp str.h
Log Message:
Added String::hasSuffix and hasPrefix
Index: str.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/str.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- str.cpp 15 Jan 2005 21:42:59 -0000 1.34
+++ str.cpp 6 Feb 2005 19:00:58 -0000 1.35
@@ -136,6 +136,35 @@
return *this;
}
+bool String::hasPrefix(const char *x) const {
+ assert(x != 0);
+ // Compare x with the start of _str.
+ const char *y = c_str();
+ while (*x && *x == *y) {
+ ++x;
+ ++y;
+ }
+ // It's a prefix, if and only if all letters in x are 'used up' before
+ // _str ends.
+ return *x == 0;
+}
+
+bool String::hasSuffix(const char *x) const {
+ assert(x != 0);
+ // Compare x with the end of _str.
+ const int x_len = strlen(x);
+ if (x_len > _len)
+ return false;
+ const char *y = c_str() + _len - x_len;
+ while (*x && *x == *y) {
+ ++x;
+ ++y;
+ }
+ // It's a suffix, if and only if all letters in x are 'used up' before
+ // _str ends.
+ return *x == 0;
+}
+
void String::deleteLastChar() {
if (_len > 0) {
ensureCapacity(_len - 1, true);
Index: str.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/str.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- str.h 15 Jan 2005 21:42:59 -0000 1.25
+++ str.h 6 Feb 2005 19:00:59 -0000 1.26
@@ -60,6 +60,9 @@
bool operator >(const String &x) const;
bool operator >=(const String &x) const;
+ bool hasSuffix(const char *x) const;
+ bool hasPrefix(const char *x) const;
+
const char *c_str() const { return _str ? _str : ""; }
uint size() const { return _len; }
@@ -75,7 +78,7 @@
assert(_str && idx >= 0 && idx < _len);
return _str[idx];
}
-
+
void deleteLastChar();
void deleteChar(int p);
void clear();
More information about the Scummvm-git-logs
mailing list