aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/str.cpp56
-rw-r--r--common/str.h116
2 files changed, 86 insertions, 86 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 6dd5d911a7..3517315e95 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -37,7 +37,7 @@
namespace Common {
-MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now
+MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now
static uint32 computeCapacity(uint32 len) {
// By default, for the capacity we use the next multiple of 32
@@ -84,7 +84,7 @@ void String::initWithCStr(const char *str, uint32 len) {
}
String::String(const String &str)
- : _size(str._size) {
+ : _size(str._size) {
if (str.isStorageIntern()) {
// String in internal storage: just copy it
memcpy(_storage, str._storage, _builtinCapacity);
@@ -100,7 +100,7 @@ String::String(const String &str)
}
String::String(char c)
-: _size(0), _str(_storage) {
+ : _size(0), _str(_storage) {
_storage[0] = c;
_storage[1] = 0;
@@ -219,7 +219,7 @@ void String::decRefCount(int *oldRefCount) {
}
}
-String& String::operator =(const char *str) {
+String &String::operator=(const char *str) {
uint32 len = strlen(str);
ensureCapacity(len, false);
_size = len;
@@ -227,7 +227,7 @@ String& String::operator =(const char *str) {
return *this;
}
-String &String::operator =(const String &str) {
+String &String::operator=(const String &str) {
if (&str == this)
return *this;
@@ -249,7 +249,7 @@ String &String::operator =(const String &str) {
return *this;
}
-String& String::operator =(char c) {
+String &String::operator=(char c) {
decRefCount(_extern._refCount);
_str = _storage;
_size = 1;
@@ -258,7 +258,7 @@ String& String::operator =(char c) {
return *this;
}
-String &String::operator +=(const char *str) {
+String &String::operator+=(const char *str) {
if (_str <= str && str <= _str + _size)
return operator+=(Common::String(str));
@@ -272,7 +272,7 @@ String &String::operator +=(const char *str) {
return *this;
}
-String &String::operator +=(const String &str) {
+String &String::operator+=(const String &str) {
if (&str == this)
return operator+=(Common::String(str));
@@ -286,7 +286,7 @@ String &String::operator +=(const String &str) {
return *this;
}
-String &String::operator +=(char c) {
+String &String::operator+=(char c) {
ensureCapacity(_size + 1, true);
_str[_size++] = c;
@@ -363,7 +363,7 @@ void String::deleteChar(uint32 p) {
makeUnique();
while (p++ < _size)
- _str[p-1] = _str[p];
+ _str[p - 1] = _str[p];
_size--;
}
@@ -388,7 +388,7 @@ void String::insertChar(char c, uint32 p) {
ensureCapacity(_size + 1, true);
_size++;
for (uint32 i = _size; i > p; --i)
- _str[i] = _str[i-1];
+ _str[i] = _str[i - 1];
_str[p] = c;
}
@@ -411,8 +411,8 @@ void String::trim() {
makeUnique();
// Trim trailing whitespace
- while (_size >= 1 && isspace(_str[_size-1]))
- _size--;
+ while (_size >= 1 && isspace(_str[_size - 1]))
+ --_size;
_str[_size] = 0;
// Trim leading whitespace
@@ -449,7 +449,7 @@ String String::printf(const char *fmt, ...) {
int size = _builtinCapacity;
do {
size *= 2;
- output.ensureCapacity(size-1, false);
+ output.ensureCapacity(size - 1, false);
assert(!output.isStorageIntern());
size = output._extern._capacity;
@@ -477,16 +477,16 @@ String String::printf(const char *fmt, ...) {
#pragma mark -
-bool String::operator ==(const String &x) const {
+bool String::operator==(const String &x) const {
return equals(x);
}
-bool String::operator ==(const char *x) const {
+bool String::operator==(const char *x) const {
assert(x != 0);
return equals(x);
}
-bool String::operator !=(const String &x) const {
+bool String::operator!=(const String &x) const {
return !equals(x);
}
@@ -495,29 +495,29 @@ bool String::operator !=(const char *x) const {
return !equals(x);
}
-bool String::operator < (const String &x) const {
+bool String::operator<(const String &x) const {
return compareTo(x) < 0;
}
-bool String::operator <= (const String &x) const {
+bool String::operator<=(const String &x) const {
return compareTo(x) <= 0;
}
-bool String::operator > (const String &x) const {
+bool String::operator>(const String &x) const {
return compareTo(x) > 0;
}
-bool String::operator >= (const String &x) const {
+bool String::operator>=(const String &x) const {
return compareTo(x) >= 0;
}
#pragma mark -
-bool operator == (const char* y, const String &x) {
+bool operator==(const char* y, const String &x) {
return (x == y);
}
-bool operator != (const char* y, const String &x) {
+bool operator!=(const char* y, const String &x) {
return x != y;
}
@@ -561,31 +561,31 @@ int String::compareToIgnoreCase(const char *x) const {
#pragma mark -
-String operator +(const String &x, const String &y) {
+String operator+(const String &x, const String &y) {
String temp(x);
temp += y;
return temp;
}
-String operator +(const char *x, const String &y) {
+String operator+(const char *x, const String &y) {
String temp(x);
temp += y;
return temp;
}
-String operator +(const String &x, const char *y) {
+String operator+(const String &x, const char *y) {
String temp(x);
temp += y;
return temp;
}
-String operator +(char x, const String &y) {
+String operator+(char x, const String &y) {
String temp(x);
temp += y;
return temp;
}
-String operator +(const String &x, char y) {
+String operator+(const String &x, char y) {
String temp(x);
temp += y;
return temp;
diff --git a/common/str.h b/common/str.h
index 60103e0242..de0f37cd62 100644
--- a/common/str.h
+++ b/common/str.h
@@ -54,20 +54,20 @@ protected:
* than 8 makes no sense, since that's the size of member _extern
* (on 32 bit machines; 12 bytes on systems with 64bit pointers).
*/
- static const uint32 _builtinCapacity = 32 - sizeof(uint32) - sizeof(char*);
+ static const uint32 _builtinCapacity = 32 - sizeof(uint32) - sizeof(char *);
/**
* Length of the string. Stored to avoid having to call strlen
* a lot. Yes, we limit ourselves to strings shorter than 4GB --
* on purpose :-).
*/
- uint32 _size;
+ uint32 _size;
/**
* Pointer to the actual string storage. Either points to _storage,
* or to a block allocated on the heap via malloc.
*/
- char *_str;
+ char *_str;
union {
@@ -81,7 +81,7 @@ protected:
*/
struct {
mutable int *_refCount;
- uint32 _capacity;
+ uint32 _capacity;
} _extern;
};
@@ -110,32 +110,32 @@ public:
~String();
- String &operator =(const char *str);
- String &operator =(const String &str);
- String &operator =(char c);
- String &operator +=(const char *str);
- String &operator +=(const String &str);
- String &operator +=(char c);
+ String &operator=(const char *str);
+ String &operator=(const String &str);
+ String &operator=(char c);
+ String &operator+=(const char *str);
+ String &operator+=(const String &str);
+ String &operator+=(char c);
- bool operator ==(const String &x) const;
- bool operator ==(const char *x) const;
- bool operator !=(const String &x) const;
- bool operator !=(const char *x) const;
+ bool operator==(const String &x) const;
+ bool operator==(const char *x) const;
+ bool operator!=(const String &x) const;
+ bool operator!=(const char *x) const;
- bool operator <(const String &x) const;
- bool operator <=(const String &x) const;
- bool operator >(const String &x) const;
- bool operator >=(const String &x) const;
+ bool operator<(const String &x) const;
+ bool operator<=(const String &x) const;
+ bool operator>(const String &x) const;
+ bool operator>=(const String &x) const;
bool equals(const String &x) const;
bool equalsIgnoreCase(const String &x) const;
- int compareTo(const String &x) const; // strcmp clone
- int compareToIgnoreCase(const String &x) const; // stricmp clone
+ int compareTo(const String &x) const; // strcmp clone
+ int compareToIgnoreCase(const String &x) const; // stricmp clone
bool equals(const char *x) const;
bool equalsIgnoreCase(const char *x) const;
- int compareTo(const char *x) const; // strcmp clone
- int compareToIgnoreCase(const char *x) const; // stricmp clone
+ int compareTo(const char *x) const; // strcmp clone
+ int compareToIgnoreCase(const char *x) const; // stricmp clone
bool hasSuffix(const String &x) const;
bool hasSuffix(const char *x) const;
@@ -152,15 +152,15 @@ public:
* Taken from exult/files/listfiles.cc
*
* Token meaning:
- * "*": any character, any amount of times.
- * "?": any character, only once.
+ * "*": any character, any amount of times.
+ * "?": any character, only once.
*
* Example strings/patterns:
- * String: monkey.s01 Pattern: monkey.s?? => true
- * String: monkey.s101 Pattern: monkey.s?? => false
- * String: monkey.s99 Pattern: monkey.s?1 => false
- * String: monkey.s101 Pattern: monkey.s* => true
- * String: monkey.s99 Pattern: monkey.s*1 => false
+ * String: monkey.s01 Pattern: monkey.s?? => true
+ * String: monkey.s101 Pattern: monkey.s?? => false
+ * String: monkey.s99 Pattern: monkey.s?1 => false
+ * String: monkey.s101 Pattern: monkey.s* => true
+ * String: monkey.s99 Pattern: monkey.s*1 => false
*
* @param str Text to be matched against the given pattern.
* @param pat Glob pattern.
@@ -173,11 +173,11 @@ public:
bool matchString(const String &pat, bool ignoreCase = false, bool pathMode = false) const;
- inline const char *c_str() const { return _str; }
- inline uint size() const { return _size; }
+ inline const char *c_str() const { return _str; }
+ inline uint size() const { return _size; }
- inline bool empty() const { return (_size == 0); }
- char lastChar() const { return (_size > 0) ? _str[_size-1] : 0; }
+ inline bool empty() const { return (_size == 0); }
+ char lastChar() const { return (_size > 0) ? _str[_size - 1] : 0; }
char operator[](int idx) const {
assert(_str && idx >= 0 && idx < (int)_size);
@@ -222,19 +222,19 @@ public:
typedef char * iterator;
typedef const char * const_iterator;
- iterator begin() {
+ iterator begin() {
return _str;
}
- iterator end() {
+ iterator end() {
return begin() + size();
}
- const_iterator begin() const {
+ const_iterator begin() const {
return _str;
}
- const_iterator end() const {
+ const_iterator end() const {
return begin() + size();
}
@@ -247,17 +247,17 @@ protected:
};
// Append two strings to form a new (temp) string
-String operator +(const String &x, const String &y);
+String operator+(const String &x, const String &y);
-String operator +(const char *x, const String &y);
-String operator +(const String &x, const char *y);
+String operator+(const char *x, const String &y);
+String operator+(const String &x, const char *y);
-String operator +(const String &x, char y);
-String operator +(char x, const String &y);
+String operator+(const String &x, char y);
+String operator+(char x, const String &y);
// Some useful additional comparison operators for Strings
-bool operator == (const char *x, const String &y);
-bool operator != (const char *x, const String &y);
+bool operator==(const char *x, const String &y);
+bool operator!=(const char *x, const String &y);
// Utility functions to remove leading and trailing whitespaces
extern char *ltrim(char *t);
@@ -269,9 +269,9 @@ extern char *trim(char *t);
* Returns the last component of a given path.
*
* Examples:
- * /foo/bar.txt would return 'bar.txt'
- * /foo/bar/ would return 'bar'
- * /foo/./bar// would return 'bar'
+ * /foo/bar.txt would return 'bar.txt'
+ * /foo/bar/ would return 'bar'
+ * /foo/./bar// would return 'bar'
*
* @param path the path of which we want to know the last component
* @param sep character used to separate path components
@@ -287,9 +287,9 @@ Common::String lastPathComponent(const Common::String &path, const char sep);
*
* @todo remove double dot components: /foo/baz/../bar -> /foo/bar
*
- * @param path the path to normalize
- * @param sep the separator token (usually '/' on Unix-style systems, or '\\' on Windows based stuff)
- * @return the normalized path
+ * @param path the path to normalize
+ * @param sep the separator token (usually '/' on Unix-style systems, or '\\' on Windows based stuff)
+ * @return the normalized path
*/
Common::String normalizePath(const Common::String &path, const char sep);
@@ -299,15 +299,15 @@ Common::String normalizePath(const Common::String &path, const char sep);
* Taken from exult/files/listfiles.cc
*
* Token meaning:
- * "*": any character, any amount of times.
- * "?": any character, only once.
+ * "*": any character, any amount of times.
+ * "?": any character, only once.
*
* Example strings/patterns:
- * String: monkey.s01 Pattern: monkey.s?? => true
- * String: monkey.s101 Pattern: monkey.s?? => false
- * String: monkey.s99 Pattern: monkey.s?1 => false
- * String: monkey.s101 Pattern: monkey.s* => true
- * String: monkey.s99 Pattern: monkey.s*1 => false
+ * String: monkey.s01 Pattern: monkey.s?? => true
+ * String: monkey.s101 Pattern: monkey.s?? => false
+ * String: monkey.s99 Pattern: monkey.s?1 => false
+ * String: monkey.s101 Pattern: monkey.s* => true
+ * String: monkey.s99 Pattern: monkey.s*1 => false
*
* @param str Text to be matched against the given pattern.
* @param pat Glob pattern.
@@ -321,6 +321,6 @@ bool matchString(const char *str, const char *pat, bool ignoreCase = false, bool
typedef Array<String> StringList;
-} // End of namespace Common
+} // End of namespace Common
#endif