version 1.111.6.15, 2005/10/14 14:09:29
|
version 1.116.4.1, 2006/01/18 17:37:56
|
|
|
// Modified By: | // Modified By: |
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) | // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3297 | // Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3297 |
// David Dillard, VERITAS Software Corp. (david.dillard@veritas.com) |
// David Dillard, Symantec Corp. (david_dillard@symantec.com) |
// Mike Brasher (mike-brasher@austin.rr.com) | // Mike Brasher (mike-brasher@austin.rr.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include <cassert> |
#include <Pegasus/Common/PegasusAssert.h> |
|
#include <cstring> |
#include "InternalException.h" | #include "InternalException.h" |
#include "CommonUTF.h" | #include "CommonUTF.h" |
#include "MessageLoader.h" | #include "MessageLoader.h" |
|
|
| |
inline void _checkNullPointer(const void* ptr) | inline void _checkNullPointer(const void* ptr) |
{ | { |
#ifdef PEGASUS_STRING_NO_THROW |
#ifndef PEGASUS_STRING_NO_THROW |
| |
if (!ptr) | if (!ptr) |
throw NullPointer(); | throw NullPointer(); |
|
|
| |
static inline void _reserve(StringRep*& rep, Uint32 cap) | static inline void _reserve(StringRep*& rep, Uint32 cap) |
{ | { |
if (cap > rep->cap || rep->refs.value() != 1) |
if (cap > rep->cap || rep->refs.get() != 1) |
{ | { |
size_t n = _roundUpToPow2(cap); | size_t n = _roundUpToPow2(cap); |
StringRep* newRep = StringRep::alloc(n); | StringRep* newRep = StringRep::alloc(n); |
|
|
{ | { |
_checkNullPointer(str); | _checkNullPointer(str); |
| |
if (n > _rep->cap || _rep->refs.value() != 1) |
if (n > _rep->cap || _rep->refs.get() != 1) |
{ | { |
StringRep::unref(_rep); | StringRep::unref(_rep); |
_rep = StringRep::alloc(n); | _rep = StringRep::alloc(n); |
|
|
{ | { |
_checkNullPointer(str); | _checkNullPointer(str); |
| |
if (n > _rep->cap || _rep->refs.value() != 1) |
if (n > _rep->cap || _rep->refs.get() != 1) |
{ | { |
StringRep::unref(_rep); | StringRep::unref(_rep); |
_rep = StringRep::alloc(n); | _rep = StringRep::alloc(n); |
|
|
{ | { |
if (_rep->size) | if (_rep->size) |
{ | { |
if (_rep->refs.value() == 1) |
if (_rep->refs.get() == 1) |
{ | { |
_rep->size = 0; | _rep->size = 0; |
_rep->data[0] = '\0'; | _rep->data[0] = '\0'; |
|
|
| |
_checkBounds(index + n, _rep->size); | _checkBounds(index + n, _rep->size); |
| |
if (_rep->refs.value() != 1) |
if (_rep->refs.get() != 1) |
_rep = StringRep::copyOnWrite(_rep); | _rep = StringRep::copyOnWrite(_rep); |
| |
assert(index + n <= _rep->size); |
PEGASUS_ASSERT(index + n <= _rep->size); |
| |
size_t rem = _rep->size - (index + n); | size_t rem = _rep->size - (index + n); |
Uint16* data = _rep->data; | Uint16* data = _rep->data; |
|
|
Uint16* p = (Uint16*)_find(_rep->data, _rep->size, c); | Uint16* p = (Uint16*)_find(_rep->data, _rep->size, c); |
| |
if (p) | if (p) |
return p - _rep->data; |
return static_cast<Uint32>(p - _rep->data); |
| |
return PEG_NOT_FOUND; | return PEG_NOT_FOUND; |
} | } |
|
|
Uint16* p = (Uint16*)_find(_rep->data + index, _rep->size - index, c); | Uint16* p = (Uint16*)_find(_rep->data + index, _rep->size - index, c); |
| |
if (p) | if (p) |
return p - _rep->data; |
return static_cast<Uint32>(p - _rep->data); |
| |
return PEG_NOT_FOUND; | return PEG_NOT_FOUND; |
} | } |
|
|
break; | break; |
| |
if (memcmp(p, s, n * sizeof(Uint16)) == 0) | if (memcmp(p, s, n * sizeof(Uint16)) == 0) |
return p - _rep->data; |
return static_cast<Uint32>(p - _rep->data); |
| |
p++; | p++; |
rem -= p - data; | rem -= p - data; |
|
|
while (q != p) | while (q != p) |
{ | { |
if (*--q == x) | if (*--q == x) |
return q - p; |
return static_cast<Uint32>(q - p); |
} | } |
| |
return PEG_NOT_FOUND; | return PEG_NOT_FOUND; |
|
|
| |
if (InitializeICU::initICUSuccessful()) | if (InitializeICU::initICUSuccessful()) |
{ | { |
if (_rep->refs.value() != 1) |
if (_rep->refs.get() != 1) |
_rep = StringRep::copyOnWrite(_rep); | _rep = StringRep::copyOnWrite(_rep); |
| |
// This will do a locale-insensitive, but context-sensitive convert. | // This will do a locale-insensitive, but context-sensitive convert. |
|
|
| |
#endif /* PEGASUS_HAS_ICU */ | #endif /* PEGASUS_HAS_ICU */ |
| |
if (_rep->refs.value() != 1) |
if (_rep->refs.get() != 1) |
_rep = StringRep::copyOnWrite(_rep); | _rep = StringRep::copyOnWrite(_rep); |
| |
Uint16* p = _rep->data; | Uint16* p = _rep->data; |
|
|
| |
if (InitializeICU::initICUSuccessful()) | if (InitializeICU::initICUSuccessful()) |
{ | { |
if (_rep->refs.value() != 1) |
if (_rep->refs.get() != 1) |
_rep = StringRep::copyOnWrite(_rep); | _rep = StringRep::copyOnWrite(_rep); |
| |
// This will do a locale-insensitive, but context-sensitive convert. | // This will do a locale-insensitive, but context-sensitive convert. |
|
|
| |
#endif /* PEGASUS_HAS_ICU */ | #endif /* PEGASUS_HAS_ICU */ |
| |
if (_rep->refs.value() != 1) |
if (_rep->refs.get() != 1) |
_rep = StringRep::copyOnWrite(_rep); | _rep = StringRep::copyOnWrite(_rep); |
| |
Uint16* p = _rep->data; | Uint16* p = _rep->data; |
|
|
| |
int String::compare(const String& s1, const String& s2, Uint32 n) | int String::compare(const String& s1, const String& s2, Uint32 n) |
{ | { |
assert(n <= s1._rep->size); |
PEGASUS_ASSERT(n <= s1._rep->size); |
assert(n <= s2._rep->size); |
PEGASUS_ASSERT(n <= s2._rep->size); |
| |
// Ignoring error in which n is greater than s1.size() or s2.size() | // Ignoring error in which n is greater than s1.size() or s2.size() |
return _compare(s1._rep->data, s2._rep->data, n); | return _compare(s1._rep->data, s2._rep->data, n); |
|
|
| |
(+) [DONE] Look at PEP223 for coding security guidelines. | (+) [DONE] Look at PEP223 for coding security guidelines. |
| |
(+) [DONE] Use old AtomicInt for now (split new AtomicInt into another |
(+) [DONE] Use old AtomicInt for now (new AtomicInt part of bug #4250). |
bug. |
|
| |
(+) [DONE] Removed appendASCII() and the ASCII form of the constructor. | (+) [DONE] Removed appendASCII() and the ASCII form of the constructor. |
| |
----------- |
(+) DOC++ String.h - will open new bug? |
| |
(+) DOC++ String.h |
(+) Added PEGASUS_DISABLE_INTERNAL_INLINES macro (to permit suppression |
|
on certain platforms). |
| |
================================================================================ | ================================================================================ |
*/ | */ |