25#ifdef __DCL_COMPILE_UNICODE__
27 #define CHAR_T wchar_t
28 #define UCHAR_T wint_t
29 #define BUFFER_T CharBuffer
30 #define STRING_T String
31 #define ARRAY_T StringArray
32 #define STRING_BUILDER_T StringBuilder
34 #define STRLEN(s) wcslen(s)
35 #define STRCMP(s1, s2) wcscmp(s1, s2)
36 #define STRNCMP(s1, s2, n) wcsncmp(s1, s2, n)
39 #define STRCASECMP(s1, s2) _wcsicmp(s1, s2)
40 #define STRNCASECMP(s1, s2, n) _wcsnicmp(s1, s2, n)
41 #define VSNPRINTF(buf, len, fmt, args) _vsnwprintf(buf, len, fmt, args)
43 #define STRCASECMP(s1, s2) wcscasecmp(s1, s2)
44 #define STRNCASECMP(s1, s2, n) wcsncasecmp(s1, s2, n)
45 #define VSNPRINTF(buf, len, fmt, args) vswprintf(buf, len, fmt, args)
48 #define STRCHR(s, c) wcschr(s, c)
49 #define STRSTR(s, cs) wcsstr(s, cs)
50 #define ISSPACE(c) iswspace(c)
51 #define ISALNUM(c) iswalnum(c)
52 #define TOUPPER(c) towupper(c)
53 #define TOLOWER(c) towlower(c)
54 #define TOUPPER_L(c, l) towupper(c, l)
55 #define TOLOWER_L(c, l) towlower(c, l)
59 #define UCHAR_T unsigned char
60 #define BUFFER_T ByteBuffer
61 #define STRING_T ByteString
62 #define ARRAY_T ByteStringArray
63 #define STRING_BUILDER_T ByteStringBuilder
65 #define STRLEN(s) strlen(s)
66 #define STRCMP(s1, s2) strcmp(s1, s2)
67 #define STRNCMP(s1, s2, n) strncmp(s1, s2, n)
70 #define STRCASECMP(s1, s2) _stricmp(s1, s2)
71 #define STRNCASECMP(s1, s2, n) _strnicmp(s1, s2, n)
72 #define VSNPRINTF(buf, len, fmt, args) _vsnprintf(buf, len, fmt, args)
74 #define STRCASECMP(s1, s2) strcasecmp(s1, s2)
75 #define STRNCASECMP(s1, s2, n) strncasecmp(s1, s2, n)
76 #define VSNPRINTF(buf, len, fmt, args) vsnprintf(buf, len, fmt, args)
79 #define STRCHR(s, c) strchr(s, c)
80 #define STRSTR(s, cs) strstr(s, cs)
81 #define ISSPACE(c) isspace(c)
82 #define ISALNUM(c) isalnum(c)
83 #define TOUPPER(c) toupper(c)
84 #define TOLOWER(c) tolower(c)
85 #define TOUPPER_L(c, l) toupper_l(c, l)
86 #define TOLOWER_L(c, l) tolower_l(c, l)
89#if __DCL_HAVE_THIS_FILE__
93 #define __THIS_FILE__ __CONCAT(__sz_STRING_T_cpp, CHAR_T)
111#ifndef __EXTENDED_LENGTH_DEFINED
112#define __EXTENDED_LENGTH_DEFINED
115 if (_allocLength <= 32)
117 else if (_allocLength <= 64)
119 else if (_allocLength <= 128)
121 else if (_allocLength <= 256)
123 else if (_allocLength <= 512)
125 else if (_allocLength <= 1024)
128 size_t m = _allocLength / 2048;
129 if (_allocLength % 2048)
131 _allocLength = m * 2048;
149 buf->__allocLength = _len;
150 buf->__dataLength = 0;
151 buf->data()[
buf->__dataLength] =
_T(
'\0');
220 write(_buf, &_ch, 1);
227#if defined(__DCL_COMPILE_UNICODE__) && defined(_MSC_VER)
229 if (
STRSTR(_format, L
"%s")) {
230 __DCL_TRACE3(L
"Warning!! vformat _format [%ls] included [%ls]. replaced to [%ls]\n",
231 _format, L
"%s", L
"%hs");
232 format.assign(_format);
233 format = format.replace(L
"%s", L
"%hs");
238#define __EXTENDED_MAX 1024 * 1024
239#define __EXTEND_MIN 32
249 va_copy(arglist, _arglist);
289#define __EMPTY_STR __CONCAT(__empty, CHAR_T)
294#define __EMPTY __EMPTY_STR()
301 if (
buf->__refCount == 0) {
303 buf = BUFFER_T::create(_len);
308 buf = BUFFER_T::create(_len);
352 assign(_psz, _start, _len);
404 CHAR_T* _end = p + _repeat;
408 __buf()->__dataLength = _repeat;
423 memcpy(
__psz, _ps + _start, _len *
sizeof(
CHAR_T));
425 __buf()->__dataLength = _len;
436 if (_len == (
size_t)-1)
438 return assign(_psz, 0, _len);
444 return assign(_begin, 0, _end - _begin);
448 const CHAR_T* _ps2,
size_t _len2)
452 size_t _len = _len1 + _len2;
457 memcpy(
__psz + _len1, _ps2, _len2 *
sizeof(
CHAR_T));
459 __buf()->__dataLength = _len;
484 r.assign(_str, _str.
length(), &_ch, 1);
491 r.assign(&_ch, 1, _str, _str.
length());
575 const CHAR_T* psz2,
size_t _len)
579 if (_len == (
size_t)-1)
580 return STRCMP(psz1, psz2);
582 return STRNCMP(psz1, psz2, _len);
586 const CHAR_T* psz2,
size_t _len)
590 if (_len == (
size_t)-1)
600 if (_len == (
size_t)-1)
605 if (_first == 0 && _len ==
length())
630 buf->__dataLength = _len;
644 end =
buf->data() + _len;
663 buf->__dataLength = _len;
671 end =
buf->data() + _len;
692 buf->__dataLength = _len;
701 end =
buf->data() + _len;
714 const CHAR_T* _new,
size_t _newlen)
const
719 if (_newlen == (
size_t)-1)
726 *(p +
len) =
_T(
'\0');
729 memcpy(p + _start, _new, _newlen *
sizeof(
CHAR_T));
730 memcpy(p + _start + _newlen,
__psz + _start + _len,
741 const CHAR_T* _new,
size_t _newlen)
const
745 return replace(
length() - _start - _len, _len, _new, _newlen);
763 *dst++ = *src == _old ? _new : *src;
774 const CHAR_T* _new,
size_t _newlen)
const
788 _start = _sub + _oldlen;
795 size_t allocLength =
length() + (count * _newlen) - (count * _oldlen);
797 buf->__dataLength = allocLength;
799 *(dst + allocLength) =
_T(
'\0');
804 _len = _sub - _start;
805 memcpy(dst, _start, _len *
sizeof(
CHAR_T));
807 memcpy(dst, _new, _newlen *
sizeof(
CHAR_T));
810 _start = _sub + _oldlen;
812 _len = _end - _start;
813 memcpy(dst, _start, _len *
sizeof(
CHAR_T));
844 _regex.__psz, _regex.__psz + _regex.length(),
869 _regex.__psz, _regex.__psz + _regex.length(),
894 _regex.__psz, _regex.__psz + _regex.length(),
919 _regex.__psz, _regex.__psz + _regex.length(),
927 const CHAR_T* _replacment,
951 _regex.__psz, _regex.__psz + _regex.length(),
953 _replacement.__psz, _replacement.__psz + _replacement.length(),
984 _regex.__psz, _regex.__psz + _regex.length(),
1004 buf->__dataLength = dst -
buf->data();
1017 while (src < _end) {
1023 buf->__dataLength = dst -
buf->data();
1030#ifdef __DCL_INCLUDED_LOCALE_H
1031STRING_T STRING_T::toUpperCase(locale_t _locale)
const
1035 const CHAR_T* src = __psz;
1036 const CHAR_T* _end = __psz + length();
1037 while (src < _end) {
1043 buf->__dataLength = dst -
buf->data();
1056 while (src < _end) {
1062 buf->__dataLength = dst -
buf->data();
1070#ifdef __DCL_COMPILE_UNICODE__
1078 return String::toHexString(*
this, 20);
1087 while(first < last) {
1093 while(first < last) {
1102 size_t len = last - first;
1107 *(p +
len) =
_T(
'\0');
1123 while (first < last) {
1129 if (
__psz < first) {
1130 size_t len = last - first;
1135 *(p +
len) =
_T(
'\0');
1151 while(first < last) {
1158 size_t len = last - first;
1163 *(p +
len) =
_T(
'\0');
1179 while (first < last) {
1185 while (first < last) {
1194 size_t len = last - first;
1199 *(p +
len) =
_T(
'\0');
1216 while (first < last) {
1222 if (
__psz < first) {
1223 size_t len = last - first;
1229 *(p +
len) =
_T(
'\0');
1245 while (first < last) {
1252 size_t len = last - first;
1257 *(p +
len) =
_T(
'\0');
1273 return __psz[_index];
1284 while (*_psz++ &&
r < _max) {
1296 va_start(arglist, _format);
1297 int n = BUFFER_T::vformat(
buf, _format, arglist);
1307#ifndef __A_HEX_DEFINED
1308#define __A_HEX_DEFINED
1309static const CHAR_T __hex__[] =
_T(
"0123456789abcdef");
1312#define ASCII_32 _T(' ')
1313#define ASCII_126 _T('~')
1318 if (_flag == STRING_T::ESCAPE_DEFAULT) {
1320 || c ==
_T(
'\"') || c ==
_T(
'\'') || c ==
_T(
'\\'));
1322 else if (_flag == STRING_T::ESCAPE_EXTENDED) {
1349 const UCHAR_T* _end = src + _len;
1352 for( ; src < _end; src++) {
1355 case _T(
'&') : BUFFER_T::write(
buf,
_T(
"&"), 5);
break;
1356 case _T(
'<') : BUFFER_T::write(
buf,
_T(
"<"), 4);
break;
1357 case _T(
'>') : BUFFER_T::write(
buf,
_T(
">"), 4);
break;
1358 case _T(
'\"') : BUFFER_T::write(
buf,
_T(
"""), 6);
break;
1359 case _T(
'\'') : BUFFER_T::write(
buf,
_T(
"'"), 5);
break;
1361 BUFFER_T::write(
buf, c);
1367 for ( ; src < _end; src++) {
1368 unsigned int c = *src;
1370 BUFFER_T::write(
buf,
_T(
'\\'));
1372 case _T(
'\0') : BUFFER_T::write(
buf,
_T(
'0'));
break;
1373 case _T(
'\a') : BUFFER_T::write(
buf,
_T(
'a'));
break;
1374 case _T(
'\b') : BUFFER_T::write(
buf,
_T(
'b'));
break;
1375 case _T(
'\t') : BUFFER_T::write(
buf,
_T(
't'));
break;
1376 case _T(
'\n') : BUFFER_T::write(
buf,
_T(
'n'));
break;
1377 case _T(
'\v') : BUFFER_T::write(
buf,
_T(
'v'));
break;
1378 case _T(
'\f') : BUFFER_T::write(
buf,
_T(
'f'));
break;
1379 case _T(
'\r') : BUFFER_T::write(
buf,
_T(
'r'));
break;
1383 BUFFER_T::write(
buf, c);
1387 BUFFER_T::write(
buf,
_T(
'x'));
1388 BUFFER_T::write(
buf, __hex__[c >> 4]);
1389 BUFFER_T::write(
buf, __hex__[c & 0x0f]);
1391 else if (c <= 0xffff) {
1393 BUFFER_T::write(
buf,
_T(
'u'));
1403 for(
int i = 0; i < 4; i++)
1404 BUFFER_T::write(
buf, __hex__[a[i]]);
1407 BUFFER_T::write(
buf, c);
1412 BUFFER_T::write(
buf, c);
1416 BUFFER_T::shrink(
buf);
1425 if (
_T(
'0') <= c && c <=
_T(
'9'))
1427 else if (
_T(
'A') <= c && c <=
_T(
'F'))
1428 return c -
_T(
'A') + 10;
1429 else if (
_T(
'a') <= c && c <=
_T(
'f'))
1430 return c -
_T(
'a') + 10;
1442 if (_len == (
size_t)-1)
1450 const UCHAR_T* _end = src + _len;
1452 for ( ; src < _end; src++) {
1453 if (*src ==
_T(
'\\') && (src + 1) < _end) {
1455 case _T(
'0') : BUFFER_T::write(
buf,
_T(
'\0'));
break;
1456 case _T(
'a') : BUFFER_T::write(
buf,
_T(
'\a'));
break;
1457 case _T(
'b') : BUFFER_T::write(
buf,
_T(
'\b'));
break;
1458 case _T(
't') : BUFFER_T::write(
buf,
_T(
'\t'));
break;
1459 case _T(
'n') : BUFFER_T::write(
buf,
_T(
'\n'));
break;
1460 case _T(
'v') : BUFFER_T::write(
buf,
_T(
'\v'));
break;
1461 case _T(
'f') : BUFFER_T::write(
buf,
_T(
'\f'));
break;
1462 case _T(
'r') : BUFFER_T::write(
buf,
_T(
'\r'));
break;
1467 BUFFER_T::write(
buf, *src);
1471 if ((src + 2) < _end) {
1474 if (high >= 0 && low >= 0)
1476 BUFFER_T::write(
buf, (high << 4) | low);
1484 if ((src + 4) < _end) {
1487#ifdef __DCL_COMPILE_UNICODE__
1488 for (
int i = 1; i <= 4; i++) {
1494 for (
int i = 1; i <= 4; i++) {
1499 BUFFER_T::write(
buf, c);
1504 BUFFER_T::write(
buf, c);
1510 BUFFER_T::write(
buf,
_T(
'\\'));
1511 BUFFER_T::write(
buf, *src);
1516 BUFFER_T::write(
buf, *src);
1519 BUFFER_T::shrink(
buf);
1543 size_t dstlen =
len * 2 + 5;
1556 *dst++ = __hex__[*src >> 4];
1557 *dst++ = __hex__[*src & 0x0f];
1570 buf->__dataLength = dst -
buf->data();
1594 size_t dstlen =
len * 4 + 3;
1602 if (isprint(*src)) {
1608 *dst++ = __hex__[*src >> 4];
1609 *dst++ = __hex__[*src & 0x0f];
1623 buf->__dataLength = dst -
buf->data();
1638 while (_begin < _end) {
1654 while (_begin <= --_end) {
1671 const CHAR_T* subbegin = _sub;
1672 const CHAR_T* subend = _sub + _sublen;
1674 if (_begin == _end) {
1675 if (subbegin == subend)
1681 while (_begin < _end) {
1682 if (c == *_begin++) {
1684 const CHAR_T* s = _begin;
1685 const CHAR_T* _sub = subbegin;
1686 while (s < _end && _sub < subend && *s == *_sub)
1691 return (
CHAR_T*)--_begin;
1709 const CHAR_T* subbegin = _sub;
1710 const CHAR_T* subend = _sub + _sublen;
1712 if (_begin == _end) {
1713 if (subbegin == subend)
1720 while (_begin <= _end) {
1723 const CHAR_T* s = _end; s++;
1724 const CHAR_T* _sub = subbegin;
1725 while (_sub < subend && *s == *_sub)
1739 const CHAR_T* _delimiter,
1740 size_t _delimiterlen,
1746 while (_begin < _end && count < _limit) {
1750 _begin = s + _delimiterlen;
1757 if ((count < _limit) && ((_begin < _end) || (count == 0 && _begin == _end))) {
1774 while (_begin < _end && count < _limit) {
1785 if ((count < _limit) && ((_begin < _end) || (count == 0 && _begin == _end))) {
1800 ARRAY_T::ConstIterator it = _array.
begin();
1801 if (it != _array.
end()) {
1805 if (++it == _array.
end()) {
1825 return _b ?
_T(
"true") :
_T(
"false");
1830#ifdef __DCL_COMPILE_UNICODE__
1839#ifdef __DCL_COMPILE_UNICODE__
1848#ifdef __DCL_COMPILE_UNICODE__
1857#ifdef __DCL_COMPILE_UNICODE__
1866#ifdef __DCL_COMPILE_UNICODE__
1875#ifdef __DCL_COMPILE_UNICODE__
1885#ifdef __DCL_COMPILE_UNICODE__
1891#ifdef __DCL_COMPILE_UNICODE__
1902#ifdef __DCL_COMPILE_UNICODE__
1908#ifdef __DCL_COMPILE_UNICODE__
1918#ifdef __DCL_COMPILE_UNICODE__
1927#ifdef __DCL_COMPILE_UNICODE__
1936#ifdef __DCL_COMPILE_UNICODE__
1937 return String::format(L
"%g", _n);
1939 return ByteString::format(
"%g", _n);
1945#ifdef __DCL_COMPILE_UNICODE__
1946 return String::format(L
"%g", _n);
1948 return ByteString::format(
"%g", _n);
1954#ifdef __DCL_COMPILE_UNICODE__
1955 return String::format(L
"%Lg", _n);
1957 return ByteString::format(
"%Lg", _n);
1961#if __DCL_HAVE_THIS_FILE__
1962 #undef __THIS_FILE__
#define STRCASECMP(s1, s2)
size_t __extended_length(size_t _allocLength)
#define STRNCMP(s1, s2, n)
#define VSNPRINTF(buf, len, fmt, args)
bool __escapeable(unsigned int c, STRING_T::EscapeFlags _flag)
DCLCAPI STRING_T operator+(const STRING_T &_str1, const STRING_T &_str2)
#define STRNCASECMP(s1, s2, n)
StringArray & __regex_split(const wchar_t *_regex, const wchar_t *_regexend, const wchar_t *_begin, const wchar_t *_end, bool _icase, StringArray &_results, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)
bool __regex_search(regex_handle _handle, const wchar_t *_begin, const wchar_t *_end, match_result **_results, unsigned int _flags)
String __regex_substring(const wchar_t *_regex, const wchar_t *_regexend, const wchar_t *_begin, const wchar_t *_end, bool _icase) __DCL_THROWS1(RegexException *)
bool __regex_matches(const wchar_t *_regex, const wchar_t *_regexend, const wchar_t *_begin, const wchar_t *_end, bool _icase) __DCL_THROWS1(RegexException *)
String __regex_replace(const wchar_t *_regex, const wchar_t *_regexend, const wchar_t *_begin, const wchar_t *_end, const wchar_t *_replacement, const wchar_t *_replacementend, bool _icase, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)
#define __DCL_ASSERT_PARAM(expr)
#define __DCL_TRACE3(fmt, arg1, arg2, arg3)
#define __CONCAT_TEXT(str, expr)
#define __DCL_ASSERT(expr)
#define __DCL_TRACE2(fmt, arg1, arg2)
void CharsetConvertException *size_t n
void CharsetConvertException *__fields clear()
ARRAY_T & add(CONST_ELEMENT_REF _element)
ConstIterator end() const
ConstIterator begin() const
static ByteString toByteString(int32_t _n, unsigned _base=10)
String toString(unsigned _base=10) const
static ByteString toByteString(int64_t _n, unsigned _base=10)
String toString(unsigned _base=10) const
int compare(const CHAR_T *_psz, size_t _len=(size_t) -1) const
STRING_T padCenter(size_t _len, CHAR_T _ch) const
STRING_T toUpperCase() const
static STRING_T escape(const CHAR_T *_ps, size_t _len, EscapeFlags _flag=ESCAPE_DEFAULT)
static size_t split(const CHAR_T *_begin, const CHAR_T *_end, const CHAR_T *_delimiter, size_t _delimiterlen, ARRAY_T &_results, size_t _limit=(size_t) -1)
const CHAR_T * data() const
static STRING_T toHexString(const char *_bytes, size_t _len, size_t _max=(size_t) -1, bool _prefix=true)
size_t lastIndexOf(CHAR_T _ch, size_t _start=0) const
static STRING_T tryString(const char *_bytes, size_t _len, size_t _max=(size_t) -1)
static CHAR_T * rfind(const CHAR_T *_begin, const CHAR_T *_end, CHAR_T _ch)
static STRING_T join(const ARRAY_T &_array, CHAR_T _delimiter, bool _hasEmpty=false)
STRING_T mid(size_t _first, size_t _len=(size_t) -1) const
STRING_T trimLeft() const
ARRAY_T & split_r(const CHAR_T *_regex, bool _icase, ARRAY_T &_results, size_t _limit=(size_t) -1) const __DCL_THROWS1(RegexException *)
STRING_T trimRight() const
STRING_T padRight(size_t _len, CHAR_T _ch) const
friend class STRING_BUILDER_T
STRING_T padLeft(size_t _len, CHAR_T _ch) const
STRING_T replace(size_t _start, size_t _len, const CHAR_T *_new, size_t _newlen=(size_t) -1) const
bool matches(const CHAR_T *_regex, bool _icase) const __DCL_THROWS1(RegexException *)
void assignAlloc(size_t _len)
static STRING_T format(const CHAR_T *_format,...)
static CHAR_T * find(const CHAR_T *_begin, const CHAR_T *_end, CHAR_T _ch)
STRING_T left(size_t _len) const
static STRING_T unescape(const CHAR_T *_psz, size_t _len)
STRING_T replace_r(const CHAR_T *_regex, const CHAR_T *_replacment, bool _icase, size_t _limit=(size_t) -1) const __DCL_THROWS1(RegexException *)
CHAR_T operator[](size_t _index) const
int compareNoCase(const CHAR_T *_psz, size_t _len=(size_t) -1) const
size_t indexOf(CHAR_T _ch, size_t _start=0) const
STRING_T right(size_t _len) const
bool searches(const CHAR_T *_regex, bool _icase) const __DCL_THROWS1(RegexException *)
size_t search(const CHAR_T *_regex, bool _icase) const __DCL_THROWS1(RegexException *)
STRING_T toLowerCase() const
static STRING_T valueOf(bool _b)
STRING_T & assign(const STRING_T &_str)
STRING_T substring(size_t _first) const
STRING_T rreplace(size_t _start, size_t _len, const CHAR_T *_new, size_t _newlen=(size_t) -1) const
static long incrementAndGet(volatile long &_n)
static long decrementAndGet(volatile long &_n)
static ByteString toByteString(uint32_t _u, unsigned _base=10)
String toString(unsigned _base=10) const
static ByteString toByteString(uint64_t _u, unsigned _base=10)
String toString(unsigned _base=10) const
size_t __MAX(size_t x, size_t y)
size_t __MIN(size_t x, size_t y)
static void destroy(BUFFER_T *_buf)
static BUFFER_T * create(size_t _len)
static void extend(BUFFER_T *&_buf, size_t _len)
static BUFFER_T * create_e(size_t _len)
static void write(BUFFER_T *&_buf, const CHAR_T *_str, size_t _len)
static void shrink(BUFFER_T *&_buf)
static int vformat(BUFFER_T *&_buf, const CHAR_T *_format, va_list _arglist)