13 #include <boost/functional/hash.hpp>
14 #include <boost/serialization/split_free.hpp>
99 template <
typename QStringType,
typename QCoreApp>
102 return QCoreApp::translate(
"makVrv::DtUnicode",
toUtf8().c_str(), 0);
106 template <
typename QStringType>
109 return fromUtf16(qstr.utf16(),qstr.length());
122 inline void setFromUtf8(
const unsigned char* utf8,
int len = -1);
131 inline void setFromUtf16(
const unsigned short* utf16,
int len = -1);
135 inline void setFromUtf32(
const unsigned int* utf32,
int len = -1);
143 inline void setFromAscii(
const char* ascii,
int len = -1);
146 template <
typename QStringType>
156 inline void toAscii(std::string& str)
const;
157 inline std::string
toAscii()
const { std::string temp;
toAscii(temp);
return temp;}
161 inline void toLatin1(std::string& str)
const;
164 inline void toUtf8(std::string& str)
const;
165 inline std::string
toUtf8()
const { std::string temp;
toUtf8(temp);
return temp;}
170 template <
typename QStringType>
177 template <
typename QStringType>
200 inline size_t length()
const;
232 inline void resize(
int size );
250 inline explicit DtUnicode(
const unsigned short* utf16,
int len = -1);
253 inline explicit DtUnicode(
const unsigned int* utf32,
int len = -1);
256 inline explicit DtUnicode(
const std::string& ascii);
272 inline void resize(
size_t newSize);
285 inline size_t size()
const;
294 inline bool unique()
const;
297 inline bool empty()
const;
306 volatile long*
count;
325 size_t seed = 2166136261U;
327 size_t last = val.
length();
328 size_t stride = 1 + last / 10;
334 for(; first < last ; first += stride )
336 seed = 16777619U * seed ^ (size_t)val.
codeUnits()[first];
Definition: DtUnicode.h:242
DtUnicode & operator+=(const DtUnicode &str)
Append a string to the end.
Definition: DtUnicode.inl:197
CodeUnit * begin
Definition: DtUnicode.h:310
size_t size() const
Definition: DtUnicode.inl:908
DtUnicode()
CTOR creates an empty string.
Definition: DtUnicode.inl:163
virtual ~DtUnicode()
DTOR may NOT deallocate memory as this string may share data.
Definition: DtUnicode.inl:177
A unicode string.
Definition: DtUnicode.h:33
DtUnicode subString(size_t pos=0, int len=-1) const
Create a substring starting at position, for n characters.
Definition: DtUnicode.inl:629
static DtUnicode fromUtf8(const unsigned char *utf8, int len=-1)
Create a unicode string from an UTF-16 encoded string, the string MUST be zero terminated if the leng...
Definition: DtUnicode.inl:248
void setFromLatin1(const char *latin, int len=-1)
Set from an UTF-8 encoded string, the string MUST be zero terminated if the length is not passed...
Definition: DtUnicode.inl:338
void concat(const CodeUnitArray &other)
Definition: DtUnicode.inl:923
bool operator!=(const DtUnicode &other) const
Test if two strings are not identical.
Definition: DtUnicode.inl:527
size_t capacity() const
Definition: DtUnicode.inl:915
static DtUnicode fromWCharArray(const wchar_t utf16[], int len=-1)
Static create via specifying encoding.
Definition: DtUnicode.inl:236
bool unique() const
Am I unique.
Definition: DtUnicode.inl:933
CodeUnit * end
Definition: DtUnicode.h:311
void clear()
Resize the array to 0, does not change the memory allocation if the array is unique.
Definition: DtUnicode.inl:768
unsigned short CodeUnit
Definition: DtUnicode.h:36
void setFromUtf8(const unsigned char *utf8, int len=-1)
Set from an UTF-8 encoded string, the string MUST be zero terminated if the length is not passed...
Definition: DtUnicode.inl:310
size_t calculateCodePoints() const
Calculate the number of Code Points.
Definition: DtUnicode.inl:583
void reserve(size_t capacity)
Ensure the array's capacity is at least capacity, do not change size.
Definition: DtUnicode.inl:760
void push_back(const DtUnicodeChar &x)
Append a unicode character to the string.
Definition: DtUnicode.inl:653
CodeUnitArray()
Definition: DtUnicode.inl:724
Internal structure used to store the code units.
Definition: DtUnicode.h:264
std::string toUtf8() const
Definition: DtUnicode.h:165
size_t length() const
Get the length in Code Units.
Definition: DtUnicode.inl:577
void setFromUtf16(const unsigned short *utf16, int len=-1)
Set from an UTF-16 encoded string, the string MUST be zero terminated if the length is not passed...
Definition: DtUnicode.inl:473
DtUnicode operator+(const DtUnicode &str) const
Append two strings together.
Definition: DtUnicode.inl:215
bool empty() const
Am I empty.
Definition: DtUnicode.inl:939
size_t sizeInBytes() const
Get the size in 8bit bytes.
Definition: DtUnicode.h:203
void setFromAscii(const std::string &ascii)
Set from an ascii string, the string MUST be zero terminated if the length is not passed...
Definition: DtUnicode.inl:281
volatile std::atomic_long * count
Definition: DtUnicode.h:308
Definition: DtUnicode.h:243
virtual bool containsRightToLeft() const
Returns true if this text contains any right to left characters.
Definition: DtUnicode.inl:969
A single unicode character.
Definition: DtUnicodeChar.h:20
static DtUnicode tr(const char *ascii)
Ascii translation function, used to be compatible with Qt's translation tools.
Definition: DtUnicode.h:92
void setFromUtf32(const unsigned int *utf32, int len=-1)
Set from an UTF-32 encoded string, the string MUST be zero terminated if the length is not passed...
Definition: DtUnicode.inl:485
QStringType translate() const
Utility function for translating a DtUnicode variable initialized using the static DtUnicode::tr func...
Definition: DtUnicode.h:100
CodeUnitArray myCodeUnits
Definition: DtUnicode.h:314
std::string toAscii() const
Definition: DtUnicode.h:157
DtUnicode & operator=(const DtUnicode &str)
Assignment operator copies the string, this function will NOT allocate memory for the string...
Definition: DtUnicode.inl:187
void resize(int size)
Resize a string to a new size, if the size < 0 the string will be empty.
Definition: DtUnicode.inl:662
Definition: DtUnicode.h:241
~CodeUnitArray()
Definition: DtUnicode.inl:732
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:598
static DtUnicode fromWideString(const std::wstring &str)
Set from a std::wstring.
Definition: DtUnicode.inl:242
static DtUnicode fromUtf16(const unsigned short *utf16, int len=-1)
Create a unicode string from an UTF-16 encoded string, the string MUST be zero terminated if the leng...
Definition: DtUnicode.inl:259
void setFromQString(QStringType qstr)
Template function for setting from Qt 4 style string.
Definition: DtUnicode.h:147
const CodeUnit * codeUnits() const
Get an array of code units.
Definition: DtUnicode.h:209
bool operator==(const DtUnicode &other) const
Test if two strings are identical.
Definition: DtUnicode.inl:509
CodeUnit * last
Definition: DtUnicode.h:312
static DtUnicode fromQString(QStringType qstr)
Template function for setting from Qt 4 style string.
Definition: DtUnicode.h:107
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)
void setFromWCharArray(const wchar_t utf16[], int len=-1)
Initialize via specifying encoding.
Definition: DtUnicode.inl:468
void toQString(QStringType &qstr) const
Template function for initializing a Qt 4 style string.
Definition: DtUnicode.h:178
void resize(size_t newSize)
Resize the array.
Definition: DtUnicode.inl:832
size_t calculateCapacity(size_t necessarySize)
Definition: DtUnicode.inl:884
QStringType toQString() const
Template function for outputting a Qt 4 style string.
Definition: DtUnicode.h:171
std::size_t hash_value(DtUnicode const &val)
Definition: DtUnicode.h:321
static DtUnicode fromAscii(const std::string &ascii)
Create a unicode string from an ascii string, the string MUST be zero terminated if the length is not...
Definition: DtUnicode.inl:276
bool operator<(const DtUnicode &other) const
Test if a string is less than another based on their first different character or the length...
Definition: DtUnicode.inl:545
CodeUnitArray & operator=(const CodeUnitArray &)
Definition: DtUnicode.inl:746
static DtUnicode fromUtf32(const unsigned int *utf32, int len=-1)
Create a unicode string from an UTF-32 encoded string, the string MUST be zero terminated if the leng...
Definition: DtUnicode.inl:265
void dec_ref()
Decrement the reference count.
Definition: DtUnicode.inl:949
std::wstring toWideString() const
Definition: DtUnicode.h:167
std::string toLatin1() const
Definition: DtUnicode.h:162
void add_ref()
Increment the reference count.
Definition: DtUnicode.inl:944
Encoding
Definition: DtUnicode.h:239