version 1.111.6.15, 2005/10/14 14:09:29
|
version 1.116.2.1, 2006/02/10 16:09:38
|
|
|
//%2005//////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development | // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. | // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
|
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. | // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; | // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
// EMC Corporation; VERITAS Software Corporation; The Open Group. | // EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec Corporation; The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// 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" |
|
|
return c1 - c2; | return c1 - c2; |
} | } |
| |
static int _compare(const Uint16* s1, const Uint16* s2, size_t n) |
|
{ |
|
// This should only be called when s1 and s2 have the same length. |
|
|
|
while (n-- && (*s1++ - *s2++) == 0) |
|
; |
|
|
|
return s1[-1] - s2[-1]; |
|
} |
|
|
|
static inline void _copy(Uint16* s1, const Uint16* s2, size_t n) | static inline void _copy(Uint16* s1, const Uint16* s2, size_t n) |
{ | { |
memcpy(s1, s2, n * sizeof(Uint16)); | memcpy(s1, s2, n * sizeof(Uint16)); |
|
|
| |
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); |
const Uint16* p1 = s1._rep->data; |
assert(n <= s2._rep->size); |
const Uint16* p2 = s2._rep->data; |
| |
// Ignoring error in which n is greater than s1.size() or s2.size() |
while (n--) |
return _compare(s1._rep->data, s2._rep->data, n); |
{ |
|
int r = *p1++ - *p2++; |
|
if (r) |
|
{ |
|
return r; |
|
} |
|
else if (!p1[-1]) |
|
{ |
|
// We must have encountered a null terminator in both s1 and s2 |
|
return 0; |
|
} |
|
} |
|
return 0; |
} | } |
| |
int String::compare(const String& s1, const String& s2) | int String::compare(const String& s1, const String& s2) |
|
|
| |
(+) [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). |
| |
================================================================================ | ================================================================================ |
*/ | */ |