version 1.121, 2006/05/30 15:41:57
|
version 1.122, 2006/08/09 20:03:27
|
|
|
// | // |
// Compile-time macros (undefined by default). | // Compile-time macros (undefined by default). |
// | // |
// PEGASUS_STRING_NO_THROW -- suppresses throwing of exceptions |
|
// |
|
// PEGASUS_STRING_NO_UTF8 -- don't generate slower UTF8 code. | // PEGASUS_STRING_NO_UTF8 -- don't generate slower UTF8 code. |
// | // |
//============================================================================== | //============================================================================== |
|
|
// Rounds x up to the nearest power of two (or just returns 8 if x < 8). | // Rounds x up to the nearest power of two (or just returns 8 if x < 8). |
static Uint32 _roundUpToPow2(Uint32 x) | static Uint32 _roundUpToPow2(Uint32 x) |
{ | { |
#ifndef PEGASUS_STRING_NO_THROW |
|
|
|
// Check for potential overflow in x | // Check for potential overflow in x |
PEGASUS_CHECK_CAPACITY_OVERFLOW(x); | PEGASUS_CHECK_CAPACITY_OVERFLOW(x); |
| |
#endif |
|
|
|
if (x < 8) | if (x < 8) |
return 8; | return 8; |
| |
|
|
| |
inline void _checkNullPointer(const void* ptr) | inline void _checkNullPointer(const void* ptr) |
{ | { |
#ifndef PEGASUS_STRING_NO_THROW |
|
|
|
if (!ptr) | if (!ptr) |
throw NullPointer(); | throw NullPointer(); |
|
|
#endif |
|
} | } |
| |
static void _StringThrowBadUTF8(Uint32 index) | static void _StringThrowBadUTF8(Uint32 index) |
|
|
| |
inline StringRep* StringRep::alloc(size_t cap) | inline StringRep* StringRep::alloc(size_t cap) |
{ | { |
#ifndef PEGASUS_STRING_NO_THROW |
|
|
|
// Check for potential overflow in cap | // Check for potential overflow in cap |
PEGASUS_CHECK_CAPACITY_OVERFLOW(cap); | PEGASUS_CHECK_CAPACITY_OVERFLOW(cap); |
| |
#endif |
|
|
|
StringRep* rep = (StringRep*)::operator new( | StringRep* rep = (StringRep*)::operator new( |
sizeof(StringRep) + cap * sizeof(Uint16)); | sizeof(StringRep) + cap * sizeof(Uint16)); |
rep->cap = cap; | rep->cap = cap; |
|
|
size_t utf8_error_index; | size_t utf8_error_index; |
rep->size = _convert((Uint16*)rep->data, data, size, utf8_error_index); | rep->size = _convert((Uint16*)rep->data, data, size, utf8_error_index); |
| |
#ifndef PEGASUS_STRING_NO_THROW |
|
if (rep->size == size_t(-1)) | if (rep->size == size_t(-1)) |
{ | { |
StringRep::free(rep); | StringRep::free(rep); |
_StringThrowBadUTF8(utf8_error_index); | _StringThrowBadUTF8(utf8_error_index); |
} | } |
#endif |
|
| |
rep->data[rep->size] = '\0'; | rep->data[rep->size] = '\0'; |
| |
|
|
size_t utf8_error_index; | size_t utf8_error_index; |
size_t tmp = _convert((Uint16*)_rep->data + n1, s2, n2, utf8_error_index); | size_t tmp = _convert((Uint16*)_rep->data + n1, s2, n2, utf8_error_index); |
| |
#ifndef PEGASUS_STRING_NO_THROW |
|
if (tmp == size_t(-1)) | if (tmp == size_t(-1)) |
{ | { |
StringRep::free(_rep); | StringRep::free(_rep); |
_rep = &StringRep::_emptyRep; | _rep = &StringRep::_emptyRep; |
_StringThrowBadUTF8(utf8_error_index); | _StringThrowBadUTF8(utf8_error_index); |
} | } |
#endif |
|
| |
_rep->size = n1 + tmp; | _rep->size = n1 + tmp; |
_rep->data[_rep->size] = '\0'; | _rep->data[_rep->size] = '\0'; |
|
|
size_t utf8_error_index; | size_t utf8_error_index; |
size_t tmp = _convert((Uint16*)_rep->data, s1, n1, utf8_error_index); | size_t tmp = _convert((Uint16*)_rep->data, s1, n1, utf8_error_index); |
| |
#ifndef PEGASUS_STRING_NO_THROW |
|
if (tmp == size_t(-1)) | if (tmp == size_t(-1)) |
{ | { |
StringRep::free(_rep); | StringRep::free(_rep); |
_rep = &StringRep::_emptyRep; | _rep = &StringRep::_emptyRep; |
_StringThrowBadUTF8(utf8_error_index); | _StringThrowBadUTF8(utf8_error_index); |
} | } |
#endif |
|
| |
_rep->size = n2 + tmp; | _rep->size = n2 + tmp; |
_copy(_rep->data + n1, s2._rep->data, n2); | _copy(_rep->data + n1, s2._rep->data, n2); |
|
|
size_t utf8_error_index; | size_t utf8_error_index; |
_rep->size = _convert(_rep->data, str, n, utf8_error_index); | _rep->size = _convert(_rep->data, str, n, utf8_error_index); |
| |
#ifndef PEGASUS_STRING_NO_THROW |
|
if (_rep->size == size_t(-1)) | if (_rep->size == size_t(-1)) |
{ | { |
StringRep::free(_rep); | StringRep::free(_rep); |
_rep = &StringRep::_emptyRep; | _rep = &StringRep::_emptyRep; |
_StringThrowBadUTF8(utf8_error_index); | _StringThrowBadUTF8(utf8_error_index); |
} | } |
#endif |
|
| |
_rep->data[_rep->size] = 0; | _rep->data[_rep->size] = 0; |
| |
|
|
size_t tmp = _convert( | size_t tmp = _convert( |
(Uint16*)_rep->data + oldSize, str, size, utf8_error_index); | (Uint16*)_rep->data + oldSize, str, size, utf8_error_index); |
| |
#ifndef PEGASUS_STRING_NO_THROW |
|
if (tmp == size_t(-1)) | if (tmp == size_t(-1)) |
{ | { |
StringRep::free(_rep); | StringRep::free(_rep); |
_rep = &StringRep::_emptyRep; | _rep = &StringRep::_emptyRep; |
_StringThrowBadUTF8(utf8_error_index); | _StringThrowBadUTF8(utf8_error_index); |
} | } |
#endif |
|
| |
_rep->size += tmp; | _rep->size += tmp; |
_rep->data[_rep->size] = '\0'; | _rep->data[_rep->size] = '\0'; |