2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-09-08 01:08:12 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-09-08 01:08:12 +00:00
|
|
|
*
|
2006-02-11 09:53:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-09-08 01:08:12 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2006-06-02 13:34:41 +00:00
|
|
|
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/str.h"
|
2006-07-30 12:21:54 +00:00
|
|
|
#include "common/hash-str.h"
|
2006-06-02 13:34:41 +00:00
|
|
|
#include "common/util.h"
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2003-10-02 17:43:02 +00:00
|
|
|
namespace Common {
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2005-11-27 02:35:57 +00:00
|
|
|
#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
|
2003-10-06 23:19:01 +00:00
|
|
|
const String String::emptyString;
|
2005-10-08 19:07:18 +00:00
|
|
|
#else
|
|
|
|
const char *String::emptyString = "";
|
|
|
|
#endif
|
2003-10-06 23:19:01 +00:00
|
|
|
|
2006-06-03 16:33:42 +00:00
|
|
|
static int computeCapacity(int len) {
|
|
|
|
// By default, for the capacity we use the nearest multiple of 32
|
|
|
|
// that leaves at least 16 chars of extra space (in case the string
|
|
|
|
// grows a bit).
|
|
|
|
// Finally, we subtract 1 to compensate for the trailing zero byte.
|
|
|
|
len += 16;
|
2006-06-10 07:56:09 +00:00
|
|
|
return ((len + 32 - 1) & ~0x1F) - 1;
|
2006-06-03 16:33:42 +00:00
|
|
|
}
|
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
String::String(const char *str, uint32 len)
|
2006-11-27 00:51:14 +00:00
|
|
|
: _len(0), _str(_storage) {
|
|
|
|
|
|
|
|
// Init _storage member explicitly (ie. without calling its constructor)
|
|
|
|
// for GCC 2.95.x compatibility (see also tracker item #1602879).
|
|
|
|
_storage[0] = 0;
|
2006-09-30 18:55:38 +00:00
|
|
|
|
|
|
|
if (str && *str) {
|
|
|
|
const uint32 tmp = strlen(str);
|
|
|
|
assert(len <= tmp);
|
|
|
|
if (len <= 0)
|
|
|
|
len = tmp;
|
|
|
|
_len = len;
|
|
|
|
|
|
|
|
if (len >= _builtinCapacity) {
|
|
|
|
// Not enough internal storage, so allocate more
|
|
|
|
_extern._capacity = computeCapacity(len);
|
|
|
|
_extern._refCount = 0;
|
|
|
|
_str = (char *)malloc(_extern._capacity+1);
|
|
|
|
assert(_str != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the string into the storage area
|
|
|
|
memcpy(_str, str, len);
|
|
|
|
_str[len] = 0;
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-15 21:42:59 +00:00
|
|
|
String::String(const String &str)
|
2006-09-30 18:55:38 +00:00
|
|
|
: _len(str._len), _str(str.isStorageIntern() ? _storage : str._str) {
|
|
|
|
if (str.isStorageIntern()) {
|
|
|
|
// String in internal storage: just copy it
|
|
|
|
memcpy(_storage, str._storage, _builtinCapacity);
|
|
|
|
} else {
|
|
|
|
// String in external storage: use refcount mechanism
|
2006-06-05 17:36:08 +00:00
|
|
|
str.incRefCount();
|
2006-09-30 18:55:38 +00:00
|
|
|
_extern._refCount = str._extern._refCount;
|
|
|
|
_extern._capacity = str._extern._capacity;
|
2006-06-05 17:36:08 +00:00
|
|
|
}
|
2006-09-30 18:55:38 +00:00
|
|
|
assert(_str != 0);
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
2007-06-02 12:42:40 +00:00
|
|
|
|
|
|
|
String::String(char c)
|
|
|
|
: _len(0), _str(_storage) {
|
2006-09-30 18:55:38 +00:00
|
|
|
|
2007-06-02 12:42:40 +00:00
|
|
|
_storage[0] = c;
|
|
|
|
_storage[1] = 0;
|
|
|
|
|
|
|
|
_len = (c == 0) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
String::~String() {
|
2006-09-30 18:55:38 +00:00
|
|
|
decRefCount(_extern._refCount);
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
|
2006-06-03 16:33:42 +00:00
|
|
|
void String::incRefCount() const {
|
2006-09-30 18:55:38 +00:00
|
|
|
assert(!isStorageIntern());
|
|
|
|
if (_extern._refCount == 0) {
|
|
|
|
_extern._refCount = new int(2);
|
2006-06-03 16:33:42 +00:00
|
|
|
} else {
|
2006-09-30 18:55:38 +00:00
|
|
|
++(*_extern._refCount);
|
2006-06-03 16:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
void String::decRefCount(int *oldRefCount) {
|
|
|
|
if (isStorageIntern())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (oldRefCount) {
|
|
|
|
--(*oldRefCount);
|
2006-06-05 17:36:08 +00:00
|
|
|
}
|
2006-09-30 18:55:38 +00:00
|
|
|
if (!oldRefCount || *oldRefCount <= 0) {
|
|
|
|
// The ref count reached zero, so we free the string storage
|
|
|
|
// and the ref count storage.
|
|
|
|
delete oldRefCount;
|
2004-03-25 11:25:50 +00:00
|
|
|
free(_str);
|
2006-09-30 18:55:38 +00:00
|
|
|
|
|
|
|
// Even though _str points to a freed memory block now,
|
|
|
|
// we do not change its value, because any code that calls
|
|
|
|
// decRefCount will have to do this afterwards anyway.
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
String& String::operator =(const char *str) {
|
2006-09-30 18:55:38 +00:00
|
|
|
uint32 len = strlen(str);
|
|
|
|
ensureCapacity(len, false);
|
|
|
|
_len = len;
|
|
|
|
memcpy(_str, str, len + 1);
|
2002-09-08 01:08:12 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
String &String::operator =(const String &str) {
|
2006-09-30 18:55:38 +00:00
|
|
|
if (str.isStorageIntern()) {
|
|
|
|
decRefCount(_extern._refCount);
|
|
|
|
_len = str._len;
|
|
|
|
_str = _storage;
|
|
|
|
memcpy(_str, str._str, _len + 1);
|
|
|
|
} else {
|
|
|
|
str.incRefCount();
|
|
|
|
decRefCount(_extern._refCount);
|
|
|
|
|
|
|
|
_extern._refCount = str._extern._refCount;
|
|
|
|
_extern._capacity = str._extern._capacity;
|
|
|
|
_len = str._len;
|
|
|
|
_str = str._str;
|
|
|
|
}
|
2002-09-08 01:08:12 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2004-07-21 14:20:37 +00:00
|
|
|
String& String::operator =(char c) {
|
|
|
|
ensureCapacity(1, false);
|
|
|
|
_len = 1;
|
|
|
|
_str[0] = c;
|
|
|
|
_str[1] = 0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
String &String::operator +=(const char *str) {
|
2002-09-28 19:25:09 +00:00
|
|
|
int len = strlen(str);
|
2002-09-08 01:08:12 +00:00
|
|
|
if (len > 0) {
|
|
|
|
ensureCapacity(_len + len, true);
|
|
|
|
|
|
|
|
memcpy(_str + _len, str, len + 1);
|
|
|
|
_len += len;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
String &String::operator +=(const String &str) {
|
2002-09-08 01:08:12 +00:00
|
|
|
int len = str._len;
|
|
|
|
if (len > 0) {
|
|
|
|
ensureCapacity(_len + len, true);
|
|
|
|
|
|
|
|
memcpy(_str + _len, str._str, len + 1);
|
|
|
|
_len += len;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
String &String::operator +=(char c) {
|
2002-09-08 01:08:12 +00:00
|
|
|
ensureCapacity(_len + 1, true);
|
2003-03-06 16:27:06 +00:00
|
|
|
|
2002-09-08 01:08:12 +00:00
|
|
|
_str[_len++] = c;
|
|
|
|
_str[_len] = 0;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2005-02-06 19:00:59 +00:00
|
|
|
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.
|
2006-09-30 18:55:38 +00:00
|
|
|
const uint32 x_len = strlen(x);
|
2005-02-06 19:00:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-04-15 18:27:10 +00:00
|
|
|
bool String::contains(const char *x) const {
|
|
|
|
assert(x != 0);
|
|
|
|
return strstr(c_str(), x) != NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-08 11:46:42 +00:00
|
|
|
void String::deleteLastChar() {
|
2006-09-30 18:55:38 +00:00
|
|
|
deleteChar(_len - 1);
|
2002-09-08 11:46:42 +00:00
|
|
|
}
|
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
void String::deleteChar(uint32 p) {
|
|
|
|
assert(p < _len);
|
|
|
|
|
|
|
|
// Call ensureCapacity to make sure we actually *own* the storage
|
|
|
|
// to which _str points to -- we wouldn't want to modify a storage
|
|
|
|
// which other string objects are sharing, after all.
|
2006-12-17 19:41:41 +00:00
|
|
|
ensureCapacity(_len, true);
|
2006-09-30 18:55:38 +00:00
|
|
|
while (p++ < _len)
|
|
|
|
_str[p-1] = _str[p];
|
|
|
|
_len--;
|
2003-01-10 21:33:42 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
void String::clear() {
|
2006-09-30 18:55:38 +00:00
|
|
|
decRefCount(_extern._refCount);
|
2003-03-06 16:27:06 +00:00
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
_len = 0;
|
|
|
|
_str = _storage;
|
|
|
|
_storage[0] = 0;
|
2002-09-08 11:46:42 +00:00
|
|
|
}
|
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
void String::insertChar(char c, uint32 p) {
|
|
|
|
assert(p <= _len);
|
|
|
|
|
|
|
|
ensureCapacity(_len + 1, true);
|
|
|
|
_len++;
|
|
|
|
for (uint32 i = _len; i > p; --i)
|
|
|
|
_str[i] = _str[i-1];
|
|
|
|
_str[p] = c;
|
2003-01-10 21:33:42 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
void String::toLowercase() {
|
2006-04-16 09:12:27 +00:00
|
|
|
ensureCapacity(_len, true);
|
2006-09-30 18:55:38 +00:00
|
|
|
for (uint32 i = 0; i < _len; ++i)
|
2002-10-08 00:11:41 +00:00
|
|
|
_str[i] = tolower(_str[i]);
|
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
void String::toUppercase() {
|
2006-04-16 09:12:27 +00:00
|
|
|
ensureCapacity(_len, true);
|
2006-09-30 18:55:38 +00:00
|
|
|
for (uint32 i = 0; i < _len; ++i)
|
2002-10-08 00:11:41 +00:00
|
|
|
_str[i] = toupper(_str[i]);
|
|
|
|
}
|
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
/**
|
|
|
|
* Ensure that enough storage is available to store at least new_len
|
|
|
|
* characters plus a null byte. In addition, if we currently share
|
|
|
|
* the storage with another string, unshare it, so that we can safely
|
|
|
|
* write to the storage.
|
|
|
|
*/
|
|
|
|
void String::ensureCapacity(uint32 new_len, bool keep_old) {
|
|
|
|
bool isShared;
|
|
|
|
uint32 curCapacity, newCapacity;
|
|
|
|
char *newStorage;
|
|
|
|
int *oldRefCount = _extern._refCount;
|
|
|
|
|
|
|
|
if (isStorageIntern()) {
|
|
|
|
isShared = false;
|
|
|
|
curCapacity = _builtinCapacity - 1;
|
|
|
|
} else {
|
|
|
|
isShared = (oldRefCount && *oldRefCount > 1);
|
|
|
|
curCapacity = _extern._capacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special case: If there is enough space, and we do not share
|
|
|
|
// the storage, then there is nothing to do.
|
|
|
|
if (!isShared && new_len <= curCapacity)
|
2002-09-08 11:46:42 +00:00
|
|
|
return;
|
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
if (isShared && new_len <= _builtinCapacity - 1) {
|
|
|
|
// We share the storage, but there is enough internal storage: Use that.
|
|
|
|
newStorage = _storage;
|
|
|
|
newCapacity = _builtinCapacity - 1;
|
|
|
|
} else {
|
|
|
|
// We need to allocate storage on the heap!
|
2006-06-03 16:33:42 +00:00
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
// Compute a suitable new capacity limit
|
|
|
|
newCapacity = computeCapacity(new_len);
|
2006-06-03 16:33:42 +00:00
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
// Allocate new storage
|
|
|
|
newStorage = (char *)malloc(newCapacity+1);
|
|
|
|
assert(newStorage);
|
|
|
|
}
|
2002-09-08 11:46:42 +00:00
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
// Copy old data if needed, elsewise reset the new storage.
|
|
|
|
if (keep_old) {
|
|
|
|
assert(_len <= newCapacity);
|
|
|
|
memcpy(newStorage, _str, _len + 1);
|
2006-06-04 09:14:07 +00:00
|
|
|
} else {
|
2002-09-08 11:46:42 +00:00
|
|
|
_len = 0;
|
2006-09-30 18:55:38 +00:00
|
|
|
newStorage[0] = 0;
|
2006-06-04 09:14:07 +00:00
|
|
|
}
|
2002-09-08 11:46:42 +00:00
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
// Release hold on the old storage ...
|
|
|
|
decRefCount(oldRefCount);
|
2003-03-06 16:27:06 +00:00
|
|
|
|
2006-09-30 18:55:38 +00:00
|
|
|
// ... in favor of the new storage
|
|
|
|
_str = newStorage;
|
|
|
|
|
|
|
|
if (!isStorageIntern()) {
|
|
|
|
// Set the ref count & capacity if we use an external storage.
|
|
|
|
// It is important to do this *after* copying any old content,
|
|
|
|
// else we would override data that has not yet been copied!
|
|
|
|
_extern._refCount = 0;
|
|
|
|
_extern._capacity = newCapacity;
|
|
|
|
}
|
2002-09-08 11:46:42 +00:00
|
|
|
}
|
|
|
|
|
2006-07-30 12:17:51 +00:00
|
|
|
uint String::hash() const {
|
|
|
|
return hashit(c_str());
|
|
|
|
}
|
|
|
|
|
2002-09-08 11:46:42 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2005-01-15 21:42:59 +00:00
|
|
|
bool String::operator ==(const String &x) const {
|
2006-07-30 12:17:51 +00:00
|
|
|
return equals(x);
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 21:42:59 +00:00
|
|
|
bool String::operator ==(const char *x) const {
|
2003-11-07 00:02:03 +00:00
|
|
|
assert(x != 0);
|
2006-07-30 12:17:51 +00:00
|
|
|
return equals(x);
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 21:42:59 +00:00
|
|
|
bool String::operator !=(const String &x) const {
|
2006-07-30 12:17:51 +00:00
|
|
|
return !equals(x);
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 21:42:59 +00:00
|
|
|
bool String::operator !=(const char *x) const {
|
2003-11-07 00:02:03 +00:00
|
|
|
assert(x != 0);
|
2006-07-30 12:17:51 +00:00
|
|
|
return !equals(x);
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 21:42:59 +00:00
|
|
|
bool String::operator < (const String &x) const {
|
2006-07-30 12:17:51 +00:00
|
|
|
return compareTo(x) < 0;
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 21:42:59 +00:00
|
|
|
bool String::operator <= (const String &x) const {
|
2006-07-30 12:17:51 +00:00
|
|
|
return compareTo(x) <= 0;
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 21:42:59 +00:00
|
|
|
bool String::operator > (const String &x) const {
|
2006-07-30 12:17:51 +00:00
|
|
|
return compareTo(x) > 0;
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 21:42:59 +00:00
|
|
|
bool String::operator >= (const String &x) const {
|
2006-07-30 12:17:51 +00:00
|
|
|
return compareTo(x) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
bool operator == (const char* y, const String &x) {
|
|
|
|
return (x == y);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (const char* y, const String &x) {
|
|
|
|
return x != y;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
bool String::equals(const String &x) const {
|
|
|
|
return (0 == compareTo(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::equals(const char *x) const {
|
|
|
|
assert(x != 0);
|
|
|
|
return (0 == compareTo(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::equalsIgnoreCase(const String &x) const {
|
|
|
|
return (0 == compareToIgnoreCase(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool String::equalsIgnoreCase(const char *x) const {
|
|
|
|
assert(x != 0);
|
|
|
|
return (0 == compareToIgnoreCase(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::compareTo(const String &x) const {
|
|
|
|
return compareTo(x.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::compareTo(const char *x) const {
|
|
|
|
assert(x != 0);
|
|
|
|
return strcmp(c_str(), x);
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::compareToIgnoreCase(const String &x) const {
|
|
|
|
return compareToIgnoreCase(x.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
int String::compareToIgnoreCase(const char *x) const {
|
|
|
|
assert(x != 0);
|
|
|
|
return scumm_stricmp(c_str(), x);
|
2002-09-08 01:08:12 +00:00
|
|
|
}
|
|
|
|
|
2004-06-27 23:58:41 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
String operator +(const String &x, const String &y) {
|
|
|
|
String temp(x);
|
|
|
|
temp += y;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
String operator +(const char *x, const String &y) {
|
|
|
|
String temp(x);
|
|
|
|
temp += y;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
String operator +(const String &x, const char *y) {
|
|
|
|
String temp(x);
|
|
|
|
temp += y;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2007-06-02 12:42:40 +00:00
|
|
|
String operator +(char x, const String &y) {
|
|
|
|
String temp(x);
|
|
|
|
temp += y;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
String operator +(const String &x, char y) {
|
|
|
|
String temp(x);
|
|
|
|
temp += y;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2007-02-13 21:06:57 +00:00
|
|
|
char *ltrim(char *t) {
|
|
|
|
while (isspace(*t))
|
|
|
|
t++;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *rtrim(char *t) {
|
|
|
|
int l = strlen(t) - 1;
|
|
|
|
while (l >= 0 && isspace(t[l]))
|
|
|
|
t[l--] = 0;
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *trim(char *t) {
|
|
|
|
return rtrim(ltrim(t));
|
|
|
|
}
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2003-10-02 17:43:02 +00:00
|
|
|
} // End of namespace Common
|