6#ifndef CXTSTRING_CLASS_H
7#define CXTSTRING_CLASS_H
15#pragma warning(disable: 4996)
102#if defined(__WINDOWS__) && defined(MOOTOOLS_DLL_IMPORTS_ALL)
106#define MOOTOOLS_XSTRINGS_NO_INLINE
109BEGIN_MOOTOOLS_NAMESPACE
112 template<
class XCHAR>
class CXTCharArray;
122#if defined(_DEBUG) && !defined(MOOTOOLS_NO_TRACE)
125 #define XTRACE(...) __noop
128 #define ISXCHARUNICODE(TYPE) ((sizeof(TYPE) == sizeof(wchar_t)))
130 template<
class XCHAR>
class CXTCharArray
136 varint bufCharCount, maxBufCount;
138 typedef enum { firstCharCount = 16, secondCharCount = 64 } XCharDefaults;
156 const XCHAR *data()
const;
162 static void xchar_memset(
XCHAR *
str,
XCHAR value, SIZET count);
163 static SIZET xchar_strlen(
const XCHAR *
str);
175#ifndef MOOTOOLS_XSTRINGS_NO_INLINE
177 template <>
inline void CXTCharArray<char>::xchar_memset(
char *
str,
char value, SIZET count)
179 return xmemset(
str, value, count);
182 template <>
inline SIZET CXTCharArray<char>::xchar_strlen(
const char *
str)
187 template <>
inline int CXTCharArray<char>::xchar_strcmp(
const char *
char1,
const char *
char2)
192 template <>
inline int CXTCharArray<char>::xchar_strcoll(
const char *
char1,
const char *
char2)
197 template <>
inline int CXTCharArray<char>::xchar_stricoll(
const char *
char1,
const char *
char2)
202 template <>
inline int CXTCharArray<char>::xchar_stricmp(
const char *
char1,
const char *
char2)
207 template <>
inline int CXTCharArray<char>::xchar_isspace(
char char1)
209 return xisspace(
char1);
212 template <>
inline int CXTCharArray<char>::xchar_toupper(
char char1)
214 return xtoupper(
char1);
217 template <>
inline int CXTCharArray<char>::xchar_tolower(
char char1)
219 return xtolower(
char1);
222 template <>
inline int CXTCharArray<char>::xchar_vnprintf(
char *buffer, SIZET count,
const char *
format,
va_list argptr)
227 template <>
inline int CXTCharArray<char>::xchar_vscanf_s(
const char *buffer,
const char *
format,
va_list argptr)
233 template <>
inline void CXTCharArray<wchar_t>::xchar_memset(
wchar_t *
str,
wchar_t value, SIZET count)
235 return xwmemset(
str, value, count);
238 template <>
inline SIZET CXTCharArray<wchar_t>::xchar_strlen(
const wchar_t *
str)
240 return xwstrlen(
str);
243 template <>
inline int CXTCharArray<wchar_t>::xchar_strcmp(
const wchar_t *
char1,
const wchar_t *
char2)
248 template <>
inline int CXTCharArray<wchar_t>::xchar_strcoll(
const wchar_t *
char1,
const wchar_t *
char2)
253 template <>
inline int CXTCharArray<wchar_t>::xchar_stricoll(
const wchar_t *
char1,
const wchar_t *
char2)
258 template <>
inline int CXTCharArray<wchar_t>::xchar_stricmp(
const wchar_t *
char1,
const wchar_t *
char2)
263 template <>
inline int CXTCharArray<wchar_t>::xchar_isspace(
wchar_t char1)
265 return xwisspace(
char1);
268 template <>
inline int CXTCharArray<wchar_t>::xchar_toupper(
wchar_t char1)
270 return xwtoupper(
char1);
273 template <>
inline int CXTCharArray<wchar_t>::xchar_tolower(
wchar_t char1)
275 return xwtolower(
char1);
278 template <>
inline int CXTCharArray<wchar_t>::xchar_vnprintf(
wchar_t *buffer, SIZET count,
const wchar_t *
format,
va_list argptr)
283 template <>
inline int CXTCharArray<wchar_t>::xchar_vscanf_s(
const wchar_t *buffer,
const wchar_t *
format,
va_list argptr)
289 template <
class XCHAR>
inline CXTCharArray<XCHAR>::CXTCharArray()
295 template <
class XCHAR>
inline CXTCharArray<XCHAR>::CXTCharArray(
const XCHAR *
string,
size_t charCount)
303 template <
class XCHAR>
inline CXTCharArray<XCHAR>::CXTCharArray(
XCHAR value,
size_t charCount)
314 template <
class XCHAR>
inline CXTCharArray<XCHAR>::~CXTCharArray()
319 template <
class XCHAR>
inline void CXTCharArray<XCHAR>::setlength(SIZET
newCharCount)
325 buffer[bufCharCount] =
'\0';
330 if (maxBufCount < firstCharCount)
331 maxBufCount = firstCharCount;
332 else if (maxBufCount < secondCharCount)
333 maxBufCount = secondCharCount;
335 buffer = (
XCHAR *)xrealloc(buffer, maxBufCount*
sizeof(
XCHAR));
337 buffer[bufCharCount] =
'\0';
340 template<
class XCHAR>
inline void CXTCharArray<XCHAR>::init()
352 template <
class XCHAR>
inline varint CXTCharArray<XCHAR>::length()
const
357 template<
class XCHAR>
inline bool CXTCharArray<XCHAR>::belongto(
varint index,
const XCHAR *
string,
size_t charSetCount)
const
376 if (*
chars == *
string)
392 bufCharCount =
first;
400 setlength(bufCharCount);
418 template <
class XCHAR>
inline void CXTCharArray<XCHAR>::assign(
const XCHAR *
string,
size_t charCount)
431 template <
class XCHAR>
inline size_t CXTCharArray<XCHAR>::insert(
varint index,
const XCHAR *
string,
size_t charCount)
449 xmemcpy_s(buffer + index, (bufCharCount-index)*
sizeof(
XCHAR),
string,
charCount*
sizeof(
XCHAR));
454 template <
class XCHAR>
inline void CXTCharArray<XCHAR>::append(
const XCHAR *
string,
size_t charCount)
470 template <
class XCHAR>
inline const XCHAR *CXTCharArray<XCHAR>::data()
const
475 template <
class XCHAR>
inline XCHAR *CXTCharArray<XCHAR>::data()
480 template <
class XCHAR>
inline XCHAR *CXTCharArray<XCHAR>::detach()
487 template <
class XCHAR>
inline void CXTCharArray<XCHAR>::empty()
493END_MOOTOOLS_NAMESPACE
498#define XSTRING_FRIEND template<XCHAR>
500#define XSTRING_FRIEND
503BEGIN_MOOTOOLS_NAMESPACE
528 typedef const XCHAR* LPCXSTR;
546#ifndef MOOTOOLS_XSTRINGS_NO_INLINE
566 str.m_str.append(&
ch, 1);
573 str.m_str.append(
string);
580 str.m_str.append(
string);
647 operator LPCXSTR()
const;
656 static xStringEncoding GetDefaultEncoding();
661 void AppendFormat(
unsigned int nFormatID, ...);
673 void Format(
unsigned int nID, ...);
686 bool IsEmpty()
const;
688 bool LoadString(
unsigned int nID);
689 void MakeLower(
int count = -1);
691 void MakeUpper(
int count = -1);
714#ifdef MOOTOOLS_MFC_PRODUCT_BUILD
725#ifndef MOOTOOLS_XSTRINGS_NO_INLINE
751 return static_cast<int>(m_str.length());
758 m_str.assign(
str,
str.GetLength());
770 m_str.assign(&
ch, 1);
777 return (Compare(
pszText) == 0);
783 return (Compare(
pszText) != 0);
791 template<
class XCHAR>
800 XASSERT(
nIndex < GetLength());
801 return m_str.data()[
nIndex];
806 m_str.append(&
ch, 1);
858 return CXTCharArray<XCHAR>::xchar_strcoll(m_str.data(),
pszText);
870 return CXTCharArray<XCHAR>::xchar_stricoll(m_str.data(),
pszText);
882 return CXTCharArray<XCHAR>::xchar_strcmp(m_str.data(),
pszText);
894 return CXTCharArray<XCHAR>::xchar_stricmp(m_str.data(),
pszText);
909 return (
int)GetLength();
922 XASSERT(
nIndex < m_str.length());
923 if (
nIndex >= m_str.length())
933 XASSERT(
nIndex < GetLength());
934 if (
nIndex >= GetLength())
937 return m_str.data()[
nIndex];
944 XASSERT(
nIndex < GetLength());
945 if (
nIndex >= GetLength())
948 return &m_str.data()[
nIndex];
960 newLength = CXTCharArray<XCHAR>::xchar_strlen(m_str.data());
1001 return m_str.detach();
1011 return (
int)m_str.length();
1020 return (
int)m_str.length();
1026 return (m_str.length() == 0);
1032 varint length = m_str.length();
1033 if (count != -1 && count < length)
1038 while (pos < length)
1050 varint length = m_str.length();
1067 varint length = m_str.length();
1068 if (count != -1 && count < length)
1073 while (pos < length)
1102 if (
nCount > m_str.length())
1103 nCount = LInt2Int(m_str.length());
1114 if (
nCount > m_str.length())
1115 nCount = LInt2Int(m_str.length());
1146 if (
nIndex >= GetLength())
1149 varint length = m_str.length();
1152 while (pos < length)
1155 return LInt2Int(pos);
1167 if (
nIndex >= GetLength())
1172 varint length = m_str.length();
1175 while (pos < length)
1177 if (xttolower(
chars[pos]) ==
ch)
1178 return LInt2Int(pos);
1206 if (
nIndex >= GetLength())
1220 if (
nIndex >= GetLength())
1247 if (
nIndex >= GetLength())
1261 if (
nIndex >= GetLength())
1284 if (m_str.length() == 0)
1288 nIndex = LInt2Int(m_str.length() - 1);
1307 if (!
pszText || m_str.length() == 0)
1311 nIndex = LInt2Int(m_str.length() - 1);
1346 while (pos < length)
1350 m_str.remove(pos, 1);
1367 size_t length = CXTCharArray<XCHAR>::xchar_strlen(
pszText);
1375 m_str.remove(pos, length);
1385 varint length = m_str.length();
1390 while (pos < length)
1415 while ((pos = Find(
pszOld, (
int)pos)) != -1)
1437 varint length = m_str.length();
1441 while (pos < length)
1463 varint length = m_str.length();
1467 while (pos < length)
1481 varint length = m_str.length();
1504 while (pos < length)
1516 while (pos < length)
1551 varint length = m_str.length();
1554 while (count < length)
1556 if (!CXTCharArray<XCHAR>::xchar_isspace(*
chars))
1563 m_str.remove(0, count);
1569 varint length = m_str.length();
1575 while (count < length)
1584 m_str.remove(0, count);
1597 varint length = m_str.length();
1602 while (count < length)
1610 m_str.remove(0, count);
1616 varint length = m_str.length();
1619 chars += (length-1);
1620 while (count < length)
1622 if (!CXTCharArray<XCHAR>::xchar_isspace(*
chars))
1629 m_str.remove(
size_t(length - count), count);
1635 varint length = m_str.length();
1641 chars += (length-1);
1642 while (count < length)
1651 m_str.remove(
size_t(length - count), count);
1664 varint length = m_str.length();
1669 while (count < length)
1677 m_str.remove(
size_t(length - count), count);
1698 return CXTCharArray<XCHAR>::xchar_vscanf_s(m_str.data(),
pszFormat,
args);
1732 FormatV(
str.m_str.data(),
args);
1745 int length = CXTCharArray<XCHAR>::xchar_vnprintf(0, 0,
pszFormat,
argscpy);
1752 XTRACE(
_T(
"CXTString<XCHAR>::Format: an error occurs when formatting the string\n"));
1757 m_str.setlength(length);
1760 int result = CXTCharArray<XCHAR>::xchar_vnprintf(m_str.data(), length+1,
pszFormat,
args);
1761 if (result != length)
1762 XTRACE(
_T(
"CXTString<XCHAR>::Format: computed buffer is too short (%d != %d)\n"), result, length);
1764 CXTCharArray<XCHAR>::xchar_vnprintf(m_str.data(), length+1,
pszFormat,
args);
1777 template<>
inline DLL_TOOLSFUNCTION
1784 template<>
inline DLL_TOOLSFUNCTION
1791 template<>
inline DLL_TOOLSFUNCTION
1796 #elif defined(__APPLE__) || defined(__LINUX__)
1801 template<>
inline DLL_TOOLSFUNCTION
1805 return xStringUtf16;
1806 #elif defined(__APPLE__) || defined(__LINUX__)
1807 return xStringUtf16;
1812 template<>
inline DLL_TOOLSFUNCTION
1823 template<>
inline DLL_TOOLSFUNCTION
1834 template<>
inline DLL_TOOLSFUNCTION
1843 template<>
inline DLL_TOOLSFUNCTION
1852 template<>
inline DLL_TOOLSFUNCTION
1858 template<>
inline DLL_TOOLSFUNCTION
1864 template<>
inline DLL_TOOLSFUNCTION
1871 template<
class XCHAR>
1880 template<>
inline DLL_TOOLSFUNCTION
1887 template<>
inline DLL_TOOLSFUNCTION
1896 template<>
inline DLL_TOOLSFUNCTION
1905#ifdef MOOTOOLS_MFC_PRODUCT_BUILD
1906 template <>
inline DLL_TOOLSFUNCTION
1911 template <>
inline DLL_TOOLSFUNCTION
1916 template <>
inline DLL_TOOLSFUNCTION
1921 template <>
inline DLL_TOOLSFUNCTION
1926 template <>
inline DLL_TOOLSFUNCTION
1929 this->operator=((
LPCSTR)
string);
1933 template <>
inline DLL_TOOLSFUNCTION
1936 this->operator=((
LPCWSTR)
string);
1940 template <>
inline DLL_TOOLSFUNCTION
1943 this->operator=((
LPCSTR)
string);
1947 template <>
inline DLL_TOOLSFUNCTION
1950 this->operator=((
LPCWSTR)
string);
1960#if defined(__WINDOWS__)
1965END_MOOTOOLS_NAMESPACE
CXTString< wchar_t > CXStringW
CXStringA is an unicode wchar_t string. Cf. CXTString.
Definition XString.h:120
CXTString< char > CXStringA
CXStringA is an ansi / utf8 char string. Cf. CXTString.
Definition XString.h:119
CXTString< TCHAR > CXString
CXString depend on the target OS. Could be CXStringW (Windows) or CXStringA (Linux / Macos)
Definition XString.h:118
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
CXStringT is the template class for handling strings.
Definition XString.h:526
void TrimLeft(XCHAR chTarget)
Remove left specified character.
Definition XString.h:1566
void Trim()
Remove left and right space char.
Definition XString.h:1541
int GetLength() const
returns the length of the buffer in characters (can be greater than strlen, if set by GetBufferSetLen...
Definition XString.h:749
LPXSTR DetachBuffer()
Detach buffer. Caller must free buffer with xfree.
Definition XString.h:999
void TrimLeft(LPCXSTR pszTargets)
Remove any character from pszTargets string on the left side of the string.
Definition XString.h:1587
Conversion from ansi / utf8 (char) to unicode (wchar_t)
Definition xstringoperation.h:66
Conversion from unicode (wchar_t) to ansi / utf8 (char)
Definition xstringoperation.h:92
strings low level functions and conversion. Some are declared in macos_stringoperation,...