17#include <boost/detail/interlocked.hpp>
27#include <vlutil/vlExceptions.h>
29#define AtomicIncrement(a) BOOST_133_INTERLOCKED_INCREMENT(a)
30#define AtomicDecrement(a) BOOST_133_INTERLOCKED_DECREMENT(a)
32#define AtomicIncrement(a) boost::detail::atomic_increment(a)
33#define AtomicDecrement(a) boost::detail::atomic_decrement(a)
37#include <boost/smart_ptr/detail/sp_counted_base.hpp>
40#if defined(__rhentws8__) || defined(__rhentws9__)
41#define AtomicIncrement(a) boost::detail::atomic_increment((unsigned int*)a)
42#define AtomicDecrement(a) boost::detail::atomic_decrement((unsigned int*)a)
44#define AtomicIncrement(a) boost::detail::atomic_increment((std::atomic_int*)a)
45#define AtomicDecrement(a) boost::detail::atomic_decrement((std::atomic_int*)a)
51#define MallocAligned(sz,align) _aligned_malloc(sz,align)
52#define ReallocAligned(ptr,sz,oldsz,align) _aligned_realloc(ptr,sz,align)
53#define FreeAligned(ptr) _aligned_free(ptr)
61 posix_memalign(&ptr,align,sz);
65#define MallocAligned(sz,align) mallocAligned(sz,align)
74 memcpy(newPtr,ptr,oldsz);
81#define ReallocAligned(ptr,sz,oldsz, align) reallocAligned(ptr,sz,oldsz,align)
82#define FreeAligned(ptr) free(ptr)
90inline size_t utf16len(
const unsigned short* str)
96 const unsigned short* checker = str;
101 return checker - str;
105inline const unsigned short*
wcsnstr(
const unsigned short* haystack,
int hayLength,
106 const unsigned short* needle,
int needleLength)
110 if(needle == NULL || needleLength < -1)
114 if(haystack == NULL || hayLength < -1 )
120 unsigned short charToFind = *needle++;
123 const unsigned short* needleEnd = needle + needleLength;
125 const unsigned short* haystackEnd = haystack + hayLength;
128 const unsigned short* searchEnd = haystackEnd - needleLength;
129 while(haystack != searchEnd)
132 unsigned short currentChar = *haystack++;
133 if(currentChar == charToFind)
136 const unsigned short* hayRead = haystack;
137 const unsigned short* needleRead = needle;
140 if(needleRead == needleEnd)
143 haystackEnd, haystack - 1, hayRead ))
152 if(*hayRead != *needleRead)
229template <
int w
charSize>
295 std::string::const_iterator i = ascii.begin();
296 std::string::const_iterator e = ascii.end();
307 len = (int)strlen(ascii);
311 const char* i = ascii;
312 const char* e = ascii + len;
323 len = (int)strlen((
const char*)utf8);
327 const unsigned char* i = utf8;
328 const unsigned char* e = utf8 + len;
344 setFromUtf8((
const unsigned char*)utf8.c_str(),utf8.size());
351 len = (int)strlen(latin);
355 const char* i = latin;
356 const char* e = latin + len;
381 str.push_back(
static_cast<unsigned char>(c));
403 str.push_back(
static_cast<unsigned char>(c));
425 str.resize(str.size() + len);
427 const char* memory = str.c_str() + (str.size() - len);
450 str.resize(str.size() + len);
453 const wchar_t* memory = str.c_str() + (str.size() - len);
461template <
int w
charSize>
499 unsigned int c = *utf32;
605 size_t codePoints = 0;
620 size_t currentPos = 0;
621 size_t countResult = 0;
623 while (currentPos <
length())
625 currentPos =
indexOf(x, currentPos);
626 if (currentPos == -1)
650 if(x.length() + pos >
length())
656 (
myCodeUnits.size() >> 1) - pos , x.myCodeUnits.begin, (x.myCodeUnits.size() >> 1));
678 int maxLen =
length() - pos;
685 len = std::min(maxLen,len);
697 x.writeUtf16(
myCodeUnits.end - x.utf16CodeUnits());
801 size_t oldSize =
size();
803 end =
reinterpret_cast<CodeUnit*
>(
reinterpret_cast<char*
>(
begin) + oldSize);
838 begin =
reinterpret_cast<CodeUnit*
>(
const_cast<long*
>(
count) + 1);
839 end = last =
reinterpret_cast<CodeUnit*
>(
reinterpret_cast<char*
>(begin) + newSize);
846 size_t oldSize = size();
849 begin =
reinterpret_cast<CodeUnit*
>(
const_cast<long*
>(
count) + 1);
850 end = last =
reinterpret_cast<CodeUnit*
>(
reinterpret_cast<char*
>(begin) + newSize);
852 memcpy(begin,oldBegin,oldSize);
858 if(newSize > capacity())
861 size_t newCapacity = calculateCapacity(newSize +
sizeof(
long)) -
sizeof(long);
862 count = (
volatile long*)
ReallocAligned(
const_cast<long*
>(
count),newCapacity +
sizeof(
long),size() +
sizeof(
long),
sizeof(
long*));
863 begin =
reinterpret_cast<CodeUnit*
>(
const_cast<long*
>(
count) + 1);
864 last =
reinterpret_cast<CodeUnit*
>(
reinterpret_cast<char*
>(begin) + newCapacity);
866 end =
reinterpret_cast<CodeUnit*
>(
reinterpret_cast<char*
>(begin) + newSize);
887 count = (
volatile std::atomic_long*)
MallocAligned(newSize +
sizeof(std::atomic_long),
sizeof(std::atomic_long*));
897 size_t oldSize =
size();
899 count = (
volatile std::atomic_long*)
MallocAligned(newSize +
sizeof(std::atomic_long),
sizeof(std::atomic_long*));
903 memcpy(
begin,oldBegin,oldSize);
912 size_t newCapacity =
calculateCapacity(newSize +
sizeof(std::atomic_long)) -
sizeof(std::atomic_long);
913 count = (
volatile std::atomic_long*)
ReallocAligned(
const_cast<std::atomic_long*
>(
count),newCapacity +
sizeof(std::atomic_long),
size() +
sizeof(std::atomic_long),
sizeof(std::atomic_long*));
915 last =
reinterpret_cast<CodeUnit*
>(
reinterpret_cast<char*
>(
begin) + newCapacity);
917 end =
reinterpret_cast<CodeUnit*
>(
reinterpret_cast<char*
>(
begin) + newSize);
926 if (necessarySize < 0x80000)
929 float f =
static_cast<float>(necessarySize);
930 unsigned int bits(0);
931 memcpy(&bits,&f,
sizeof(
float));
932 const unsigned int t = 1U << ((bits >> 23) - 0x7f);
933 return t << ((t < necessarySize) ? 1 : 0);
935 else if (necessarySize != 0)
938 return necessarySize + 32;
949 return reinterpret_cast<const char*
>(
end) -
950 reinterpret_cast<const char*
>(
begin);
956 return reinterpret_cast<const char*
>(
last) -
957 reinterpret_cast<const char*
>(
begin);
964 size_t oldSize =
size();
965 size_t otherSize = other.
size();
966 resize(oldSize + otherSize);
967 memcpy(
reinterpret_cast<char*
>(
begin) + oldSize,other.
begin,otherSize);
#define FreeAligned(ptr)
Definition DtUnicode.inl:82
void * reallocAligned(void *ptr, size_t sz, size_t oldsz, size_t align)
Definition DtUnicode.inl:66
#define AtomicIncrement(a)
Definition DtUnicode.inl:44
#define ReallocAligned(ptr, sz, oldsz, align)
Definition DtUnicode.inl:81
#define AtomicDecrement(a)
Definition DtUnicode.inl:45
void * mallocAligned(size_t sz, size_t align)
Definition DtUnicode.inl:58
#define MallocAligned(sz, align)
Definition DtUnicode.inl:65
A single unicode character.
Definition DtUnicodeChar.h:18
unsigned int readUtf8(const unsigned char *memory)
Definition DtUnicodeChar.h:271
unsigned int readUtf16(const Surrogate *memory)
Definition DtUnicodeChar.h:208
unsigned int utf8Length() const
Calculate the utf-8 length of a code point.
Definition DtUnicodeChar.h:139
void writeUtf8(char *memory) const
Definition DtUnicodeChar.h:306
static bool isSurrogateSubstringValid(const Surrogate *start, const Surrogate *end, const Surrogate *substringStart, const Surrogate *substringEnd)
Definition DtUnicodeChar.h:100
unsigned int wideStringLength() const
Definition DtUnicodeChar.h:397
void writeWChar(wchar_t *memory) const
Definition DtUnicodeChar.h:402
static bool isSurrogate(Surrogate cp)
Definition DtUnicodeChar.h:126
Definition DtUnicode.h:34
bool operator<(const DtUnicode &other) const
Definition DtUnicode.inl:565
void setFromUtf16(const unsigned short *utf16, int len=-1)
Definition DtUnicode.inl:482
std::wstring toWideString() const
Definition DtUnicode.h:167
DtUnicode operator+(const DtUnicode &str) const
Append two strings together.
Definition DtUnicode.inl:217
bool operator==(const DtUnicode &other) const
Test if two strings are identical.
Definition DtUnicode.inl:517
virtual bool containsRightToLeft() const
Returns true if this text contains any right to left characters.
Definition DtUnicode.inl:1010
DtUnicode()
CTOR creates an empty string.
Definition DtUnicode.inl:165
void setFromLatin1(const char *latin, int len=-1)
Definition DtUnicode.inl:347
static DtUnicode fromWideString(const std::wstring &str)
Set from a std::wstring.
Definition DtUnicode.inl:251
void push_back(const DtUnicodeChar &x)
Append a unicode character to the string.
Definition DtUnicode.inl:692
unsigned short CodeUnit
Definition DtUnicode.h:36
void resize(int size)
Definition DtUnicode.inl:701
DtUnicode & operator+=(const DtUnicode &str)
Append a string to the end.
Definition DtUnicode.inl:199
size_t count(const DtUnicodeChar &x) const
Definition DtUnicode.inl:618
std::string toLatin1() const
Definition DtUnicode.h:162
CodeUnitArray myCodeUnits
Definition DtUnicode.h:318
void setFromAscii(const std::string &ascii)
Definition DtUnicode.inl:290
static DtUnicode fromAscii(const std::string &ascii)
Definition DtUnicode.inl:285
Encoding
Definition DtUnicode.h:244
@ Ascii
Definition DtUnicode.h:245
@ Utf8
Definition DtUnicode.h:247
@ Latin1
Definition DtUnicode.h:246
int indexOf(const DtUnicodeChar &x, size_t pos=0) const
Search for a character starting a pos, returns index, or -1 if not found.
Definition DtUnicode.inl:637
std::string toUtf8() const
Definition DtUnicode.h:165
void setFromUtf8(const unsigned char *utf8, int len=-1)
Definition DtUnicode.inl:319
std::string toAscii() const
Definition DtUnicode.h:157
virtual ~DtUnicode()
DTOR may NOT deallocate memory as this string may share data.
Definition DtUnicode.inl:179
DtUnicode subString(size_t pos=0, int len=-1) const
Definition DtUnicode.inl:668
void setFromUtf32(const unsigned int *utf32, int len=-1)
Definition DtUnicode.inl:494
static DtUnicode fromWCharArray(const wchar_t utf16[], int len=-1)
Static create via specifying encoding.
Definition DtUnicode.inl:245
size_t calculateCodePoints() const
Calculate the number of Code Points.
Definition DtUnicode.inl:603
static DtUnicode fromUtf8(const unsigned char *utf8, int len=-1)
Definition DtUnicode.inl:257
static DtUnicode fromUtf16(const unsigned short *utf16, int len=-1)
Definition DtUnicode.inl:268
void setFromWCharArray(const wchar_t utf16[], int len=-1)
Initialize via specifying encoding.
Definition DtUnicode.inl:477
bool operator!=(const DtUnicode &other) const
Test if two strings are not identical.
Definition DtUnicode.inl:541
DtUnicode & operator=(const DtUnicode &str)
Definition DtUnicode.inl:189
static DtUnicode fromUtf32(const unsigned int *utf32, int len=-1)
Definition DtUnicode.inl:274
size_t length() const
Definition DtUnicode.inl:597
const CodeUnit * codeUnits() const
Get an array of code units.
Definition DtUnicode.h:211
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtUnicode decodeWCHAR< 4 >(const wchar_t utf16[], int len)
Definition DtUnicode.inl:239
bool DT_DLL_VRVUTIL DtIsRightToLeft(unsigned int c)
Returns true if the given character is right to left according to unicode.
size_t utf16len(const unsigned short *str)
Definition DtUnicode.inl:90
DtUnicode decodeWCHAR(const wchar_t utf16[], int len)
DtUnicode decodeWCHAR< 2 >(const wchar_t utf16[], int len)
Definition DtUnicode.inl:233
const unsigned short * wcsnstr(const unsigned short *haystack, int hayLength, const unsigned short *needle, int needleLength)
Definition DtUnicode.inl:105
void setFromWCHAR< 2 >(DtUnicode &str, const wchar_t utf16[], int len)
Definition DtUnicode.inl:465
void setFromWCHAR(DtUnicode &ref, const wchar_t utf16[], int len)
void setFromWCHAR< 4 >(DtUnicode &str, const wchar_t utf32[], int len)
Definition DtUnicode.inl:471
Internal structure used to store the code units.
Definition DtUnicode.h:269
volatile std::atomic_long * count
Definition DtUnicode.h:312
size_t calculateCapacity(size_t necessarySize)
Definition DtUnicode.inl:923
CodeUnitArray & operator=(const CodeUnitArray &)
Definition DtUnicode.inl:785
void reserve(size_t capacity)
Ensure the array's capacity is at least capacity, do not change size.
Definition DtUnicode.inl:799
void concat(const CodeUnitArray &other)
Definition DtUnicode.inl:962
CodeUnit * end
Definition DtUnicode.h:315
void dec_ref()
Decrement the reference count.
Definition DtUnicode.inl:988
size_t capacity() const
Definition DtUnicode.inl:954
CodeUnit * last
Definition DtUnicode.h:316
void clear()
Definition DtUnicode.inl:807
void add_ref()
Increment the reference count.
Definition DtUnicode.inl:983
bool unique() const
Am I unique.
Definition DtUnicode.inl:972
~CodeUnitArray()
Definition DtUnicode.inl:771
bool empty() const
Am I empty.
Definition DtUnicode.inl:978
size_t size() const
Definition DtUnicode.inl:947
void resize(size_t newSize)
Resize the array.
Definition DtUnicode.inl:871
CodeUnit * begin
Definition DtUnicode.h:314
CodeUnitArray()
Definition DtUnicode.inl:763