41 #include <corelib/ncbi_base64.h>
51 #define NCBI_USE_ERRCODE_X Corelib_Util
58 static const char kDigitUpper[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
59 static const char kDigitLower[] =
"0123456789abcdefghijklmnopqrstuvwxyz";
70 #if defined(HAVE_WSTRING)
79 #ifdef NCBI_PRODUCTION_VER
80 extern const char*
const kNcbiProductionVersionString;
81 const char*
const kNcbiProductionVersionString
86 #if !defined(NCBI_OS_MSWIN) && \
87 !(defined(NCBI_OS_LINUX) && \
88 (defined(NCBI_COMPILER_GCC) || defined(NCBI_COMPILER_ANY_CLANG)))
89 const string* CNcbiEmptyString::m_Str = 0;
90 const string& CNcbiEmptyString::FirstGet(
void) {
91 static const string s_Str =
"";
96 const wstring* CNcbiEmptyWString::m_Str = 0;
97 const wstring& CNcbiEmptyWString::FirstGet(
void) {
98 static const wstring s_Str = L
"";
128 if (
int res = memcmp(s1.
data(), s2.
data(),
min(n1, n2))) {
131 return (n1 == n2) ? 0 : (n1 > n2 ? 1 : -1);
147 const char* s = s1.
data() + pos;
148 while (
n && *s2 && *s == *s2) {
162 return s2.
empty() ? 0 : -1;
171 if (n_cmp > s2.
length()) {
174 const char* s = s1.
data() + pos;
175 const char* p = s2.
data();
176 while (n_cmp && *s == *p) {
183 return n > s2.
length() ? 1 : -1;
202 const char* p1 = s1.
data();
203 const char* p2 = s2.
data();
205 while (
n && (*p1 == *p2 ||
206 tolower((
unsigned char)(*p1)) ==
tolower((
unsigned char)(*p2))) ) {
210 return (n1 == n2) ? 0 : (n1 > n2 ? 1 : -1);
215 return tolower((
unsigned char)(*p1)) -
tolower((
unsigned char)(*p2));
233 const char* s = s1.
data() + pos;
234 while (
n && *s2 && (*s == *s2 ||
235 tolower((
unsigned char)(*s)) ==
tolower((
unsigned char)(*s2))) ) {
244 return tolower((
unsigned char)(*s)) -
tolower((
unsigned char)(*s2));
252 return s2.
empty() ? 0 : -1;
262 if (n_cmp > s2.
length()) {
265 const char* s = s1.
data() + pos;
266 const char* p = s2.
data();
267 while (n_cmp && (*s == *p ||
277 return tolower((
unsigned char)(*s)) -
tolower((
unsigned char)(*p));
294 size_t str_pos = 0, mask_pos = 0;
296 for ( ; (m =
mask[mask_pos]); ++str_pos, ++mask_pos) {
300 if (!s && m !=
'*') {
310 while ( (m =
mask[mask_pos]) ==
'*' ) mask_pos++;
328 if (!(m =
mask[++mask_pos]))
336 s = (char)
tolower((
unsigned char) s);
340 if (!(
a =
mask[mask_pos++]))
342 if (
mask[mask_pos] ==
'-' &&
mask[mask_pos+1] !=
']') {
344 if (!(
b =
mask[mask_pos++]))
353 if (
a <= s && s <=
b)
356 }
while (
mask[mask_pos] !=
']');
362 if (!(m =
mask[++mask_pos]))
370 if (s != m &&
tolower((
unsigned char)s) !=
tolower((
unsigned char)m))
380 if (
str[str_pos] ) {
408 *it = (char)
tolower((
unsigned char)(*it));
427 *it = (char)
toupper((
unsigned char)(*it));
459 int error = 0, ret = -1;
467 if (
str.data()[0] ==
'+' &&
len > 1) {
471 for (;
i <
len; ++
i) {
472 unsigned d =
str.data()[
i] -
'0';
477 unsigned nv = v * 10 + d;
478 const unsigned kOverflowLimit = (INT_MAX - 9) / 10 + 1;
479 if (v >= kOverflowLimit) {
481 if (v > kOverflowLimit || nv > INT_MAX) {
489 ret =
static_cast<int>(v);
548 s.reserve(
str.length() + msg.
length() + 50);
549 s +=
"Cannot convert string '";
553 if ( !msg.
empty() ) {
561 #define S2N_CONVERT_GUARD(flags) \
562 CS2N_Guard err_guard(flags, false)
566 #define S2N_CONVERT_GUARD_EX(flags) \
567 CS2N_Guard err_guard(flags, true)
569 #define S2N_CONVERT_ERROR(to_type, msg, errcode, pos) \
571 err_guard.Set(errcode); \
572 if ( !(flags & NStr::fConvErr_NoThrow) ) { \
574 NCBI_THROW2(CStringException, eConvert, \
575 err_guard.Message(str, #to_type, msg), pos); \
583 if (flags & NStr::fConvErr_NoErrMessage) { \
584 CNcbiError::SetErrno(err_guard.Errno()); \
586 CNcbiError::SetErrno(err_guard.Errno(), \
587 err_guard.Message(str, #to_type, msg)); \
594 #define S2N_CONVERT_ERROR_INVAL(to_type) \
595 S2N_CONVERT_ERROR(to_type, kEmptyStr, EINVAL, pos)
597 #define S2N_CONVERT_ERROR_RADIX(to_type, msg) \
598 S2N_CONVERT_ERROR(to_type, msg, EINVAL, pos)
600 #define S2N_CONVERT_ERROR_OVERFLOW(to_type) \
601 S2N_CONVERT_ERROR(to_type, "overflow", ERANGE, pos)
603 #define CHECK_ENDPTR(to_type) \
605 S2N_CONVERT_ERROR(to_type, kEmptyStr, EINVAL, pos); \
608 #define CHECK_ENDPTR_SIZE(to_type) \
609 if ( pos < size ) { \
610 S2N_CONVERT_ERROR(to_type, kEmptyStr, EINVAL, pos); \
613 #define CHECK_COMMAS \
615 if (flags & NStr::fAllowCommas) { \
617 if ((numpos == pos) || \
618 ((comma >= 0) && (comma != 3)) ) { \
639 if ( value < kMin_Int || value >
kMax_Int ) {
654 return (
unsigned int)
value;
662 if ( value < kMin_Long || value > kMax_Long ) {
674 if (
value > kMax_ULong ) {
677 return (
unsigned long)
value;
689 if (
unsigned(
delta) <
unsigned(base) ) {
697 if (!
isalnum((
unsigned char) ch)) {
702 if (
isdigit((
unsigned char) ch)) {
705 ch = (char)
tolower((
unsigned char) ch);
706 delta = ch -
'a' + 10;
726 if ( ch !=
'.' && ch !=
',') {
733 return ch ==
'.' || ch ==
',';
735 struct lconv*
conv = localeconv();
736 return ch == *(
conv->decimal_point);
751 unsigned char ch =
str[pos];
768 if ( base == 10 || base == 8 ) {
773 if ( base < 0 || base == 1 || base > 36 ) {
777 unsigned char ch =
str[pos];
778 unsigned char next =
str[pos+1];
782 }
else if (
next ==
'x' ||
next ==
'X') {
790 if (ch ==
'0' && (
next ==
'x' ||
next ==
'X')) {
842 while (
char ch =
str[pos]) {
852 if (
n >= limdiv && (
n > limdiv ||
delta > limoff) ) {
861 if ( pos == pos0 || ((comma >= 0) && (comma != 3)) ) {
879 TStringToNumFlags
flags,
int base)
886 if ( base == 10 && (
flags & slow_flags) == 0 ) {
893 if ( ptr != end && *ptr ==
'+' ) {
908 int delta = ch -
'0';
909 if (
unsigned(
delta) >= 10 ) {
913 if (
n >= limdiv && (
n > limdiv ||
delta > limoff) ) {
917 }
while ( ++ptr != end );
932 if (
str[pos] ==
'+') {
956 while (
char ch =
str[pos]) {
966 if (
n >= limdiv && (
n > limdiv ||
delta > limoff) ) {
975 if ( pos == pos0 || ((comma >= 0) && (comma != 3)) ) {
993 const char* start = ptr;
997 while (
isspace((
unsigned char)c) ) {
1006 else if ( c ==
'+' ) {
1013 *endptr = (
char*)start;
1015 err_guard.Set(EINVAL);
1020 if ( !*ptr && c >=
'0' && c <=
'9' ) {
1022 *endptr = (
char*)ptr;
1029 bool dot =
false, expn =
false, anydigits =
false;
1030 int digits = 0, dot_position = 0;
1031 unsigned int first=0, second=0, first_mul=1;
1036 for ( ; ; c = *ptr++ ) {
1037 if (c >=
'0' && c <=
'9') {
1039 c = (char)(c -
'0');
1051 }
else if (digits <= 9) {
1054 }
else if (digits <= 18) {
1057 second = second*10 + c;
1064 else if (c ==
'.') {
1071 dot_position = digits;
1074 else if (c ==
'e' || c ==
'E') {
1086 if ( !dot && (c ==
'n' || c ==
'N') &&
1089 *endptr = (
char*)(ptr+3);
1091 return HUGE_VAL/HUGE_VAL;
1093 if ( (c ==
'i' || c ==
'I') ) {
1100 *endptr = (
char*)ptr;
1102 return sign < 0 ? -HUGE_VAL : HUGE_VAL;
1112 *endptr = (
char*)start;
1114 err_guard.Set(EINVAL);
1117 int exponent = dot ? dot_position - digits : 0;
1122 bool expsign =
false, expnegate=
false;
1127 if (c ==
'-' || c ==
'+') {
1129 if (expsign || expdigits) {
1133 expnegate = c ==
'-';
1136 else if (c >=
'0' && c <=
'9') {
1138 int newexpvalue = expvalue*10 + (c-
'0');
1139 if (newexpvalue > expvalue) {
1140 expvalue = newexpvalue;
1159 exponent = expnegate ? exponent - expvalue : exponent + expvalue;
1163 if ( first_mul > 1 ) {
1165 ret = ((
long double)
first * first_mul + second)* second_mul + third;
1175 if (
first && exponent ) {
1177 if (exponent > 2*DBL_MAX_10_EXP) {
1179 err_guard.Set(ERANGE);
1180 }
else if (exponent < 2*DBL_MIN_10_EXP) {
1182 err_guard.Set(ERANGE);
1184 if ( exponent > 0 ) {
1185 static const double mul1[16] = {
1186 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7,
1187 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15
1189 ret *= mul1[exponent&15];
1190 if ( exponent >>= 4 ) {
1191 static const long double mul2[16] = {
1209 ret *= mul2[exponent&15];
1210 for ( exponent >>= 4; exponent; --exponent ) {
1214 if (!
finite(
double(ret))) {
1218 err_guard.Set(ERANGE);
1222 exponent = -exponent;
1223 static const long double mul1[16] = {
1241 ret *= mul1[exponent&15];
1242 if ( exponent >>= 4 ) {
1243 static const long double mul2[16] = {
1261 ret *= mul2[exponent&15];
1262 for ( exponent >>= 4; exponent; --exponent ) {
1266 if ( ret < DBL_MIN ) {
1270 err_guard.Set(ERANGE);
1280 *endptr = (
char*)ptr;
1293 "NStr::StringToDouble(): mutually exclusive flags specified", 0);
1327 int& errno_ref = errno;
1331 const char* begptr =
str + pos;
1337 n = strtod(begptr, &endptr);
1342 if (!endptr || (endptr2 && endptr2 > endptr)) {
1347 if ( !endptr || endptr == begptr ) {
1352 if ( errno_ref && errno_ref != ERANGE ) {
1358 bool is_negative =
n < 0.;
1386 TStringToNumFlags
flags)
1395 if (
str.HasZeroAtEnd() ) {
1419 unsigned char ch =
str[pos];
1424 ch = (
unsigned char)
toupper(ch);
1438 if ((
kMax_UI8 / 1024 / 1024) < v) {
1445 if ((
kMax_UI8 / 1024 / 1024 / 1024) < v) {
1448 v *= 1024 * 1024 * 1024;
1459 if ( ch &&
toupper(ch) ==
'B' ) {
1467 TStringToNumFlags
flags,
1471 if ( base < 2 || base > 16 ) {
1490 if (
str[pos] ==
'+') {
1517 if (pos-numpos == 0) {
1524 if ( !
n && errno ) {
1545 TStringToNumFlags
flags )
1561 const char* str_ptr =
str.data();
1562 const char* str_end = str_ptr +
str.size();
1565 for (; str_ptr < str_end; ++str_ptr) {
1572 && str_ptr + 1 < str_end &&
isdigit(*(str_ptr + 1)))
1581 if (str_ptr < str_end && *str_ptr ==
'+') {
1584 else if ((str_ptr < str_end && *str_ptr ==
'-')
1590 const char* num_start = str_ptr;
1591 bool have_dot =
false;
1594 Uint4 digs_pre_dot = 0, digs_post_dot = 0;
1596 for (; str_ptr < str_end; ++str_ptr) {
1604 else if (c ==
'.' && allow_dot) {
1605 if (have_dot || str_ptr == num_start)
1607 if (*(str_ptr - 1) ==
',') {
1613 else if (c ==
',' && allow_commas) {
1614 if (have_dot || str_ptr == num_start)
1616 if (*(str_ptr - 1) ==
',') {
1624 if (have_dot && digs_post_dot == 0)
1626 else if (str_ptr > num_start && *(str_ptr - 1) ==
',')
1629 const char* num_end = str_ptr;
1630 if (num_start == num_end) {
1633 if (str_ptr < str_end && *str_ptr ==
' '
1639 if (str_ptr < str_end)
1640 suff_c = (char)
toupper(*str_ptr);
1642 static const char s_Suffixes[] = {
'K',
'M',
'G',
'T',
'P',
'E'};
1643 static const char*
const s_BinCoefs[] = {
"1024",
"1048576",
"1073741824",
1646 "1152921504606846976"};
1647 static const Uint4 s_NumSuffixes = (
Uint4)(
sizeof(s_Suffixes) /
sizeof(s_Suffixes[0]));
1651 for (; suff_idx < s_NumSuffixes; ++suff_idx) {
1652 if (suff_c == s_Suffixes[suff_idx])
1655 if (suff_idx < s_NumSuffixes) {
1657 if (str_ptr + 1 < str_end &&
toupper(*str_ptr) ==
'I'
1658 &&
toupper(*(str_ptr + 1)) ==
'B')
1663 else if (str_ptr < str_end &&
toupper(*str_ptr) ==
'B')
1666 else if (suff_c ==
'B') {
1669 else if (*(str_ptr - 1) ==
' ')
1674 for (; str_ptr < str_end; ++str_ptr) {
1682 if (str_ptr != str_end) {
1686 Uint4 orig_digs = digs_pre_dot + digs_post_dot;
1688 str_ptr = num_start;
1689 for (
Uint4 i = 0; str_ptr < num_end; ++str_ptr) {
1690 if (*str_ptr ==
',' || *str_ptr ==
'.')
1692 orig_num[
i++] =
Uint1(*str_ptr -
'0');
1695 Uint1* num_to_conv = orig_num.get();
1696 Uint4 digs_to_conv = digs_pre_dot;
1698 if (binary_suff && suff_idx < s_NumSuffixes) {
1699 const char* coef = s_BinCoefs[suff_idx];
1701 mul_num =
new Uint1[orig_digs + coef_size];
1702 memset(mul_num.
get(), 0, orig_digs + coef_size);
1703 for (
Uint4 coef_i = 0; coef_i < coef_size; ++coef_i) {
1706 Uint4 res_idx = orig_digs + coef_i;
1707 for (
int orig_i = orig_digs - 1; orig_i >= 0; --orig_i, --res_idx) {
1708 Uint1 orig_d = orig_num[orig_i];
1709 Uint1 res_d =
Uint1(coef_d * orig_d + carry + mul_num[res_idx]);
1711 while (res_d >= 10) {
1712 res_d = (
Uint1)(res_d - 10);
1715 mul_num[res_idx] = res_d;
1718 for (; carry != 0; --res_idx) {
1719 Uint1 res_d =
Uint1(mul_num[res_idx] + carry);
1721 while (res_d >= 10) {
1722 res_d = (
Uint1)(res_d - 10);
1725 mul_num[res_idx] = res_d;
1728 digs_to_conv = orig_digs + coef_size - digs_post_dot;
1729 num_to_conv = mul_num.
get();
1730 while (digs_to_conv > 1 && *num_to_conv == 0) {
1735 else if (suff_idx < s_NumSuffixes) {
1736 Uint4 coef_size = (suff_idx + 1) * 3;
1737 if (coef_size <= digs_post_dot) {
1738 digs_to_conv += coef_size;
1739 digs_post_dot -= coef_size;
1742 digs_to_conv += digs_post_dot;
1743 coef_size -= digs_post_dot;
1745 mul_num =
new Uint1[digs_to_conv + coef_size];
1746 memmove(mul_num.
get(), num_to_conv, digs_to_conv);
1747 memset(mul_num.
get() + digs_to_conv, 0, coef_size);
1748 num_to_conv = mul_num.
get();
1749 digs_to_conv += coef_size;
1756 for (
Uint4 i = 0;
i < digs_to_conv; ++
i) {
1757 Uint1 d = num_to_conv[
i];
1758 if (
n >= limdiv && (
n > limdiv || d > limoff)) {
1764 if (digs_post_dot != 0 && num_to_conv[digs_to_conv] >= 5) {
1775 TStringToNumFlags
flags,
int base)
1777 #if (SIZEOF_SIZE_T > 4)
1786 template <
typename T>
1803 out_str.append(
"0x");
1807 *--pos = kDigit[
value % 16];
1811 else if ( base == 8 ) {
1813 out_str.append(
"0");
1820 *--pos = kDigit[
value % 8];
1826 *--pos = kDigit[
value % base];
1836 unsigned long value,
1848 value =
static_cast<unsigned long>(-svalue);
1857 *--pos =
'0' +
value % 10;
1863 *--pos =
'0' +
value % 10;
1878 TNumToStringFlags
flags,
int base)
1880 if ( base < 2 || base > 36 ) {
1884 unsigned int value =
static_cast<unsigned int>(svalue);
1895 TNumToStringFlags
flags,
int base)
1897 if ( base < 2 || base > 36 ) {
1901 unsigned long value =
static_cast<unsigned long>(svalue);
1912 unsigned long value,
1913 TNumToStringFlags
flags,
1916 if ( base < 2 || base > 36 ) {
1933 *--pos =
'0' +
value % 10;
1939 *--pos =
'0' +
value % 10;
1961 #define PRINT_INT8_CHUNK 1000000000
1962 #define PRINT_INT8_CHUNK_SIZE 9
1971 #ifdef PRINT_INT8_CHUNK
1984 *--pos =
'0' + chunk % 10;
1986 }
while ( pos != end );
1995 *--pos =
'0' + chunk % 10;
2004 *--pos =
'0' +
value % 10;
2010 #ifdef PRINT_INT8_CHUNK
2019 *--pos =
'0' + chunk % 10;
2021 }
while ( pos != end );
2026 *--pos =
'0' + chunk % 10;
2031 *--pos =
'0' +
value % 10;
2041 TNumToStringFlags
flags,
int base)
2043 if ( base < 2 || base > 36 ) {
2052 value =
static_cast<Uint8>(svalue<0?-svalue:svalue);
2068 TNumToStringFlags
flags,
int base)
2070 if ( base < 2 || base > 36 ) {
2092 TNumToStringFlags
flags ,
2093 unsigned int max_digits )
2110 static const char s_Suffixes[] = {
'K',
'M',
'G',
'T',
'P',
'E'};
2111 static const Uint4 s_NumSuffixes =
Uint4(
sizeof(s_Suffixes) /
sizeof(s_Suffixes[0]));
2118 Uint4 digs_pre_dot, suff_idx;
2121 static const Uint8 s_Coefs[] = {1000, 1000000, 1000000000,
2126 for (; suff_idx < s_NumSuffixes; ++suff_idx) {
2127 if (
value < s_Coefs[suff_idx])
2131 num_start[-1] =
'0';
2133 digs_pre_dot =
Uint4(dot_ptr - num_start);
2138 while (suff_idx > 0 && max_digits - digs_pre_dot >= 3) {
2145 char* round_dig = num_end - 1;
2146 if (num_end < buffer + kBufSize && *num_end >=
'5')
2148 while (*round_dig ==
'0' + 10) {
2153 if (round_dig < num_start) {
2154 _ASSERT(num_start - round_dig == 1);
2155 num_start = round_dig;
2158 if (digs_pre_dot > 3) {
2166 if (digs_pre_dot > max_digits) {
2176 static const Uint8 s_Coefs[] = {1, 1024, 1048576, 1073741824,
2182 for (; suff_idx < s_NumSuffixes; ++suff_idx) {
2183 if (
value < s_Coefs[suff_idx])
2186 bool can_try_another =
true;
2188 Uint8 mul_coef = s_Coefs[suff_idx - 1];
2190 if (max_digits == 3 && whole_num >= 1000) {
2192 goto try_another_suffix;
2195 num_start[-1] =
'0';
2198 && suff_idx != 1 && can_try_another)
2200 Uint4 new_suff = suff_idx - 1;
2201 try_even_more_suffix:
2202 Uint8 new_num =
value / s_Coefs[new_suff - 1];
2205 if (new_digs <= max_digits) {
2206 if (max_digits - digs_pre_dot >= 3 && new_suff != 1) {
2208 goto try_even_more_suffix;
2210 suff_idx = new_suff;
2211 can_try_another =
false;
2212 goto try_another_suffix;
2214 if (new_suff != suff_idx - 1) {
2215 suff_idx = new_suff + 1;
2216 can_try_another =
false;
2217 goto try_another_suffix;
2220 memcpy(
buffer, num_start - 1, digs_pre_dot + 1);
2222 dot_ptr = num_start + digs_pre_dot;
2223 Uint4 cnt_more_digs = 1;
2225 cnt_more_digs +=
min(max_digits - digs_pre_dot, 3 * (suff_idx - 1));
2227 Uint8 left_val =
value - whole_num * mul_coef;
2231 *num_end = char(d +
'0');
2233 left_val -= d * mul_coef;
2236 while (cnt_more_digs != 0);
2239 char* round_dig = num_end - 1;
2240 if (*num_end >=
'5')
2242 while (*round_dig ==
'0' + 10) {
2247 if (round_dig < num_start) {
2249 num_start = round_dig;
2251 if (digs_pre_dot > max_digits) {
2253 goto try_another_suffix;
2255 if (num_end != dot_ptr)
2259 && num_start[0] ==
'1' && num_start[1] ==
'0'
2260 && num_start[2] ==
'2' && num_start[3] ==
'4')
2263 goto try_another_suffix;
2271 out_str.append(1,
'+');
2273 out_str.append(num_start, digs_pre_dot);
2276 Uint4 digs_first = digs_pre_dot % 3;
2277 out_str.append(num_start, digs_first);
2278 char* left_ptr = num_start + digs_first;
2279 Uint4 digs_left = digs_pre_dot - digs_first;
2280 while (digs_left != 0) {
2281 out_str.append(1,
',');
2282 out_str.append(left_ptr, 3);
2287 if (num_end != dot_ptr) {
2288 out_str.append(1,
'.');
2289 out_str.append(dot_ptr, num_end - dot_ptr);
2292 if (suff_idx == 0) {
2295 out_str.append(1,
' ');
2296 out_str.append(1,
'B');
2302 out_str.append(1,
' ');
2303 out_str.append(1, s_Suffixes[suff_idx]);
2306 out_str.append(1,
'i');
2307 out_str.append(1,
'B');
2315 #if defined(NCBI_OS_MSWIN)
2353 struct lconv*
conv = localeconv();
2354 if (
'.' != *(
conv->decimal_point)) {
2355 char* pos = strchr(
buffer, *(
conv->decimal_point));
2369 TNumToStringFlags
flags)
2376 if (memcmp(&
value, &zero,
sizeof(
double)) == 0) {
2386 }
else if (
value > 0.) {
2415 struct lconv*
conv = localeconv();
2416 if (
'.' != *(
conv->decimal_point)) {
2417 char* pos = strchr(
buffer, *(
conv->decimal_point));
2433 char* buffer_start =
buffer;
2434 char* buffer_end = (
buffer += digits-1);
2443 }
while (
value /= 10);
2445 if (++
buffer != buffer_start) {
2447 buffer_end -=
buffer - buffer_start;
2450 return ++buffer_end;
2454 #define __NLG NCBI_CONST_LONGDOUBLE
2458 int* dec,
int* sign)
2470 if (memcmp(&
val, &zero,
sizeof(
double)) == 0) {
2479 *sign =
val < 0. ? -1 : 1;
2487 bool exp_positive =
val >= 1.;
2488 unsigned int first, second=0;
2489 long double mult =
__NLG(1.);
2529 else {mult=
__NLG(1.e-8); exp+=16;}
2566 else {mult=
__NLG(1.e8); }
2570 long double t1 =
value * mult;
2571 if (t1 >=
__NLG(1.e9)) {
2573 }
else if (t1 <
__NLG(1.e8)) {
2579 if (high_precision) {
2581 if (t2 >=
__NLG(1.e8)) {
2584 second = (
unsigned int)t2;
2589 bool use_ext_buffer =
bufsize > 20;
2591 char *digits = use_ext_buffer ?
buffer :
tmp;
2593 if (high_precision) {
2596 size_t digits_len = digits_end - digits;
2597 size_t digits_got = digits_len;
2598 size_t digits_expected = high_precision ? 17 : 9;
2608 if (high_precision) {
2609 if (digits[pos] ==
'4') {
2611 while (pt != 0 && digits[--pt] ==
'9')
2615 }
else if (digits[pos] ==
'5') {
2617 while (pt != 0 && digits[--pt] ==
'0')
2625 if (digits[pos] >=
'5') {
2627 if (digits[--pos] <
'9') {
2634 if (digits_expected <= digits_got) {
2639 exp_positive = --exp == 0;
2649 for (pos = digits_len; pos-- > 0 && digits[pos] ==
'0';)
2652 *dec = exp_positive ?
int(exp) : -
int(exp);
2654 if (!use_ext_buffer) {
2656 memcpy(
buffer, digits, digits_len);
2659 "Destination buffer too small", 0);
2672 "Destination buffer too small", 0);
2678 if (digits_len == 0) {
2683 strncpy(
buffer,digits, digits_len);
2686 if (digits_len == 1 && dec == 0 && sign >=0) {
2691 bool exp_positive = dec >= 0;
2692 unsigned int exp= (
unsigned int)(exp_positive ? dec : (-dec));
2695 char *buffer_pos =
buffer;
2697 char *digits_pos = digits;
2700 *buffer_pos++ =
'-';
2704 if ((exp_positive && exp >=
precision) || (!exp_positive && exp > 4)) {
2705 *buffer_pos++ = *digits_pos++;
2707 if (digits_len != 0) {
2708 *buffer_pos++ =
'.';
2709 strncpy(buffer_pos,digits_pos,digits_len);
2710 buffer_pos += digits_len;
2712 *buffer_pos++ =
'e';
2713 *buffer_pos++ = exp_positive ?
'+' :
'-';
2716 #if NCBI_COMPILER_MSVC && _MSC_VER < 1900
2717 bool need_zeros =
true;
2718 size_t need_digits = 3;
2720 bool need_zeros = exp < 10 ?
true :
false;
2721 size_t need_digits = exp < 100 ? 2 : 3;
2725 }
else if (exp_positive) {
2726 *buffer_pos++ = *digits_pos++;
2728 if (digits_len > exp) {
2729 strncpy(buffer_pos,digits_pos,exp);
2731 *buffer_pos++ =
'.';
2732 strncpy(buffer_pos,digits_pos+exp,digits_len-exp);
2733 buffer_pos += digits_len-exp;
2735 strncpy(buffer_pos,digits_pos,digits_len);
2736 buffer_pos += digits_len;
2737 exp -= (
unsigned int)digits_len;
2739 *buffer_pos++ =
'0';
2743 *buffer_pos++ =
'0';
2744 *buffer_pos++ =
'.';
2745 for (--exp; exp--;) {
2746 *buffer_pos++ =
'0';
2748 strncpy(buffer_pos,digits_pos, digits_len);
2749 buffer_pos += digits_len;
2752 return buffer_pos -
buffer;
2758 #if (SIZEOF_SIZE_T > 4)
2791 if (
str.HasZeroAtEnd() ) {
2792 res = ::sscanf(
str.data(),
"%p", &ptr);
2794 res = ::sscanf(
string(
str).c_str(),
"%p", &ptr);
2847 "String cannot be converted to bool", 0);
2853 #ifdef HAVE_VASPRINTF
2864 #elif defined(HAVE_VSNPRINTF)
2881 #elif defined(HAVE_VPRINTF)
2883 buf[
sizeof(
buf) - 1] = 0;
2885 if (
buf[
sizeof(
buf) - 1]) {
2891 # error Please port this code to your system.
2899 EDirection direction,
2913 if (use_case ==
eCase) {
2917 pos =
str.find(pattern, search_pos);
2922 search_pos = pos + plen;
2923 ++current_occurence;
2925 while (current_occurence <= occurence);
2929 search_pos = slen - plen;
2931 pos =
str.rfind(pattern, search_pos);
2936 search_pos = (pos < plen) ? 0 : pos - plen;
2937 ++current_occurence;
2939 while (current_occurence <= occurence);
2946 string x_first(pattern, 0, 1);
2947 if (
isupper((
unsigned char)x_first[0])) {
2948 x_first += (char)
tolower((
unsigned char)x_first[0]);
2949 }
else if (
islower((
unsigned char)x_first[0])) {
2950 x_first += (char)
toupper((
unsigned char)x_first[0]);
2955 pos =
str.find_first_of(x_first, search_pos);
2956 while (pos !=
NPOS) {
2957 if ( (pos + plen) > slen ) {
2963 pos =
str.find_first_of(x_first, pos + 1);
2969 search_pos = pos + plen;
2970 ++current_occurence;
2972 while (current_occurence <= occurence);
2976 search_pos = slen - plen;
2978 pos =
str.find_last_of(x_first, search_pos);
2979 while (pos !=
NPOS && pos
2984 pos =
str.find_last_of(x_first, pos - 1);
2987 search_pos = (pos < plen) ? 0 : pos - plen;
2988 ++current_occurence;
2990 while (current_occurence <= occurence);
3001 string pat(pattern, 0, 1);
3003 if (
isupper((
unsigned char) pat[0])) {
3004 pat += (char)
tolower((
unsigned char) pat[0]);
3005 }
else if (
islower((
unsigned char) pat[0])) {
3006 pat += (char)
toupper((
unsigned char) pat[0]);
3011 while (pos !=
NPOS && (pos + l) <=
end
3013 pos =
str.find_first_of(pat, pos + 1);
3015 return pos >
end ?
NPOS : pos;
3019 while (pos !=
NPOS && pos >= start
3024 pos =
str.find_last_of(pat, pos - 1);
3034 if (lst.empty())
return NULL;
3035 ITERATE (list<string>, st_itr, lst) {
3036 if (
Equal(*st_itr,
val, use_case)) {
3046 if (vec.empty())
return NULL;
3047 ITERATE (vector<string>, st_itr, vec) {
3048 if (
Equal(*st_itr,
val, use_case)) {
3061 return !(ch ==
'_' ||
isalnum((
unsigned char)ch));
3068 EDirection direction)
3078 while (pos !=
NPOS) {
3086 if (pos + plen == slen) {
3112 if (len1 == 0 || len2 == 0) {
3144 if (pos == 0 || memcmp(t1.
data() +
len -
n, t2.
data(),
n) == 0) {
3154 template <
class TStr>
3156 const TStr& empty_str)
3165 while (
isspace((
unsigned char)
str[beg]) ) {
3166 if (++beg == length) {
3174 while (
isspace((
unsigned char)
str[--end])) {
3182 _ASSERT(beg < end && end <= length);
3183 if ( beg | (end - length) ) {
3184 return str.substr(beg, end - beg);
3217 while (
isspace((
unsigned char)
str.data()[beg]) ) {
3218 if (++beg == length) {
3230 while (
isspace((
unsigned char)
str.data()[--end])) {
3239 _ASSERT(beg < end && end <= length);
3241 if ( beg | (end - length) ) {
3250 if (!
str.length() ||
3262 if (!
str.length() ||
3274 if (!
str.length() ||
3286 if (!
str.length() ||
3298 if (!
str.length() ||
3310 if (!
str.length() ||
3320 const string& search,
const string& replace,
3327 "NStr::Replace(): source and destination are the same", 0);
3331 if (start_pos + search.size() > src.size() || search == replace) {
3339 if (replace.size() > search.size() && src.size() > 16*1024) {
3345 for (
SIZE_TYPE count = 0; !(max_replace && count >= max_replace); count++){
3346 start_pos = src.find(search, start_pos);
3347 if (start_pos ==
NPOS)
3350 start_pos += search.size();
3353 dst.resize(src.size() -
n*search.size() +
n*replace.size());
3356 start_pos = start_orig;
3357 string::const_iterator src_start = src.begin();
3358 string::const_iterator src_end = src.begin();
3359 string::iterator dst_pos = dst.begin();
3361 for (
SIZE_TYPE count = 0; !(max_replace && count >= max_replace); count++){
3362 start_pos = src.find(search, start_pos);
3363 if (start_pos ==
NPOS)
3366 src_end = src.begin() + start_pos;
3367 copy(src_start, src_end, dst_pos);
3368 dst_pos += (src_end - src_start);
3370 copy(replace.begin(), replace.end(), dst_pos);
3371 dst_pos += replace.size();
3372 start_pos += search.size();
3373 src_start = src.begin() + start_pos;
3376 copy(src_start, src.end(), dst_pos);
3385 for (
SIZE_TYPE count = 0; !(max_replace && count >= max_replace); count++){
3386 start_pos = dst.find(search, start_pos);
3387 if (start_pos ==
NPOS)
3389 dst.replace(start_pos, search.size(), replace);
3390 start_pos += replace.size();
3400 const string& search,
const string& replace,
3405 Replace(src, search, replace, dst, start_pos, max_replace, num_replace);
3411 const string& search,
const string& replace,
3417 if ( start_pos + search.size() > src.size() || search == replace )
3420 bool equal_len = (search.size() == replace.size());
3421 for (
SIZE_TYPE count = 0; !(max_replace && count >= max_replace); count++){
3422 start_pos = src.find(search, start_pos);
3423 if (start_pos ==
NPOS)
3428 copy(replace.begin(), replace.end(), src.begin() + start_pos);
3430 src.replace(start_pos, search.size(), replace);
3432 start_pos += replace.size();
3440 template<
typename TString,
typename TContainer>
3441 TContainer&
s_Split(
const TString&
str,
const TString& delim,
3443 vector<SIZE_TYPE>* token_pos,
3451 TPosArray token_pos_proxy(token_pos);
3457 #define CHECK_SPLIT_TEMPSTRING_FLAGS(where) \
3459 if ((flags & (NStr::fSplit_CanEscape | NStr::fSplit_CanQuote)) && !storage) { \
3460 NCBI_THROW2(CStringException, eBadArgs, \
3461 "NStr::" #where "(): the selected flags require non-NULL storage", 0); \
3468 vector<SIZE_TYPE>* token_pos)
3474 vector<string>&
arr, TSplitFlags
flags,
3475 vector<SIZE_TYPE>* token_pos)
3481 list<CTempString>&
arr, TSplitFlags
flags,
3489 vector<CTempString>&
arr, TSplitFlags
flags,
3497 list<CTempStringEx>&
arr, TSplitFlags
flags,
3505 vector<CTempStringEx>&
arr, TSplitFlags
flags,
3513 list<string>&
arr, TSplitFlags
flags,
3514 vector<SIZE_TYPE>* token_pos)
3520 vector<string>&
arr, TSplitFlags
flags,
3521 vector<SIZE_TYPE>* token_pos)
3527 list<CTempString>&
arr, TSplitFlags
flags,
3535 vector<CTempString>&
arr, TSplitFlags
flags,
3543 list<CTempStringEx>&
arr, TSplitFlags
flags,
3551 vector<CTempStringEx>&
arr, TSplitFlags
flags,
3560 string& str1,
string& str2, TSplitFlags
flags)
3593 TSplitter splitter(
str, delim,
flags, storage);
3597 splitter.Advance(&part_collector,
NULL, &delim_pos);
3598 part_collector.
Join(&str1);
3599 part_collector.
Clear();
3603 splitter.Advance(&part_collector);
3604 part_collector.
Join(&str2);
3606 return delim_pos !=
NPOS;
3610 #define SS_ADD_CHAR(c) \
3622 if ( allow_chars.
empty() && reject_chars.
empty() && !have_class ) {
3627 bool have_allowed =
false;
3630 for (
char c :
str) {
3633 bool allowed =
false;
3660 if (!allowed && !allow_chars.
empty() && allow_chars.
find(c) !=
NPOS ) {
3663 if (allowed && !reject_chars.
empty() && reject_chars.
find(c) !=
NPOS ) {
3689 have_allowed =
true;
3699 if (reject_replacement ==
' ') {
3708 have_allowed =
true;
3712 if (
last != reject_replacement) {
3714 have_allowed =
true;
3745 unique_ptr<CNcbiOstrstream>
out;
3748 for (
i = 0;
i <
str.size(); ++
i) {
3787 if (
i &&
str[
i - 1] ==
'?')
3789 if (
i <
str.size() - 1 &&
str[
i + 1] ==
'?')
3794 if (!isascii((
unsigned char) c)) {
3800 if (!
isprint((
unsigned char) c)) {
3810 out->write(
str.data() + j,
i - j);
3814 out->write(
"n\\\n", 3);
3818 reduce = (
i ==
str.size() - 1 ||
3826 v = (
unsigned char) c >> 6;
3828 val[k++] = char(
'0' + v);
3831 v = ((
unsigned char) c >> 3) & 7;
3833 val[k++] = char(
'0' + v);
3835 v = (
unsigned char) c & 7;
3836 val[k++] = char(
'0' + v);
3845 out->write(
str.data() + j,
i - j);
3860 if (
str.empty() ) {
3863 out.reserve(
str.size() * 2);
3865 for (
char c :
str) {
3866 if (c == escape_char || metacharacters.
find(c) !=
NPOS) {
3878 if (
str.empty() ) {
3882 bool escaped =
false;
3884 for (
char c :
str) {
3890 if (c == escape_char) {
3908 out.reserve(
str.size() * 2);
3910 out.push_back(quote_char);
3911 for (
char c :
str) {
3912 if (c == quote_char || c == escape_char) {
3917 out.push_back(quote_char);
3930 bool escaped =
false;
3931 char quote_char =
str[0];
3933 if (
str.length() < 2 ||
str[
str.length()-1] != quote_char) {
3935 "The source string must start and finish with the same character", 0);
3946 if (c == escape_char) {
3995 const char quote_char =
'"';
3997 if (
len < 2 ||
str[0] != quote_char ||
str[
len-1] != quote_char) {
3999 "The source string must start and finish with a double quote", 0);
4003 bool escaped =
false;
4005 bool collect =
true;
4012 for (pos = 1; pos <
len; ++pos) {
4013 unsigned char ch =
str[pos];
4014 if (ch == quote_char && !escaped) {
4016 CTempString sub(
str.data() + last_quote + 1, pos - last_quote - 1);
4022 if (pos != last_quote + 1) {
4024 "Quoted string format error", pos);
4030 escaped = ch ==
'\\' ? !escaped :
false;
4033 if (escaped || last_quote !=
len-1) {
4035 "Unterminated quoted string",
str.length());
4050 for (
i = 0;
i <
str.size();
i++) {
4072 if (
i+1 ==
str.size()) {
4075 }
else if (
str[
i+1] ==
'-') {
4077 result.append(1, c).append(
"-");
4085 unsigned int uc = (
unsigned int)(c);
4092 if ((uc < 0x8) || (uc == 0xB) || (uc == 0xC) ||
4093 (uc >= 0x0E && uc <=0x1F) ||
4094 (uc >= 0x7F && uc <=0x84) ||
4095 (uc >= 0x86 && uc <=0x9F) )
4108 const char* charmap =
"0123456789abcdef";
4111 unsigned hi = ch >> 4;
4112 unsigned lo = ch & 0xF;
4114 result.append(1, charmap[hi]);
4116 result.append(1, charmap[lo]).append(1,
';');
4138 for (
const char* curr =
begin; curr <
end; ++curr ) {
4146 bool is_entity =
false;
4148 (
i+2 <
str.size()) && (semicolon !=
NPOS)) {
4150 if (
i >= semicolon ) {
4151 semicolon =
str.find(
";",
i+1);
4153 if ( semicolon !=
NPOS ) {
4156 if (
str[
i+1] ==
'#') {
4161 for (; p < semicolon; ++p) {
4171 for (; p < semicolon; ++p) {
4178 is_entity = (p == semicolon);
4184 "\" contains HTML encoded entities");
4204 if ((
unsigned int)c < 0x20) {
4205 const char* charmap =
"0123456789abcdef";
4208 unsigned hi = ch >> 4;
4209 unsigned lo = ch & 0xF;
4211 result.append(1, charmap[hi]);
4213 result.append(1, charmap[lo]).append(1,
';');
4214 }
else if (c > 0x7F) {
4423 { 977,
"thetasym" },
4457 { 8501,
"alefsym" },
4524 for ( ; p->
u != 0; ++p) {
4541 "Unable to guess the source string encoding", 0);
4545 ustr.reserve(
str.size());
4551 for (
i =
str.begin();
i != e;) {
4554 if (
i != e && ch ==
'&') {
4556 end_of_entity = itmp =
i;
4557 bool ent, dec,
hex, parsed=
false;
4558 ent =
isalpha((
unsigned char)(*itmp)) != 0;
4559 dec = !ent && *itmp ==
'#' && ++itmp != e &&
4560 isdigit((
unsigned char)(*itmp)) != 0;
4561 hex = !dec && itmp != e &&
4562 (*itmp ==
'x' || *itmp ==
'X') && ++itmp != e &&
4563 isxdigit((
unsigned char)(*itmp)) != 0;
4564 start_of_entity = itmp;
4566 if (itmp != e && (ent || dec ||
hex)) {
4568 for (
int len=0;
len<16 && itmp != e; ++
len, ++itmp) {
4569 if (*itmp ==
'&' || *itmp ==
'#') {
4573 end_of_entity = itmp;
4576 ent = ent &&
isalnum( (
unsigned char)(*itmp)) != 0;
4577 dec = dec &&
isdigit( (
unsigned char)(*itmp)) != 0;
4580 if (end_of_entity !=
i && (ent || dec ||
hex)) {
4583 string entity(start_of_entity, end_of_entity);
4585 for ( ; p->
u != 0; ++p) {
4586 if (entity.compare(p->
s) == 0) {
4596 for (itmp = start_of_entity; itmp != end_of_entity; ++itmp) {
4601 if (
ud >=
'0' &&
ud <=
'9') {
4603 }
else if (
ud >=
'a' &&
ud <=
'f') {
4606 }
else if (
ud >=
'A' &&
ud <=
'F') {
4616 i = ++end_of_entity;
4624 ustr.append( 1, ch );
4645 auto encode_char = [&](
char c)
4647 static const char* charmap =
"0123456789abcdef";
4650 unsigned hi = ch >> 4;
4651 unsigned lo = ch & 0xF;
4652 result.append(1, charmap[hi]);
4653 result.append(1, charmap[lo]);
4656 for (
auto c :
str) {
4665 if ((
unsigned int)c < 0x20) {
4679 return '"' +
result +
'"';
4721 str.find_first_of(
"!{} \t\r\n[|&;<>()$`\"'*?#~=%\\") ==
NPOS) {
4734 str.find_first_of(
"\"\\$`") ==
NPOS) {
4735 return "\"" +
str +
"\"";
4767 bool avoid_double_quotes = (
str.find(
'"') ==
NPOS ||
4770 avoid_double_quotes ?
"'\\''" :
"'\"'\"'") +
"'";
4784 pos =
s.find(
"''", pos);
4785 if (pos ==
NPOS)
break;
4786 if (pos == 0 ||
s[pos-1] !=
'\\') {
4803 bool is_error =
false;
4805 while (pos <
str.size() || !is_error) {
4816 if (++pos2 ==
str.size()) {
4818 "Unterminated escape sequence", pos2);
4820 switch (
str[pos2]) {
4821 case 'a':
out +=
'\a';
break;
4822 case 'b':
out +=
'\b';
break;
4823 case 'f':
out +=
'\f';
break;
4824 case 'n':
out +=
'\n';
break;
4825 case 'r':
out +=
'\r';
break;
4826 case 't':
out +=
'\t';
break;
4827 case 'v':
out +=
'\v';
break;
4831 while (pos <
str.size()
4842 unsigned int value =
4853 "' is out of range [0-255]", pos2);
4860 value = (unsigned)user_char;
4869 "\\x followed by no hexadecimal digits", pos);
4873 case '0':
case '1':
case '2':
case '3':
4874 case '4':
case '5':
case '6':
case '7':
4877 unsigned char c = (
unsigned char)(
str[pos++] -
'0');
4878 while (pos < pos2 + 3 && pos <
str.size()
4879 &&
str[pos] >=
'0' &&
str[pos] <=
'7') {
4880 c = (
unsigned char)((c << 3) | (
str[pos++] -
'0'));
4906 const char* str_pos =
str.data();
4909 if (
str.empty() || ((quote_char = *str_pos) !=
'"' && quote_char !=
'\'')) {
4911 "The source string must start with a quote", 0);
4914 const char* str_end = str_pos +
str.length();
4915 bool escaped =
false;
4917 while (++str_pos < str_end) {
4918 if (*str_pos == quote_char && !escaped) {
4919 size_t pos = str_pos -
str.data();
4924 escaped = *str_pos ==
'\\' ? !escaped :
false;
4928 "Unterminated quoted string",
str.length());
4945 while (pos <
str.size()) {
4956 if (++pos2 ==
str.size()) {
4958 "Unterminated escape sequence", pos2);
4960 switch (
str[pos2]) {
4963 case '/':
out +=
str[pos2];
break;
4964 case 'b':
out +=
'\b';
break;
4965 case 'f':
out +=
'\f';
break;
4966 case 'n':
out +=
'\n';
break;
4967 case 'r':
out +=
'\r';
break;
4968 case 't':
out +=
'\t';
break;
4974 if (
auto len = pos - pos2) {
4977 }
else if (
len > 4) {
4984 "Escaped UTF-8 characters after '\\u00ff' are not supported", pos2);
5011 bool comments_ok = (start + 1 <
str.size() &&
str[start + 1] ==
'!');
5012 for (
SIZE_TYPE pos = start + 1; pos <
str.size(); ++pos) {
5018 pos =
str.find(
'\"', pos + 1);
5021 "Unclosed string in HTML tag", start);
5027 if (comments_ok && pos + 1 <
str.size()
5028 &&
str[pos + 1] ==
'-') {
5029 pos =
str.find(
"--", pos + 2);
5032 "Unclosed comment in HTML tag", start);
5052 (
"#0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
5054 if (pos !=
NPOS &&
str[pos] ==
';') {
5070 width +=
str.size() - pos;
5073 width += pos2 - pos;
5074 if (
str[pos2] ==
'&') {
5091 inline bool _isspace(
unsigned char c)
5093 return ((c>=0x09 && c<=0x0D) || (c==0x20));
5096 template<
typename _D>
5098 _D& dest, TWrapFlags
flags,
5100 const string* prefix1)
5113 string temp_back; temp_back.reserve(width);
5126 typedef pair<SIZE_TYPE, SIZE_TYPE> TWrapSubstr;
5133 TWrapSubstr best_link(0, 0);
5134 TWrapSubstr latest_link(0, 0);
5137 bool hyphen =
false;
5142 EScore best_score = eForced;
5146 bool thisPartHasBackspace =
false;
5148 temp_back = *prefix1;
5151 if (is_html && best_link.second != 0) {
5153 str.begin() + best_link.first,
5154 str.begin() + best_link.second);
5162 if (nl_pos <= pos) {
5163 nl_pos =
str.find(
'\n', pos);
5164 if (nl_pos ==
NPOS) {
5168 if (
column + (nl_pos - pos) <= width) {
5175 EScore score = eForced;
5177 const char c =
str[pos2];
5181 best_score = eNewline;
5182 best_link = latest_link;
5185 else if (
_isspace((
unsigned char)c)) {
5186 if (!do_flat && pos2 > 0 &&
5188 if (pos2 <
len - 1 &&
str[pos2 + 1] ==
'\b') {
5189 thisPartHasBackspace =
true;
5195 else if (is_html && c ==
'<') {
5204 if ((pos2 - start_of_tag) >= 6 &&
5205 str[start_of_tag + 1] ==
'a' &&
5206 str[start_of_tag + 2] ==
' ' &&
5207 str[start_of_tag + 3] ==
'h' &&
5208 str[start_of_tag + 4] ==
'r' &&
5209 str[start_of_tag + 5] ==
'e' &&
5210 str[start_of_tag + 6] ==
'f')
5213 latest_link.first = start_of_tag;
5214 latest_link.second = pos2 + 1;
5216 if ((pos2 - start_of_tag) >= 3 &&
5217 str[start_of_tag + 1] ==
'/' &&
5218 str[start_of_tag + 2] ==
'a' &&
5219 str[start_of_tag + 3] ==
'>')
5222 latest_link.first = 0;
5223 latest_link.second = 0;
5226 else if (is_html && c ==
'&') {
5233 else if (c ==
',' &&
column < width && score_pos <
len - 1) {
5237 else if (do_flat ? c ==
'-' :
ispunct((
unsigned char)c)) {
5241 case '(':
case '[':
case '{':
case '<':
case '`':
5245 if (score_pos <
len - 1 &&
column < width) {
5253 if (score >= best_score && score_pos > pos0) {
5254 best_pos = score_pos;
5256 best_link = latest_link;
5259 while (pos2 <
len - 1 &&
str[pos2 + 1] ==
'\b') {
5265 thisPartHasBackspace =
true;
5269 if (best_score != eNewline &&
column <= width) {
5270 if (best_pos !=
len) {
5273 best_link = latest_link;
5275 thisPartHasBackspace =
true;
5284 string::const_iterator
begin =
str.begin() + pos;
5285 string::const_iterator
end =
str.begin() + best_pos;
5286 if (thisPartHasBackspace) {
5289 string::const_iterator bs;
5290 while ((bs = find(begin, end,
'\b')) != end) {
5293 temp_back.append(begin, bs - 1);
5299 if (
size > prefix1->size()) {
5300 temp_back.resize(
size - 1);
5309 temp_back.append(begin, end);
5315 if (is_html && best_link.second != 0) {
5316 temp_back +=
"</a>";
5326 if (best_score ==
eSpace) {
5327 while (
str[pos] ==
' ') {
5330 if (
str[pos] ==
'\n') {
5334 if (best_score == eNewline) {
5339 if (best_score ==
eSpace || best_score == eNewline) {
5343 while (pos <
len &&
str[pos] ==
'\b') {
5347 dest.Append(temp_back);
5353 IWrapDest& dest, TWrapFlags
flags,
5355 const string* prefix1)
5363 const string*
prefix,
const string* prefix1)
5365 CWrapDestStringList d(arr2);
5372 const string& delim, list<string>&
arr,
5375 const string* prefix1)
5381 const string* pfx = prefix1 ? prefix1 :
prefix;
5386 bool at_start =
true;
5388 ITERATE (list<string>, it, l) {
5391 if (
column + term_width <= width) {
5403 }
else if (
column + delwidth + term_width <= width) {
5406 column += delwidth + term_width;
5436 list<CTempString> words;
5437 unsigned int nw = 0;
5440 while (pos <
str.size()) {
5446 while (pos <
str.size()) {
5454 if (width <
len + nw + wlen) {
5456 if (width < wlen &&
len < width -
len)
5466 if (
str[pos - 1] ==
'.' ||
5467 str[pos - 1] ==
'!' ||
5468 str[pos - 1] ==
'?') {
5469 if (
len + 1 >= width)
5478 if (words.back().empty()) {
5485 if (pos <
str.size() &&
len < width && !big) {
5486 space = (width -
len) / (nw - 1);
5487 nw = (
unsigned int)((width -
len) % (nw - 1));
5496 ITERATE(list<CTempString>, w, words) {
5498 par.back().append(space + (
n <= nw ? 1 : 0) ,
' ');
5499 par.back().append(w->data(), w->size());
5513 #if !defined(NCBI_OS_MSWIN)
5515 vector<CTempString> lines;
5523 auto& line = lines[
i];
5534 while (
isspace((
unsigned char)line[pos])) {
5549 prefix.assign(line, 0, pos);
5559 auto& line = lines[
i];
5561 bool last_line = (
i == lines.size()-1);
5579 while (
isspace((
unsigned char)line[pos])) {
5606 #if !defined(HAVE_STRDUP)
5612 size_t size = strlen(
str) + 1;
5619 static const char s_Encode[256][4] = {
5620 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5621 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5622 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5623 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5624 "+",
"!",
"%22",
"%23",
"$",
"%25",
"%26",
"'",
5625 "(",
")",
"*",
"%2B",
",",
"-",
".",
"%2F",
5626 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5627 "8",
"9",
"%3A",
"%3B",
"%3C",
"%3D",
"%3E",
"%3F",
5628 "%40",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5629 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5630 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5631 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"_",
5632 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5633 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5634 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5635 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"%7E",
"%7F",
5636 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5637 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5638 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5639 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5640 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5641 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5642 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5643 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5644 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5645 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5646 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5647 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5648 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5649 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5650 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5651 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5655 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5656 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5657 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5658 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5659 "+",
"%21",
"%22",
"%23",
"%24",
"%25",
"%26",
"%27",
5660 "%28",
"%29",
"%2A",
"%2B",
"%2C",
"%2D",
"%2E",
"%2F",
5661 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5662 "8",
"9",
"%3A",
"%3B",
"%3C",
"%3D",
"%3E",
"%3F",
5663 "%40",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5664 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5665 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5666 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"%5F",
5667 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5668 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5669 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5670 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"%7E",
"%7F",
5671 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5672 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5673 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5674 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5675 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5676 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5677 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5678 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5679 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5680 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5681 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5682 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5683 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5684 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5685 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5686 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5690 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5691 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5692 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5693 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5694 "%20",
"%21",
"%22",
"%23",
"%24",
"%25",
"%26",
"%27",
5695 "%28",
"%29",
"%2A",
"%2B",
"%2C",
"%2D",
"%2E",
"%2F",
5696 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5697 "8",
"9",
"%3A",
"%3B",
"%3C",
"%3D",
"%3E",
"%3F",
5698 "%40",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5699 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5700 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5701 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"%5F",
5702 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5703 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5704 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5705 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"%7E",
"%7F",
5706 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5707 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5708 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5709 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5710 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5711 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5712 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5713 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5714 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5715 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5716 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5717 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5718 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5719 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5720 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5721 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5725 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5726 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5727 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5728 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5729 "+",
"%21",
"%22",
"%23",
"%24",
"%25",
"%26",
"%27",
5730 "%28",
"%29",
"%2A",
"%2B",
"%2C",
"%2D",
".",
"/",
5731 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5732 "8",
"9",
"%3A",
"%3B",
"%3C",
"%3D",
"%3E",
"%3F",
5733 "%40",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5734 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5735 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5736 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"_",
5737 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5738 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5739 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5740 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"%7E",
"%7F",
5741 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5742 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5743 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5744 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5745 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5746 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5747 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5748 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5749 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5750 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5751 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5752 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5753 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5754 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5755 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5756 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5762 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5763 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5764 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5765 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5766 "%20",
"%21",
"%22",
"%23",
"%24",
"%25",
"%26",
"%27",
5767 "%28",
"%29",
"%2A",
"+",
"%2C",
"-",
".",
"%2F",
5768 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5769 "8",
"9",
"%3A",
"%3B",
"%3C",
"%3D",
"%3E",
"%3F",
5770 "%40",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5771 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5772 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5773 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"%5F",
5774 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5775 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5776 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5777 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"%7E",
"%7F",
5778 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5779 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5780 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5781 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5782 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5783 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5784 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5785 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5786 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5787 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5788 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5789 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5790 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5791 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5792 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5793 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5803 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5804 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5805 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5806 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5807 "%20",
"!",
"%22",
"%23",
"$",
"%25",
"&",
"'",
5808 "(",
")",
"*",
"+",
",",
"-",
".",
"%2F",
5809 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5810 "8",
"9",
"%3A",
";",
"%3C",
"=",
"%3E",
"%3F",
5811 "%40",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5812 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5813 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5814 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"_",
5815 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5816 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5817 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5818 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"~",
"%7F",
5819 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5820 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5821 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5822 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5823 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5824 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5825 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5826 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5827 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5828 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5829 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5830 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5831 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5832 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5833 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5834 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5844 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5845 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5846 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5847 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5848 "%20",
"%21",
"%22",
"%23",
"%24",
"%25",
"%26",
"%27",
5849 "%28",
"%29",
"%2A",
"%2B",
"%2C",
"-",
".",
"%2F",
5850 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5851 "8",
"9",
"%3A",
"%3B",
"%3C",
"%3D",
"%3E",
"%3F",
5852 "%40",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5853 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5854 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5855 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"%5F",
5856 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5857 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5858 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5859 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"%7E",
"%7F",
5860 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5861 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5862 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5863 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5864 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5865 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5866 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5867 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5868 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5869 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5870 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5871 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5872 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5873 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5874 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5875 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5887 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5888 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5889 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5890 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5891 "%20",
"!",
"%22",
"%23",
"$",
"%25",
"&",
"'",
5892 "(",
")",
"*",
"+",
",",
"-",
".",
"/",
5893 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5894 "8",
"9",
":",
";",
"%3C",
"=",
"%3E",
"%3F",
5895 "@",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5896 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5897 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5898 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"_",
5899 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5900 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5901 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5902 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"~",
"%7F",
5903 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5904 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5905 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5906 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5907 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5908 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5909 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5910 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5911 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5912 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5913 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5914 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5915 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5916 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5917 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5918 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5922 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5923 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5924 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5925 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5926 "%20",
"!",
"%22",
"%23",
"$",
"%25",
"%26",
"'",
5927 "(",
")",
"%2A",
"%2B",
"%2C",
"-",
".",
"/",
5928 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5929 "8",
"9",
":",
"%3B",
"%3C",
"%3D",
"%3E",
"?",
5930 "@",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5931 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5932 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5933 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"_",
5934 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5935 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5936 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5937 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"~",
"%7F",
5938 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5939 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5940 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5941 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5942 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5943 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5944 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5945 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5946 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5947 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5948 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5949 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5950 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5951 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5952 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5953 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5957 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5958 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
5959 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
5960 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
5961 "%20",
"!",
"%22",
"%23",
"$",
"%25",
"%26",
"'",
5962 "(",
")",
"%2A",
"%2B",
"%2C",
"-",
".",
"/",
5963 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
5964 "8",
"9",
":",
"%3B",
"%3C",
"%3D",
"%3E",
"?",
5965 "@",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
5966 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
5967 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
5968 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"_",
5969 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
5970 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
5971 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
5972 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"~",
"%7F",
5973 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
5974 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
5975 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
5976 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
5977 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
5978 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
5979 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
5980 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
5981 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
5982 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
5983 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
5984 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
5985 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
5986 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
5987 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
5988 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
5998 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
5999 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
6000 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
6001 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
6002 "%20",
"!",
"%22",
"%23",
"$",
"%25",
"&",
"'",
6003 "(",
")",
"*",
"+",
",",
"-",
".",
"/",
6004 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
6005 "8",
"9",
":",
";",
"%3C",
"=",
"%3E",
"?",
6006 "@",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
6007 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
6008 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
6009 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"_",
6010 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
6011 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
6012 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
6013 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"~",
"%7F",
6014 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
6015 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
6016 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
6017 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
6018 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
6019 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
6020 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
6021 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
6022 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
6023 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
6024 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
6025 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
6026 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
6027 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
6028 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
6029 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
6033 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
6034 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
6035 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
6036 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
6037 "+",
"!",
"%22",
"%23",
"$",
"%25",
"%26",
"'",
6038 "(",
")",
"*",
"%2B",
"%2C",
"-",
".",
"%2F",
6039 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
6040 "8",
"9",
"%3A",
"%3B",
"%3C",
"%3D",
"%3E",
"%3F",
6041 "%40",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
6042 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
6043 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
6044 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"_",
6045 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
6046 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
6047 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
6048 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"%7E",
"%7F",
6049 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
6050 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
6051 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
6052 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
6053 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
6054 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
6055 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
6056 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
6057 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
6058 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
6059 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
6060 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
6061 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
6062 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
6063 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
6064 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
6073 const char (*encode_table)[4];
6122 const unsigned char* cstr = (
const unsigned char*)
str.data();
6123 for (pos = 0; pos <
len; pos++) {
6124 if (encode_table[cstr[pos]][0] ==
'%')
6127 dst.resize(dst_len);
6130 for (pos = 0; pos <
len; pos++, p++) {
6131 const char* subst = encode_table[cstr[pos]];
6132 if (*subst !=
'%') {
6136 dst[++p] = *(++subst);
6137 dst[++p] = *(++subst);
6150 result.reserve(stringSize + 7);
6160 }
else if (
offset > 0 && (c & 0x80) != 0) {
6179 if (dst.length() < src.
length()) {
6185 switch ( src[psrc] ) {
6190 if (psrc + 2 >
len) {
6191 dst[pdst] = src[psrc++];
6195 if (n1 < 0 || n1 > 15 || n2 < 0 || n2 > 15) {
6196 dst[pdst] = src[psrc++];
6198 dst[pdst] = char((n1 << 4) | n2);
6210 dst[pdst] = src[psrc++];
6239 const char (*encode_table)[4];
6263 const unsigned char* cstr = (
const unsigned char*)
str.data();
6266 const char* subst = encode_table[cstr[pos]];
6267 if (*subst != cstr[pos]) {
6277 size_t n =
str.size();
6280 size_t pos = 0, n_read, n_written;
6283 BASE64_Encode(
str.data() + pos,
n, &n_read, dst_buf,
sizeof(dst_buf), &n_written, &line_len);
6286 dst.append(dst_buf, n_written);
6293 size_t n =
str.size();
6296 size_t pos = 0, n_read, n_written;
6299 if (!
BASE64_Decode(
str.data() + pos,
n, &n_read, dst_buf,
sizeof(dst_buf), &n_written)) {
6304 dst.append(dst_buf, n_written);
6317 const char* c =
str;
6320 if ( strchr(
str,
':') ) {
6327 bool have_group =
false;
6328 const char* prev_colon =
NULL;
6331 for (; c && c -
str < (
int)
size && *c !=
'%'; c++) {
6338 if (prev_colon && c - prev_colon == 1) {
6355 char d = (char)
toupper((
unsigned char)(*c));
6356 if (d < '0' || d >
'F') {
6373 int& errno_ref = errno;
6376 if ( !
isdigit((
unsigned char)(*c)) )
6379 val = strtoul(c, &e, 10);
6380 if (c == e || errno_ref)
6394 if ((
size_t)(c -
str) !=
size) {
6397 return !*c && dots == 3 &&
val < 256;
6404 if (
str.HasZeroAtEnd() ) {
6423 template <
typename TDelimiter>
6430 PDelimiter(
const TDelimiter& delim)
6434 bool operator()(
char tested_symbol)
const;
6449 template <
typename TComparator,
typename TResult>
6455 const char* current_ptr =
str.data();
6456 const char* end_ptr = current_ptr +
str.length();
6457 size_t current_field = 0;
6460 for ( ; current_field != field_no; current_field++) {
6461 while (current_ptr < end_ptr && !
delimiter(*current_ptr))
6465 while (current_ptr < end_ptr &&
delimiter(*current_ptr))
6471 if (current_ptr >= end_ptr)
6475 if (current_field != field_no)
6479 const char* field_start = current_ptr;
6480 while (current_ptr < end_ptr && !
delimiter(*current_ptr))
6483 return TResult(field_start, current_ptr - field_start);
6489 bool PDelimiter<char>::operator() (
char c)
const
6495 bool PDelimiter<CTempString>::operator() (
char c)
const
6507 return s_GetField<PDelimiter<CTempString>,
string>
6510 PDelimiter<CTempString>(delimiters),
6520 return s_GetField<PDelimiter<char>,
string>
6533 return s_GetField<PDelimiter<CTempString>,
CTempString>
6536 PDelimiter<CTempString>(delimiters),
6566 "NStr::StringToNumeric overflow", 0);
6574 #if defined(__EXPORT_CTOR_STRINGUTF8__)
6602 #if NCBITOOLKIT_USE_LONG_UCS4
6610 #if defined(HAVE_WSTRING)
6618 #if NCBITOOLKIT_USE_LONG_UCS4
6626 #if defined(HAVE_WSTRING)
6636 #if NCBITOOLKIT_USE_LONG_UCS4
6658 for (; src != to; ++src, ++count) {
6661 while (more-- && good) {
6675 if (err == src.
end()) {
6687 if (err !=
str.end()) {
6689 string(
"Source string is not in UTF8 format: ") +
6701 bool cp1252, iso1, ascii,
utf8, cesu8;
6702 for (cp1252 = iso1 = ascii =
utf8 =
true, cesu8=
false;
i !=
end; ++
i) {
6725 if (ch == 0x81 || ch == 0x8D || ch == 0x8F ||
6726 ch == 0x90 || ch == 0x9D) {
6733 if (
utf8 && !cesu8 && ch == 0xED && (end -
i) > 5) {
6737 if ( ((c1 & 0xA0) == 0xA0) && (c3 == (
uint8_t)0xED) && ((c4 & 0xB0) == 0xB0) ) {
6750 }
else if (cp1252) {
6759 bool matches =
false;
6761 switch ( enc_src ) {
6774 matches = (encoding == enc_src);
6793 "Cannot convert encoding to string", 0);
6809 const char* ascii[] = {
6810 "ANSI_X3.4-1968",
"iso-ir-6",
"ANSI_X3.4-1986",
"ISO_646.irv:1991",
6811 "ASCII",
"ISO646-US",
"US-ASCII",
"us",
"IBM367",
"cp367",
"csASCII",
NULL};
6812 for (
i=0; ascii[
i]; ++
i) {
6817 const char* iso8859_1[] = {
6818 "ISO_8859-1:1987",
"iso-ir-100",
"ISO_8859-1",
"ISO-8859-1",
6819 "latin1",
"l1",
"IBM819",
"CP819",
"csISOLatin1",
NULL};
6820 for (
i=0; iso8859_1[
i]; ++
i) {
6825 const char* cesu[] = {
6826 "CESU-8",
"csCESU8",
"csCESU-8",
NULL};
6827 for (
i=0; cesu[
i]; ++
i) {
6838 0x20AC, 0x003F, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
6839 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x003F, 0x017D, 0x003F,
6840 0x003F, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
6841 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x003F, 0x017E, 0x0178
6853 "Unacceptable character encoding", 0);
6858 if (ch > 0x7F && ch < 0xA0) {
6864 "Unsupported character encoding", 0);
6873 "Unacceptable character encoding", 0);
6879 for (
Uint1 ch = 0x80; ch <= 0x9F; ++ch) {
6887 "Failed to convert symbol to requested encoding", 0);
6910 #if defined(HAVE_WSTRING)
6915 ,
m_Facet(use_facet< ctype<wchar_t> >(lcl)) {
6918 wchar_t w =
m_Facet.widen(ch);
6919 if (w == (
wchar_t)-1) {
6920 string msg(
"Failed to convert to Unicode char ");
6927 char ch =
m_Facet.narrow(sym,0);
6928 if (ch == 0 && sym != 0) {
6929 string msg(
"Failed to convert Unicode symbol ");
6936 const ctype<wchar_t>&
m_Facet;
6954 for (
char ch : src) {
6957 self.reserve(needed+1);
6958 for (
char ch : src) {
6966 const SCharEncoder& enc,
const char* substitute_on_error)
6972 for ( ; src != to; ++src ) {
6974 if (substitute_on_error) {
6979 result.append(substitute_on_error);
6999 "Conversion into CESU-8 encoding is not supported", 0);
7004 #if defined(HAVE_WSTRING)
7006 const locale& lcl,
const char* substitute_on_error, EValidate
validate)
7019 string(
"Source string is not in UTF8 format: ") +
7029 self.append(1,
Uint1(ch));
7031 else if (ch < 0x800) {
7032 self.append(1,
Uint1( (ch >> 6) | 0xC0));
7033 self.append(1,
Uint1( (ch & 0x3F) | 0x80));
7034 }
else if (ch < 0x10000) {
7035 self.append(1,
Uint1( (ch >> 12) | 0xE0));
7036 self.append(1,
Uint1(((ch >> 6) & 0x3F) | 0x80));
7037 self.append(1,
Uint1(( ch & 0x3F) | 0x80));
7039 self.append(1,
Uint1( (ch >> 18) | 0xF0));
7040 self.append(1,
Uint1(((ch >> 12) & 0x3F) | 0x80));
7041 self.append(1,
Uint1(((ch >> 6) & 0x3F) | 0x80));
7042 self.append(1,
Uint1( (ch & 0x3F) | 0x80));
7054 "Unable to guess the source string encoding", 0);
7059 "Source string does not match the declared encoding", 0);
7067 self.reserve(
max(
self.capacity(),
self.length()+src.
length()));
7068 const char*
i = src.
data();
7070 for (;
i !=
end; ++
i) {
7072 if (ch == 0xED && (end -
i) > 5) {
7076 if ( ((c1 & 0xA0) == 0xA0) && (c3 == (
uint8_t)0xED) && ((c4 & 0xB0) == 0xB0) ) {
7090 for (
i = src.
begin();
i != end; ++
i) {
7096 self.reserve(
max(
self.capacity(),
self.length()+needed+1));
7097 for (
i = src.
begin();
i != end; ++
i) {
7108 }
else if (ch < 0x800) {
7110 }
else if (ch < 0x10000) {
7122 while (more-- && good) {
7125 return good ? (src -
str.begin() + 1) : 0;
7131 if ((ch & 0x80) != 0) {
7132 if ((ch & 0xE0) == 0xC0) {
7133 if ((ch & 0xFE) == 0xC0) {
7138 }
else if ((ch & 0xF0) == 0xE0) {
7140 }
else if ((ch & 0xF8) == 0xF0) {
7141 if ((
unsigned char)ch > (
unsigned char)0xF4) {
7156 return (ch & 0xC0) == 0x80;
7163 if ((ch & 0x80) == 0) {
7165 }
else if ((ch & 0xE0) == 0xC0) {
7166 chRes = (ch & 0x1F);
7168 }
else if ((ch & 0xF0) == 0xE0) {
7169 chRes = (ch & 0x0F);
7171 }
else if ((ch & 0xF8) == 0xF0) {
7172 chRes = (ch & 0x07);
7176 "Source string is not in UTF8 format", 0);
7184 if ((ch & 0xC0) == 0x80) {
7185 return (chU << 6) | (ch & 0x3F);
7188 "Source string is not in UTF8 format", 0);
7202 return chU == 0x85 || chU == 0xA0 || chU == 0x1680 || chU == 0x180E;
7203 }
else if (chU >= 0x3000) {
7204 return chU == 0x3000;
7206 return chU <=0x200A || chU == 0x2028 || chU == 0x2029 || chU == 0x202F || chU == 0x205F;
7208 return iswspace(chU)!=0;
7218 str.replace(0,
str.length(),
t.data(),
t.length());
7240 while (end != beg) {
7241 while (end != beg) {
7243 if ((ch & 0x80) == 0 || (ch & 0xC0) == 0xC0) {
7266 case eFormat:
return "eFormat";
7355 node = node->next.get()) {
7356 s->append(node->str.data(), node->str.size());
7376 "CTempStringList::Join(): non-NULL storage required", 0);
7382 node = node->next.get()) {
7383 memcpy(p, node->str.data(), node->str.size());
7384 p += node->str.size();
7396 node = node->next.get()) {
7397 total += node->str.size();
7426 SIZE_TYPE pos, part_start, delim_pos = 0, quote_pos = 0;
7427 bool found_text =
false,
done;
7428 char active_quote =
'\0';
7435 pos = part_start =
m_Pos;
7438 if (ptr_part_start) {
7439 *ptr_part_start = part_start;
7447 if (ptr_delim_pos) {
7448 *ptr_delim_pos =
NPOS;
7456 SIZE_TYPE next_start = pos = delim_pos + 1;
7457 bool handled =
false;
7458 char c =
m_Str[delim_pos];
7468 if (active_quote !=
'\0') {
7469 if (c == active_quote) {
7474 active_quote =
'\0';
7483 quote_pos = delim_pos;
7502 if (ptr_delim_pos) {
7503 *ptr_delim_pos = delim_pos;
7507 if (delim_pos > part_start) {
7509 if (part_collector !=
NULL) {
7510 part_collector->
Add(
m_Str.
substr(part_start, delim_pos - part_start));
7513 part_start = next_start;
7516 if (active_quote !=
'\0') {
7520 if (delim_pos ==
NPOS) {
7522 if (part_collector !=
NULL) {
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
CS2N_Guard(NStr::TStringToNumFlags, bool skip_if_zero)
string Message(const CTempString str, const char *to_type, const CTempString msg)
Adapter for token position container pointer(NULL legal) Makes pointer to a container look as a legal...
Main tokenization algorithm.
@ eCharBuffer
Zeros are part of the data.
CStringUTF8_DEPRECATED(void)
Singly-linked list of substrings that will constitute a single Split/Tokenize piece,...
Helper class to allocate memory for CTempString[Ex] on demand in the functions which need to modify t...
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
The NCBI C++ standard methods for dealing with std::string.
constexpr auto begin(const ct_const_array< T, N > &in) noexcept
constexpr auto end(const ct_const_array< T, N > &in) noexcept
static vector< string > arr
std::ofstream out("events_result.xml")
main entry point for tests
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static const char * str(char *buf, int n)
static const char * column
static const char * validate(DSNINFO *di)
Go looking for trouble.
char * strdup(const char *str)
Supply string duplicate function, if one is not defined.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
element_type * get(void) const
Get pointer.
#define ERR_POST_X_ONCE(err_subcode, message)
Error posting only once during program execution with default error code and given error subcode.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
void Warning(CExceptionArgs_Base &args)
#define NCBI_THROW2(exception_class, err_code, message, extra)
Throw exception with extra parameter.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
static void SetErrno(int errno_code)
Set last error using errno code.
void Info(CExceptionArgs_Base &args)
#define finite
Define value of finite (Is Finite).
#define NCBI_CONST_LONGDOUBLE(v)
uint8_t Uint1
1-byte (8-bit) unsigned integer
unsigned char Uchar
Alias for unsigned char.
uint32_t Uint4
4-byte (32-bit) unsigned integer
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define NCBI_AS_STRING(value)
Convert some value to string even if this value is macro itself.
char * Allocate(CTempString::size_type len)
static EEncoding StringToEncoding(const CTempString &encoding_name)
Convert encoding name into EEncoding enum, taking into account synonyms as per http://www....
static list< string > & SplitByPattern(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Variation of Split() with fSplit_ByPattern flag applied by default.
static bool IsWhiteSpace(TUnicodeSymbol sym)
Determines if a symbol is whitespace per http://unicode.org/charts/uca/chart_Whitespace....
static bool StringToBool(const CTempString str)
Convert string to bool.
CTempStringEx m_InternalDelim
static string HtmlDecode(const CTempString str, EEncoding encoding=eEncoding_Unknown, THtmlDecode *result_flags=NULL)
Decode HTML entities and character references.
static void x_Validate(const CTempString &str)
NCBI_NS_STD::string::size_type SIZE_TYPE
static bool x_EvalFirst(char ch, SIZE_TYPE &more)
static string SizetToString(size_t value, TNumToStringFlags flags=0, int base=10)
Convert size_t to string.
virtual string Encode(const CTempString src, EStringType stype) const
const_iterator end() const
Return an iterator to the string's ending position (one past the end of the represented sequence)
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
static string PrintableString(const CTempString str, TPrintableMode mode=fNewLine_Quote|fNonAscii_Passthru)
Get a printable version of the specified string.
CStringDecoder_Url(NStr::EUrlDecode flag=NStr::eUrlDec_All)
static CStringUTF8 & x_Append(CStringUTF8 &u8str, const CTempString &src, EEncoding encoding, EValidate validate)
static CTempString TruncateSpaces_Unsafe(const CTempString str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
static string DoubleToString(double value, int precision=-1, TNumToStringFlags flags=0)
Convert double to string.
static int StringToNonNegativeInt(const CTempString str, TStringToNumFlags flags=0)
Convert string to non-negative integer value.
~CTempString_Storage(void)
static CTempString GetField_Unsafe(const CTempString str, size_t field_no, const CTempString delimiters, EMergeDelims merge=eNoMergeDelims)
Search for a field.
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
EUrlEncode
URL-encode flags.
EMergeDelims
Whether to merge adjacent delimiters.
static string AsSingleByteString(const CTempString &src, EEncoding encoding, const char *substitute_on_error=0, EValidate validate=eNoValidate)
Convert UTF8 string into a single-byte character representation.
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
static SIZE_TYPE CommonOverlapSize(const CTempString s1, const CTempString s2)
Determine if the suffix of one string is the prefix of another.
const CTempString & m_Str
static bool x_EvalNext(char ch)
int TPrintableMode
Bitwise OR of EPrintableMode flags.
static bool MatchEncoding(const CTempString &src, EEncoding encoding)
Check the encoding of the C/C++ string.
static Int8 StringToInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Int8.
int TNumToStringFlags
Bitwise OR of "ENumToStringFlags".
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static string Base64Encode(const CTempString str, size_t line_len=0)
Base64-encode string.
static string GetField(const CTempString str, size_t field_no, const CTempString delimiters, EMergeDelims merge=eNoMergeDelims)
Search for a field.
EUrlDecode
URL decode flags.
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
static string Escape(const CTempString str, const CTempString metacharacters, char escape_char='\\')
Escape string (generic version).
static bool IsLower(const CTempString str)
Checks if all letters in the given string have a lower case.
static CTempString TruncateSpaces_Unsafe(const CTempString &str, NStr::ETrunc side=NStr::eTrunc_Both)
Truncate spaces in the string.
static string HtmlEntity(TUnicodeSymbol uch)
Returns HTML entity name for this symbol if one exists (without leading ampersand and trailing semico...
static bool MatchesMask(CTempString str, CTempString mask, ECase use_case=eCase)
Match "str" against the "mask".
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
static SIZE_TYPE x_BytesNeeded(TUnicodeSymbol ch)
static CStringUTF8 SQLEncode(const CStringUTF8 &str, ESqlEncode flag)
SQL-encode string.
static string LongToString(long value, TNumToStringFlags flags=0, int base=10)
Convert Int to string.
unique_ptr< string > m_Encoded
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
static double StringToDoubleEx(const char *str, size_t size, TStringToNumFlags flags=0)
This version accepts zero-terminated string.
void x_ExtendInternalDelim()
static double StringToDouble(const CTempStringEx str, TStringToNumFlags flags=0)
Convert string to double.
static string HtmlEncode(const CTempString str, THtmlEncode flags=fHtmlEnc_EncodeAll)
Encode a string for HTML.
static Uint8 StringToUInt8_DataSize(const CTempString str, TStringToNumFlags flags=0)
Convert string that can contain "software" qualifiers to Uint8.
static SIZE_TYPE GetSymbolCount(const CTempString &src)
Get the number of symbols (code points) in UTF8 string.
static int strncasecmp(const char *s1, const char *s2, size_t n)
Case-insensitive comparison of two zero-terminated strings, narrowed to the specified number of chara...
static size_t StringToSizet(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to size_t.
Uint4 TUnicodeSymbol
Unicode character.
CTempString & assign(const char *src_str, size_type len)
Assign new values to the content of the a string.
static CTempString x_GetErrorFragment(const CTempString &src)
static string URLDecode(const CTempString str, EUrlDecode flag=eUrlDec_All)
URL-decode string.
static CTempString TrimSuffix_Unsafe(const CTempString str, const CTempString suffix, ECase use_case=eCase)
Trim suffix from a string.
static const string BoolToString(bool value)
Convert bool to string.
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static SIZE_TYPE DoubleToStringPosix(double value, unsigned int precision, char *buf, SIZE_TYPE buf_size)
Convert double to string with specified precision and put the result into a character buffer,...
void x_SkipDelims(bool force_skip)
static EEncoding GuessEncoding(const CTempString &src)
Guess the encoding of the C/C++ string.
static string Dedent(const CTempString str, TDedentFlags flags=0)
Dedent multi-line string, removing common whitespace prefix for each line.
virtual string Decode(const CTempString src, EStringType stype) const
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
PNocase_Generic< string > PNocase
static unsigned long StringToULong(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned long.
const char * const_iterator
static int HexChar(char ch)
Convert character to integer.
size_t GetSize(void) const
static string EncodingToString(EEncoding encoding)
Give Encoding name as string.
int TSplitFlags
Bitwise OR of ESplitFlags.
ETrunc
Which end to truncate a string.
static string ParseEscapes(const CTempString str, EEscSeqRange mode=eEscSeqRange_Standard, char user_char='?')
Parse C-style escape sequences in the specified string.
static void PtrToString(string &out_str, const void *ptr)
Convert pointer to string.
static string Quote(const CTempString str, char quote_char='"', char escape_char = '\\')
Quote string (generic version).
const char * data(void) const
Return a pointer to the array represented.
static string UInt8ToString_DataSize(Uint8 value, TNumToStringFlags flags=0, unsigned int max_digits=3)
Convert UInt8 to string using "software" qualifiers.
basic_string< TUnicodeSymbol > TStringUnicode
Unicode string.
static double StringToDoublePosix(const char *str, char **endptr=0, TStringToNumFlags flags=0)
Convert string to double-precision value (analog of strtod function)
const wchar_t *const kEmptyWCStr
static SIZE_TYPE FindWord(const CTempString str, const CTempString word, ECase use_case=eCase, EDirection direction=eForwardSearch)
Find given word in the string.
static TUnicodeSymbol DecodeFirst(char ch, SIZE_TYPE &more)
Begin converting first character of UTF8 sequence into Unicode.
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
static CTempString TrimPrefix_Unsafe(const CTempString str, const CTempString prefix, ECase use_case=eCase)
Trim prefix from a string.
TStringUnicode TStringUCS4
static string JsonDecode(const CTempString str, size_t *n_read=NULL)
Decode a string encoded by JsonEncode.
bool AStrEquiv(const Arg1 &x, const Arg2 &y, Pred pr)
Check equivalence of arguments using predicate.
static SIZE_TYPE EvaluateSymbolLength(const CTempString &src)
Check buffer for presence of UTF-8 byte sequence and return length of first symbol.
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Uint2 TCharUCS2
Type for character in UCS-2 encoding.
static char SymbolToChar(TUnicodeSymbol sym, EEncoding encoding)
Convert Unicode code point into encoded character.
static CStringUTF8 & x_AppendChar(CStringUTF8 &u8str, TUnicodeSymbol ch)
static long StringToLong(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to long.
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
basic_string< TCharUCS2 > TStringUCS2
Type for string in UCS-2 encoding.
static string Unescape(const CTempString str, char escape_char='\\')
Unescape string (generic version).
static list< string > & WrapList(const list< string > &l, SIZE_TYPE width, const string &delim, list< string > &arr, TWrapFlags flags=0, const string *prefix=0, const string *prefix1=0)
Wrap the list using the specified criteria.
static CStringUTF8 & TruncateSpacesInPlace(CStringUTF8 &str, NStr::ETrunc side=NStr::eTrunc_Both)
Truncate spaces in the string (in-place)
bool Advance(CTempStringList *part_collector)
Return TRUE if it found some text and put it into collector.
static string CParse(const CTempString str, EQuoted quoted=eQuoted)
Discard C-style backslash escapes.
static string XmlEncode(const CTempString str, TXmlEncode flags=eXmlEnc_Contents)
Encode a string for XML.
static string Unquote(const CTempString str, char escape_char='\\')
Unquote string (generic version).
static SIZE_TYPE x_GetValidSymbolCount(const CTempString &src, CTempString::const_iterator &err)
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
static string JavaScriptEncode(const CTempString str)
Encode a string for JavaScript.
static void WrapIt(const string &str, SIZE_TYPE width, _D &dest, TWrapFlags flags=0, const string *prefix=0, const string *prefix1=0)
Wrap the specified string into lines of a specified width.
static TUnicodeSymbol DecodeNext(TUnicodeSymbol chU, char ch)
Convert next character of UTF8 sequence into Unicode.
void MergeDelims(void)
Assumes that we already have a delimiter on the previous position, so just skip all subsequent,...
static void TrimSuffixInPlace(string &str, const CTempString suffix, ECase use_case=eCase)
Trim suffix from a string (in-place)
static Uint8 StringToUInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Uint8.
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
size_type length(void) const
Return the length of the represented array.
static bool x_ReportLimitsError(const CTempString str, TStringToNumFlags flags)
static string ULongToString(unsigned long value, TNumToStringFlags flags=0, int base=10)
Convert unsigned long to string.
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
int TSS_Flags
Bitwise OR of ESS_Flags.
static TUnicodeSymbol CharToSymbol(char ch, EEncoding encoding)
Convert encoded character into Unicode.
static string Base64Decode(const CTempString str)
Base64-decode string.
static list< string > & Justify(const CTempString str, SIZE_TYPE width, list< string > &par, const CTempString *pfx=0, const CTempString *pfx1=0)
Justify the specified string into a series of lines of the same width.
CTempString_Storage * m_Storage
static const void * StringToPtr(const CTempStringEx str, TStringToNumFlags flags=0)
Convert string to pointer.
void Join(string *s) const
static string Sanitize(CTempString str, TSS_Flags flags=fSS_print)
Sanitize a string, allowing only specified classes of characters.
CTempString substr(size_type pos) const
Obtain a substring from this string, beginning at a given offset.
void Add(const CTempString &s)
static bool NeedsURLEncoding(const CTempString str, EUrlEncode flag=eUrlEnc_SkipMarkChars)
Check if the string needs the requested URL-encoding.
static string JsonEncode(const CTempString str, EJsonEncode encoding=eJsonEnc_UTF8)
Encode a string for JSON.
static bool IsIPAddress(const CTempStringEx str)
Check if the string contains a valid IP address.
static TUnicodeSymbol Decode(const char *&src)
Convert sequence of UTF8 code units into Unicode code point.
size_type find_first_not_of(const CTempString match, size_type pos=0) const
Find the first occurrence of any character not in the matching string within the current string,...
static void TrimPrefixInPlace(string &str, const CTempString prefix, ECase use_case=eCase)
Trim prefix from a string (in-place)
ECase
Which type of string comparison.
TErrCode GetErrCode(void) const
Get error code.
void SetString(const CTempString s, NStr::EUrlEncode flag=NStr::eUrlEnc_SkipMarkChars)
Set new original string.
int TWrapFlags
Bitwise OR of "EWrapFlags".
int TStringToNumFlags
Bitwise OR of "EStringToNumFlags".
CTempString_Storage(void)
static bool IsUpper(const CTempString str)
Checks if all letters in the given string have a upper case.
size_type find_first_of(const CTempString match, size_type pos=0) const
Find the first occurrence of any character in the matching string within the current string,...
static SIZE_TYPE GetValidBytesCount(const CTempString &src)
Get the number of valid UTF-8 bytes (code units) in buffer.
static string FormatVarargs(const char *format, va_list args)
Handle an arbitrary printf-style format string.
static void Wrap(const string &str, SIZE_TYPE width, IWrapDest &dest, TWrapFlags flags, const string *prefix, const string *prefix1)
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
size_type find(const CTempString match, size_type pos=0) const
Find the first instance of the entire matching string within the current string, beginning at an opti...
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
static void URLDecodeInPlace(string &str, EUrlDecode flag=eUrlDec_All)
URL-decode string to itself.
static string CEncode(const CTempString str, EQuoted quoted=eQuoted)
Encode a string for C/C++.
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
static string & ToUpper(string &str)
Convert string to upper case – string& version.
void SkipDelims(void)
Skip all delimiters starting from current position.
static string URLEncode(const CTempString str, EUrlEncode flag=eUrlEnc_SkipMarkChars)
URL-encode string.
static enable_if< is_integral< TChar >::value &&(1< sizeof(TChar)), CStringUTF8 & >::type AppendAsUTF8(CStringUTF8 &dest, const basic_string< TChar > &src)
Convert Unicode C++ string into UTF8 and append it to existing string.
static string ShellEncode(const string &str)
Quotes a string in Bourne Again Shell (BASH) syntax, in a way that disallows non-printable characters...
CTempStringEx & assign(const char *str, size_type len)
Assign new values to the content of the a string.
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
CTempString_Storage m_DelimStorage
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
CStringEncoder_Url(NStr::EUrlEncode flag=NStr::eUrlEnc_SkipMarkChars)
size_type size(void) const
Return the length of the represented array.
static SIZE_TYPE DoubleToString_Ecvt(double value, unsigned int precision, char *buf, SIZE_TYPE buf_size, int *dec, int *sign)
Convert double to string with specified precision.
static string & ToLower(string &str)
Convert string to lower case – string& version.
static int CompareCase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-sensitive compare of a substring with another string.
static string UInt8ToString(Uint8 value, TNumToStringFlags flags=0, int base=10)
Convert UInt8 to string.
const_iterator begin() const
Return an iterator to the string's starting position.
static string ParseQuoted(const CTempString str, size_t *n_read=NULL)
Discard C-style backslash escapes and extract a quoted string.
@ eJsonEnc_UTF8
Encode all characters above 0x80 to \uXXXX form.
@ eJsonEnc_Quoted
Quote resulting string.
@ eEncoding_ISO8859_1
Note: From the point of view of the C++.
@ fNonAscii_Passthru
Allow non-ASCII but printable characters.
@ fPrintable_Full
Show all octal digits at all times.
@ fNonAscii_Quote
Octal for all non-ASCII characters.
@ fNewLine_Passthru
Break the line at every "\n" occurrence.
@ fNewLine_Quote
Display "\n" instead of actual linebreak.
@ fDedent_NormalizeEmptyLines
Each line containing only whitespaces will be normalized to a single newline character in the output.
@ fDedent_SkipEmptyFirstLine
Ignore first line and skip it from the result, if it is empty only.
@ fDedent_SkipFirstLine
Ignore first line and skip it from the result.
@ fSS_NoMerge
Do not merge adjacent spaces (rejected chars)
@ fSS_print
Check on isprint()
@ fSS_NoTruncate_Begin
Do not truncate leading spaces.
@ fSS_NoTruncate_End
Do not truncate trailing spaces.
@ fSS_cntrl
Check on iscntrl()
@ fSS_Reject
Reject specified characters, allow all other.
@ fSS_punct
Check on ispunct()
@ fSS_alpha
Check on isalpha()
@ fSS_digit
Check on isdigit()
@ fSS_alnum
Check on isalnum()
@ fSS_Remove
Remove (rather than replace) rejected chars.
@ fDecimalPosixFinite
StringToDouble*(): Keep result finite and normalized: if DBL_MAX < result < INF, result becomes DBL_M...
@ fAllowTrailingSpaces
Ignore trailing space characters.
@ fDS_ProhibitFractions
StringToUInt8_DataSize(): Ignore any fraction part of a value, "1.2K" ~ "1K".
@ fConvErr_NoErrMessage
Set errno, but do not set CNcbiError message on error.
@ fConvErr_NoThrow
Do not throw an exception on error.
@ fAllowLeadingSymbols
Ignore leading non-numeric characters.
@ fDS_ForceBinary
StringToUInt8_DataSize(): Use 1024 as a kilobyte factor regardless of suffix, like "KB" or "KiB".
@ fAllowCommas
Allow commas. See 'ENumToStringFlags::fWithCommas'.
@ fAllowTrailingSymbols
Ignore trailing non-numerics characters.
@ fDS_ProhibitSpaceBeforeSuffix
StringToUInt8_DataSize(): Do not allow spaces between value and suffix, like "10 K".
@ fMandatorySign
Check on mandatory sign. See 'ENumToStringFlags::fWithSign'.
@ fAllowLeadingSpaces
Ignore leading spaces in converted string.
@ fDecimalPosix
StringToDouble*(): For decimal point, use C locale.
@ fDecimalPosixOrLocal
StringToDouble*(): For decimal point, try both C and current locale.
@ eSqlEnc_TagNonASCII
Produce N'...' when input's not pure ASCII.
@ fSplit_CanEscape
Allow \... escaping.
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
@ fSplit_CanDoubleQuote
Allow "..." quoting.
@ fSplit_Truncate_Begin
Truncate leading delimiters.
@ fSplit_ByPattern
Require full delimiter strings.
@ fSplit_CanSingleQuote
Allow '...' quoting.
@ fWrap_Hyphenate
Add a hyphen when breaking words?
@ fWrap_HTMLPre
Wrap as pre-formatted HTML?
@ fWrap_FlatFile
Wrap for flat file use.
@ eUrlEnc_ProcessMarkChars
Convert all non-alphanumeric chars, spaces are converted to '+'.
@ eUrlEnc_None
Do not encode.
@ eUrlEnc_URIQueryValue
Encode query part of an URI, arg value.
@ eUrlEnc_PercentOnly
Convert all non-alphanumeric chars including space and '' to %## format.
@ eUrlEnc_URIHost
Encode host part of an URI.
@ eUrlEnc_URIQueryName
Encode query part of an URI, arg name.
@ eUrlEnc_URIPath
Encode path part of an URI.
@ eUrlEnc_Path
Same as ProcessMarkChars but preserves valid path characters ('/', '.')
@ eUrlEnc_URIScheme
Encode scheme part of an URI.
@ eUrlEnc_URIUserinfo
Encode userinfo part of an URI.
@ eUrlEnc_SkipMarkChars
Do not convert chars like '!', '(' etc.
@ eUrlEnc_Cookie
Same as SkipMarkChars with encoded ','.
@ eUrlEnc_URIFragment
Encode fragment part of an URI.
@ eFirst
First occurrence.
@ eUrlDec_All
Decode '+' to space.
@ eReverseSearch
Search in a backward direction.
@ eForwardSearch
Search in a forward direction.
@ eXmlEnc_CommentSafe
Encode double hyphen and ending hyphen, making the result safe to put into XML comments.
@ eXmlEnc_Unsafe_Skip
Check each character to conform XML 1.1 standards, skip any not allowed character or throw an CString...
@ fDoubleScientific
DoubleToString*(): Use scientific format for double conversions.
@ fDoublePosix
DoubleToString*(): Use C locale for double conversions.
@ fWithRadix
Prefix the output value with radix for "well-known" bases like 8 ("0") and 16 ("0x")
@ fDoubleFixed
DoubleToString*(): Use n.nnnn format for double conversions.
@ fDS_PutBSuffixToo
UInt8ToString_DataSize(): Use "B" suffix for small bytes values.
@ fWithCommas
Use commas as thousands separator.
@ fUseLowercase
Use lowercase letters for string representation for bases above 10.
@ fDS_ShortSuffix
UInt8ToString_DataSize(): Use short suffix, like "10.0K".
@ fWithSign
Prefix the output value with a sign ('+'/'-')
@ fDS_PutSpaceBeforeSuffix
UInt8ToString_DataSize(): Add space between value and qualifiers, like "10.0 KB".
@ fDS_Binary
UInt8ToString_DataSize(): Use 1024 as a kilobyte factor, not 1000.
@ fDS_NoDecimalPoint
UInt8ToString_DataSize(): Do not add a decimal point ("10KB" vs "10.0KB")
@ eConvert
Failure to convert string.
@ eFormat
Wrong format for any input to string methods.
@ eBadArgs
Bad arguments to string methods.
@ eTrunc_Both
Truncate spaces at both begin and end of string.
@ eTrunc_End
Truncate trailing spaces only.
@ eTrunc_Begin
Truncate leading spaces only.
@ eQuoted
String is quoted.
@ eNotQuoted
String is not quoted.
@ fHtmlEnc_CheckPreencoded
Print warning if some pre-encoded entity found in the string.
@ fHtmlEnc_SkipLiteralEntities
Skip "&entity;".
@ fHtmlEnc_SkipNumericEntities
Skip "&#NNNN;".
@ fHtmlDec_Encoding_Changed
Character encoding changed.
@ fHtmlDec_CharRef_Entity
Character entity reference(s) was found.
@ fHtmlDec_CharRef_Numeric
Numeric character reference(s) was found.
@ eNocase
Case insensitive compare.
@ eCase
Case sensitive compare.
@ eEscSeqRange_User
Set char to the user value passed in another parameter.
@ eEscSeqRange_Standard
Set char to the last (least significant byte) of the escape sequence (default).
@ eEscSeqRange_Throw
Throw an exception.
@ eEscSeqRange_Errno
Set errno to ERANGE, return empty string.
@ eEscSeqRange_FirstByte
Set char to the first byte of the escape sequence.
unsigned int
A callback function used to compare two keys in a database.
#define NCBI_DEVELOPMENT_VER
Definition of all error codes used in corelib (xncbi.lib).
static void hex(unsigned char c)
const struct ncbi::grid::netcache::search::fields::SIZE size
pair< CTempString, CTempString > s_GetField(const string &data, size_t &pos)
const GenericPointer< typename T::ValueType > T2 value
static unsigned int ud(time_t one, time_t two)
#define NCBI_CONST_UINT8(v)
Defines NCBI C++ Toolkit portable error codes.
Floating-point support routines.
static const char * s_kFString
static bool _isspace(unsigned char c)
static const char * s_kYString
static const char s_EncodeURIScheme[256][4]
#define CHECK_ENDPTR_SIZE(to_type)
#define S2N_CONVERT_GUARD_EX(flags)
static const char * s_kOnString
static double s_StringToDouble(const char *str, size_t size, NStr::TStringToNumFlags flags)
static void s_UnsignedOtherBaseToString(string &out_str, T value, NStr::TNumToStringFlags flags, int base)
static const char * s_kNoString
static const char s_EncodeURIPath[256][4]
static const char s_EncodePath[256][4]
static const char s_EncodeMarkChars[256][4]
#define CHECK_SPLIT_TEMPSTRING_FLAGS(where)
const int kMaxDoublePrecision
#define PRINT_INT8_CHUNK_SIZE
static const char kDigitUpper[]
string x_AsSingleByteString(const CTempString &str, const SCharEncoder &enc, const char *substitute_on_error)
static const char s_EncodePercentOnly[256][4]
const char *const kNcbiDevelopmentVersionString
static bool s_IsWordBoundaryChar(char ch)
static const char * s_kFalseString
static const char kDigitLower[]
static const char s_EncodeURIQueryValue[256][4]
static const char * s_kOffString
TStr s_TruncateSpaces(const TStr &str, NStr::ETrunc where, const TStr &empty_str)
static SIZE_TYPE s_DiffPtr(const char *end, const char *start)
#define S2N_CONVERT_ERROR(to_type, msg, errcode, pos)
static const TUnicodeSymbol s_cp1252_table[]
#define S2N_CONVERT_ERROR_RADIX(to_type, msg)
static const char * s_kYesString
static const char * s_kNString
static bool s_IsDecimalPoint(unsigned char ch, NStr::TStringToNumFlags flags)
#define S2N_CONVERT_GUARD(flags)
Regular guard.
static struct tag_HtmlEntities s_HtmlEntities[]
static bool s_IsIPAddress(const char *str, size_t size)
static void s_SkipAllowedSymbols(const CTempString str, SIZE_TYPE &pos, ESkipMode skip_mode, NStr::TStringToNumFlags flags)
static const char s_EncodeURIFragment[256][4]
static Uint8 s_DataSizeConvertQual(const CTempString str, SIZE_TYPE &pos, Uint8 value, NStr::TStringToNumFlags flags)
static bool s_IsGoodCharForRadix(char ch, int base, int *value=0)
static const char * s_kTrueString
static bool s_CheckRadix(const CTempString str, SIZE_TYPE &pos, int &base)
static const char s_EncodeURIQueryName[256][4]
static EMatchesMaskResult s_MatchesMask(CTempString str, CTempString mask, bool ignore_case)
string s_ParseJsonEncodeEscapes(const CTempString str)
static const char s_EncodeURIUserinfo[256][4]
static SIZE_TYPE s_VisibleHtmlWidth(const string &str)
static SIZE_TYPE s_EndOfReference(const string &str, SIZE_TYPE start)
static void s_SignedBase10ToString(string &out_str, unsigned long value, long svalue, NStr::TNumToStringFlags flags, int base)
static char * s_ncbi_append_int2str(char *buffer, unsigned int value, size_t digits, bool zeros)
TContainer & s_Split(const TString &str, const TString &delim, TContainer &arr, NStr::TSplitFlags flags, vector< SIZE_TYPE > *token_pos, CTempString_Storage *storage=NULL)
static string s_PrintableString(const CTempString str, NStr::TPrintableMode mode, ELanguage lang)
static const char s_EncodeURIHost[256][4]
CTempString s_Unquote(const CTempString str, size_t *n_read)
static const char s_Encode[256][4]
const int kMaxDoubleStringSize
static const char s_EncodeCookie[256][4]
static char * s_PrintBase10Uint8(char *pos, Uint8 value, NStr::TNumToStringFlags flags)
static void s_URLDecode(const CTempString src, string &dst, NStr::EUrlDecode flag)
static const char * s_kTString
static SIZE_TYPE s_EndOfTag(const string &str, SIZE_TYPE start)
#define S2N_CONVERT_ERROR_INVAL(to_type)
#define CHECK_ENDPTR(to_type)
#define S2N_CONVERT_ERROR_OVERFLOW(to_type)
Algorithms for string processing.
Int4 delta(size_t dimension_, const Int4 *score_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
static const char * suffix[]
static const char * prefix[]
static pcre_uint8 * buffer
static const streamsize kBufSize
static const char delimiter[]
Do nothing target reservation trait.
Do nothing token counter.
Do-nothing token position container.
virtual char ToChar(TUnicodeSymbol sym) const =0
virtual TUnicodeSymbol ToUnicode(char ch) const =0
virtual TUnicodeSymbol ToUnicode(char ch) const
SEncEncoder(EEncoding encoding)
virtual char ToChar(TUnicodeSymbol sym) const
const ctype< wchar_t > & m_Facet
virtual TUnicodeSymbol ToUnicode(char ch) const
virtual char ToChar(TUnicodeSymbol sym) const
SLocaleEncoder(const locale &lcl)