1 #ifndef CORELIB___NCBISTR__HPP
2 #define CORELIB___NCBISTR__HPP
59 #define NcbiEmptyCStr NCBI_NS_NCBI::kEmptyCStr
61 #if defined(HAVE_WSTRING)
63 #define NcbiEmptyWCStr NCBI_NS_NCBI::kEmptyWCStr
67 #if defined(NCBI_OS_MSWIN) \
68 || (defined(NCBI_OS_LINUX) \
69 && (defined(NCBI_COMPILER_GCC) || defined(NCBI_COMPILER_ANY_CLANG)))
75 static const string&
Get(
void)
77 static string empty_str;
81 #if defined(HAVE_WSTRING)
86 static const wstring&
Get(
void)
88 static wstring empty_str;
98 static const string&
Get(
void);
102 static const string& FirstGet(
void);
103 static const string* m_Str;
106 # if defined(HAVE_WSTRING)
111 static const wstring&
Get(
void);
115 static const wstring& FirstGet(
void);
116 static const wstring* m_Str;
122 #define NcbiEmptyString NCBI_NS_NCBI::CNcbiEmptyString::Get()
123 #define kEmptyStr NcbiEmptyString
125 #if defined(HAVE_WSTRING)
126 # define NcbiEmptyWString NCBI_NS_NCBI::CNcbiEmptyWString::Get()
127 # define kEmptyWStr NcbiEmptyWString
133 #define NPOS NCBI_NS_STD::string::npos
145 #if defined(NCBI_OS_MSWIN) && defined(_UNICODE)
151 # define _TX(x) L ## x
155 # define _T_XSTRING(x) \
156 ncbi::CUtf8::AsBasicString<ncbi::TXChar>(x, NULL, ncbi::CUtf8::eValidate)
158 # define _T_XSTRING(x) \
159 ncbi::CUtf8::AsBasicString<ncbi::TXChar>(x, NULL, ncbi::CUtf8::eNoValidate)
161 # define _T_STDSTRING(x) ncbi::CUtf8::AsUTF8(x)
162 # define _T_XCSTRING(x) _T_XSTRING(x).c_str()
163 # define _T_CSTRING(x) _T_STDSTRING(x).c_str()
165 # define NcbiEmptyXCStr NcbiEmptyWCStr
166 # define NcbiEmptyXString NcbiEmptyWString
167 # define kEmptyXStr kEmptyWStr
168 # define kEmptyXCStr kEmptyWCStr
179 # define _T_XSTRING(x) (x)
180 # define _T_STDSTRING(x) (x)
181 # define _T_XCSTRING(x) ncbi::impl_ToCString(x)
182 # define _T_CSTRING(x) (x)
184 # define NcbiEmptyXCStr NcbiEmptyCStr
185 # define NcbiEmptyXString NcbiEmptyString
186 # define kEmptyXStr kEmptyStr
187 # define kEmptyXCStr kEmptyCStr
198 #if defined(NCBI_CUTF8_ENCODING_CLASSIC) || !defined(HAVE_ENUM_CLASS)
227 #define eEncoding_Unknown EEncoding::Unknown
228 #define eEncoding_UTF8 EEncoding::UTF8
229 #define eEncoding_Ascii EEncoding::Ascii
230 #define eEncoding_ISO8859_1 EEncoding::ISO8859_1
231 #define eEncoding_Windows_1252 EEncoding::Windows_1252
232 #define eEncoding_CESU8 EEncoding::CESU8
251 fUseLowercase = (1 << 4),
252 fWithRadix = (1 << 5),
253 fWithSign = (1 << 6),
254 fWithCommas = (1 << 7),
255 fDoubleFixed = (1 << 8),
256 fDoubleScientific = (1 << 9),
257 fDoublePosix = (1 << 10),
258 fDoubleGeneral = fDoubleFixed | fDoubleScientific,
260 fDS_Binary = (1 << 11),
261 fDS_NoDecimalPoint = (1 << 12),
262 fDS_PutSpaceBeforeSuffix = (1 << 13),
263 fDS_ShortSuffix = (1 << 14),
264 fDS_PutBSuffixToo = (1 << 15)
285 fConvErr_NoThrow = (1 << 0),
291 fConvErr_NoErrMessage = (1 << 2),
292 fMandatorySign = (1 << 17),
293 fAllowCommas = (1 << 18),
294 fAllowLeadingSpaces = (1 << 19),
295 fAllowLeadingSymbols = (1 << 20) | fAllowLeadingSpaces,
297 fAllowTrailingSpaces = (1 << 21),
298 fAllowTrailingSymbols = (1 << 22) | fAllowTrailingSpaces,
300 fDecimalPosix = (1 << 23),
301 fDecimalPosixOrLocal = (1 << 24),
302 fDecimalPosixFinite = (1 << 25),
306 fDS_ForceBinary = (1 << 26),
307 fDS_ProhibitFractions = (1 << 27),
308 fDS_ProhibitSpaceBeforeSuffix = (1 << 28)
329 template <
typename TNumeric>
334 return x_StringToNumeric<TNumeric>(
str,
flags, base);
355 template <
typename TNumeric>
382 return StringToNonNegativeInt(
str);
401 TStringToNumFlags
flags = 0,
420 TStringToNumFlags
flags = 0,
439 TStringToNumFlags
flags = 0,
458 TStringToNumFlags
flags = 0,
490 static double StringToDoublePosix(
const char*
str,
char** endptr=0,
491 TStringToNumFlags
flags=0);
511 TStringToNumFlags
flags = 0);
518 static double StringToDoubleEx(
const char*
str,
size_t size,
519 TStringToNumFlags
flags = 0);
537 TStringToNumFlags
flags = 0,
556 TStringToNumFlags
flags = 0,
583 TStringToNumFlags
flags = 0);
611 TStringToNumFlags
flags,
630 TStringToNumFlags
flags = 0,
654 static int HexChar(
char ch);
671 template<
typename TNumeric>
679 template <
typename TStrictId>
683 return NumericToString(
value.Get(),
flags, base);
703 template<
typename TNumeric>
707 x_NumericToString(out_str,
value,
flags, base);
724 static string IntToString(
int value, TNumToStringFlags
flags = 0,
727 static string IntToString(
unsigned int value, TNumToStringFlags
flags = 0,
746 static void IntToString(
string& out_str,
int value,
747 TNumToStringFlags
flags = 0,
750 static void IntToString(
string& out_str,
unsigned int value,
751 TNumToStringFlags
flags = 0,
768 static string UIntToString(
unsigned int value,
769 TNumToStringFlags
flags = 0,
772 static string UIntToString(
int value,
773 TNumToStringFlags
flags = 0,
792 static void UIntToString(
string& out_str,
unsigned int value,
793 TNumToStringFlags
flags = 0,
796 static void UIntToString(
string& out_str,
int value,
797 TNumToStringFlags
flags = 0,
814 static string LongToString(
long value, TNumToStringFlags
flags = 0,
833 static void LongToString(
string& out_str,
long value,
834 TNumToStringFlags
flags = 0,
851 static string ULongToString(
unsigned long value,
852 TNumToStringFlags
flags = 0,
871 static void ULongToString(
string& out_str,
unsigned long value,
872 TNumToStringFlags
flags = 0,
890 TNumToStringFlags
flags = 0,
910 TNumToStringFlags
flags = 0,
928 TNumToStringFlags
flags = 0,
947 static void UInt8ToString(
string& out_str,
Uint8 value,
948 TNumToStringFlags
flags = 0,
979 static string UInt8ToString_DataSize(
Uint8 value,
980 TNumToStringFlags
flags = 0,
981 unsigned int max_digits = 3);
996 static void UInt8ToString_DataSize(
string& out_str,
998 TNumToStringFlags
flags = 0,
999 unsigned int max_digits = 3);
1020 TNumToStringFlags
flags = 0);
1043 static void DoubleToString(
string& out_str,
double value,
1045 TNumToStringFlags
flags = 0);
1069 TNumToStringFlags
flags = 0);
1129 int* dec,
int* sign);
1145 static string SizetToString(
size_t value,
1146 TNumToStringFlags
flags = 0,
1159 static void PtrToString(
string& out_str,
const void* ptr);
1169 static string PtrToString(
const void* ptr);
1179 static const string BoolToString(
bool value);
1200 static string FormatVarargs(
const char*
format, va_list args);
1275 static int CompareCase(
const char* s1,
const char* s2);
1380 const char* s2, ECase use_case = eCase);
1421 static int Compare(
const char* s1,
const char* s2,
1422 ECase use_case = eCase);
1441 ECase use_case = eCase);
1492 static bool EqualCase(
const char* s1,
const char* s2);
1556 static bool EqualNocase(
const char* s1,
const char* s2);
1591 const char* s2, ECase use_case = eCase);
1631 static bool Equal(
const char* s1,
const char* s2,
1632 ECase use_case = eCase);
1649 ECase use_case = eCase);
1666 static int strcmp(
const char* s1,
const char* s2);
1682 static int strncmp(
const char* s1,
const char* s2,
size_t n);
1696 static int strcasecmp(
const char* s1,
const char* s2);
1711 static int strncasecmp(
const char* s1,
const char* s2,
size_t n);
1715 static size_t strftime(
char* s,
size_t maxsize,
const char*
format,
1716 const struct tm* timeptr);
1820 static string& ToLower(
string&
str);
1828 static char* ToLower(
char*
str);
1836 static string& ToUpper(
string&
str);
1844 static char* ToUpper(
char*
str);
1867 ECase use_case = eCase);
1879 ECase use_case = eCase);
1891 ECase use_case = eCase);
1903 ECase use_case = eCase);
1972 ECase use_case = eCase,
1973 EDirection direction = eForwardSearch,
2027 EOccurrence which = eFirst,
2028 ECase use_case = eCase);
2033 {
return FindCase(
str, pattern, start); }
2091 EOccurrence which = eFirst);
2150 EOccurrence which = eFirst);
2158 static const string* Find (
const list<string>& lst,
2160 ECase use_case = eCase);
2162 static const string* FindCase (
const list<string>& lst,
2165 static const string* FindNoCase(
const list<string>& lst,
2168 static const string* Find (
const vector<string>& vec,
2170 ECase use_case = eCase);
2172 static const string* FindCase (
const vector<string>& vec,
2175 static const string* FindNoCase(
const vector<string>& vec,
2196 ECase use_case = eCase,
2197 EDirection direction = eForwardSearch);
2233 ECase use_case = eCase) {
2234 return FindWord(
str, word, use_case, which == eFirst ? eForwardSearch : eReverseSearch);
2254 static string TruncateSpaces(
const string&
str,
2255 ETrunc where = eTrunc_Both);
2273 ETrunc where = eTrunc_Both);
2280 ETrunc where = eTrunc_Both) {
2281 return TruncateSpaces_Unsafe(
str, where);
2289 ETrunc where = eTrunc_Both) {
2290 return TruncateSpaces_Unsafe(
str, where);
2300 static void TruncateSpacesInPlace(
string&
str, ETrunc where = eTrunc_Both);
2301 static void TruncateSpacesInPlace(
CTempString&, ETrunc where = eTrunc_Both);
2315 ECase use_case = eCase);
2317 ECase use_case = eCase);
2339 ECase use_case = eCase);
2352 ECase use_case = eCase);
2354 ECase use_case = eCase);
2376 ECase use_case = eCase);
2407 static string& Replace(
const string& src,
2408 const string& search,
2409 const string& replace,
2444 static string Replace(
const string& src,
2445 const string& search,
2446 const string& replace,
2480 static string& ReplaceInPlace(
string& src,
2481 const string& search,
2482 const string& replace,
2498 fSplit_MergeDelimiters = 1 << 0,
2499 fSplit_Truncate_Begin = 1 << 1,
2500 fSplit_Truncate_End = 1 << 2,
2501 fSplit_Truncate = fSplit_Truncate_Begin | fSplit_Truncate_End,
2502 fSplit_ByPattern = 1 << 3,
2503 fSplit_CanEscape = 1 << 4,
2504 fSplit_CanSingleQuote = 1 << 5,
2505 fSplit_CanDoubleQuote = 1 << 6,
2506 fSplit_CanQuote = fSplit_CanSingleQuote | fSplit_CanDoubleQuote,
2508 fSplit_Tokenize = fSplit_MergeDelimiters | fSplit_Truncate
2515 eMergeDelims = fSplit_MergeDelimiters | fSplit_Truncate,
2546 TSplitFlags
flags = 0,
2547 vector<SIZE_TYPE>* token_pos =
NULL);
2549 static vector<string>& Split(
2552 vector<string>&
arr,
2553 TSplitFlags
flags = 0,
2554 vector<SIZE_TYPE>* token_pos =
NULL);
2556 static list<CTempString>& Split(
2559 list<CTempString>&
arr,
2560 TSplitFlags
flags = 0,
2561 vector<SIZE_TYPE>* token_pos =
NULL,
2564 static vector<CTempString>& Split(
2567 vector<CTempString>&
arr,
2568 TSplitFlags
flags = 0,
2569 vector<SIZE_TYPE>* token_pos =
NULL,
2572 static list<CTempStringEx>& Split(
2575 list<CTempStringEx>&
arr,
2576 TSplitFlags
flags = 0,
2577 vector<SIZE_TYPE>* token_pos =
NULL,
2580 static vector<CTempStringEx>& Split(
2583 vector<CTempStringEx>&
arr,
2584 TSplitFlags
flags = 0,
2585 vector<SIZE_TYPE>* token_pos =
NULL,
2620 TSplitFlags
flags = 0);
2626 TSplitFlags
flags = 0,
2633 TSplitFlags
flags = 0,
2639 static list<string>& SplitByPattern(
2643 TSplitFlags
flags = 0,
2644 vector<SIZE_TYPE>* token_pos =
NULL);
2646 static vector<string>& SplitByPattern(
2649 vector<string>&
arr,
2650 TSplitFlags
flags = 0,
2651 vector<SIZE_TYPE>* token_pos =
NULL);
2653 static list<CTempString>& SplitByPattern(
2656 list<CTempString>&
arr,
2657 TSplitFlags
flags = 0,
2658 vector<SIZE_TYPE>* token_pos =
NULL,
2661 static vector<CTempString>& SplitByPattern(
2664 vector<CTempString>&
arr,
2665 TSplitFlags
flags = 0,
2666 vector<SIZE_TYPE>* token_pos =
NULL,
2669 static list<CTempStringEx>& SplitByPattern(
2672 list<CTempStringEx>&
arr,
2673 TSplitFlags
flags = 0,
2674 vector<SIZE_TYPE>* token_pos =
NULL,
2677 static vector<CTempStringEx>& SplitByPattern(
2680 vector<CTempStringEx>&
arr,
2681 TSplitFlags
flags = 0,
2682 vector<SIZE_TYPE>* token_pos =
NULL,
2695 template<
typename TContainer>
2699 return x_Join(begin(
arr), end(
arr), delim);
2701 template<
typename TValue>
2705 return x_Join(begin(
arr), end(
arr), delim);
2707 template<
typename TInputIterator>
2711 return x_Join(from, to, delim);
2713 template<
typename TInputIterator>
2717 return x_Join( from, to, delim);
2719 template<
typename TIterator,
typename FTransform>
2729 eNewLine_Quote = fNewLine_Quote,
2730 fNewLine_Passthru = 1,
2731 eNewLine_Passthru = fNewLine_Passthru,
2732 fNonAscii_Passthru = 0,
2733 fNonAscii_Quote = 2,
2734 fPrintable_Full = 64
2781 char escape_char =
'\\');
2794 static string Unescape(
const CTempString str,
char escape_char =
'\\');
2816 static string Quote(
const CTempString str,
char quote_char =
'"',
char escape_char =
'\\');
2829 static string Unquote(
const CTempString str,
char escape_char =
'\\');
2843 fSS_Reject = 1 << 11,
2847 fSS_Remove = 1 << 12,
2848 fSS_NoMerge = 1 << 13,
2849 fSS_NoTruncate_Begin = 1 << 14,
2850 fSS_NoTruncate_End = 1 << 15,
2851 fSS_NoTruncate = fSS_NoTruncate_Begin | fSS_NoTruncate_End
2930 char reject_replacement =
' ',
2931 TSS_Flags
flags = 0);
2939 eEscSeqRange_Standard,
2941 eEscSeqRange_FirstByte,
2971 EEscSeqRange
mode = eEscSeqRange_Standard,
2972 char user_char =
'?');
3000 static string CEncode(
const CTempString str, EQuoted quoted = eQuoted);
3027 eXmlEnc_Contents = 0,
3030 eXmlEnc_CommentSafe = 1 << 0,
3034 eXmlEnc_Unsafe_Skip = 1 << 1,
3035 eXmlEnc_Unsafe_Throw = 1 << 2
3048 fHtmlEnc_EncodeAll = 0,
3049 fHtmlEnc_SkipLiteralEntities = 1 << 1,
3050 fHtmlEnc_SkipNumericEntities = 1 << 2,
3051 fHtmlEnc_SkipEntities = fHtmlEnc_SkipLiteralEntities | fHtmlEnc_SkipNumericEntities,
3052 fHtmlEnc_CheckPreencoded = 1 << 3
3067 fHtmlDec_CharRef_Entity = 1,
3068 fHtmlDec_CharRef_Numeric = 1 << 1,
3069 fHtmlDec_Encoding_Changed = 1 << 2
3113 static string JsonEncode(
const CTempString str, EJsonEncode encoding = eJsonEnc_UTF8);
3138 static string ShellEncode(
const string&
str);
3193 {
return SQLEncode(
str, eSqlEnc_Plain); }
3198 static void URLDecodeInPlace(
string&
str,
EUrlDecode flag = eUrlDec_All);
3211 static string Base64Encode(
const CTempString str,
size_t line_len = 0);
3228 fWrap_Hyphenate = 0x1,
3229 fWrap_HTMLPre = 0x2,
3230 fWrap_FlatFile = 0x4
3262 template<
typename _D>
3265 const string*
prefix = 0,
3266 const string* prefix1 = 0);
3284 m_list.push_back(s);
3294 IWrapDest& dest, TWrapFlags
flags,
3296 const string* prefix1);
3298 static list<string>& Wrap(
const string&
str,
SIZE_TYPE width,
3299 list<string>&
arr, TWrapFlags
flags = 0,
3300 const string*
prefix = 0,
3301 const string* prefix1 = 0);
3303 static list<string>& Wrap(
const string&
str,
SIZE_TYPE width,
3304 list<string>&
arr, TWrapFlags
flags,
3306 const string* prefix1 = 0);
3308 static list<string>& Wrap(
const string&
str,
SIZE_TYPE width,
3309 list<string>&
arr, TWrapFlags
flags,
3311 const string& prefix1);
3343 static list<string>& WrapList(
const list<string>& l,
SIZE_TYPE width,
3344 const string& delim, list<string>&
arr,
3345 TWrapFlags
flags = 0,
3346 const string*
prefix = 0,
3347 const string* prefix1 = 0);
3349 static list<string>& WrapList(
const list<string>& l,
SIZE_TYPE width,
3350 const string& delim, list<string>&
arr,
3353 const string* prefix1 = 0);
3355 static list<string>& WrapList(
const list<string>& l,
SIZE_TYPE width,
3356 const string& delim, list<string>&
arr,
3359 const string& prefix1);
3408 fDedent_NormalizeEmptyLines = 1 << 0,
3412 fDedent_SkipFirstLine = 1 << 1,
3413 fDedent_SkipEmptyFirstLine = 1 << 2,
3547 template<
typename TNumeric,
typename TSource>
3551 return x_ReportLimitsError(
str,
flags);
3555 template<
typename TNumeric,
typename TSource>
3560 return x_ReportLimitsError(
str,
flags);
3565 template <
typename TNumeric>
3570 return x_VerifyIntLimits<TNumeric>(
n,
str,
flags) ? (TNumeric)
n : 0;
3572 template <
typename TNumeric>
3576 unsigned int n = StringToUInt(
str,
flags, base);
3577 return x_VerifyIntLimits<TNumeric>(
n,
str,
flags) ? (TNumeric)
n : 0;
3580 template <
typename TNumeric>
3584 return StringToInt(
str,
flags, base);
3586 template <
typename TNumeric>
3590 return StringToUInt(
str,
flags, base);
3592 template <
typename TNumeric>
3596 return StringToLong(
str,
flags, base);
3598 template <
typename TNumeric>
3602 return StringToULong(
str,
flags, base);
3604 template <
typename TNumeric>
3610 template <
typename TNumeric>
3614 return StringToUInt8(
str,
flags, base);
3616 template <
typename TStrictId>
3620 return TStrictId(StringToNumeric<typename TStrictId::TId>(
str,
flags, base));
3623 template <
typename TNumeric>
3628 return x_VerifyFloatLimits<TNumeric>(
n,
str,
flags) ? (TNumeric)
n : 0;
3630 template <
typename TNumeric>
3637 template <
typename TNumeric>
3643 if (( !
n && errno ) || !x_VerifyIntLimits<TNumeric>(
n,
str,
flags)) {
3649 template <
typename TNumeric>
3653 unsigned int n = StringToUInt(
str,
flags, base);
3655 if (( !
n && errno ) || !x_VerifyIntLimits<TNumeric>(
n,
str,
flags)) {
3661 template <
typename TNumeric>
3666 return (*
value || !errno);
3668 template <
typename TNumeric>
3673 return (*
value || !errno);
3679 return (*
value || !errno);
3685 return (*
value || !errno);
3687 template <
typename TNumeric>
3692 return (*
value || !errno);
3694 template <
typename TNumeric>
3699 return (*
value || !errno);
3706 if (( !
n && errno ) || !x_VerifyFloatLimits<float>(
n,
str,
flags)) {
3716 return (*
value || !errno);
3718 template <
typename TStrictId>
3726 template<
typename TNumeric>
3732 template<
typename TNumeric>
3748 #if NCBI_COMPILER_MSVC && (_MSC_VER < 1900)
3750 x_NumericToString(
string& out_str,
Int8 value, TNumToStringFlags
flags,
int base)
3755 x_NumericToString(
string& out_str,
Uint8 value, TNumToStringFlags
flags,
int base)
3760 template<
typename TNumeric>
3766 template<
typename TNumeric>
3772 template<
typename TNumeric>
3778 template <
typename TStrictId>
3782 return x_NumericToString(out_str,
value.Get(),
flags, base);
3787 template<
typename TIterator>
3790 template<
typename TIterator>
3798 template<
typename TIterator>
3803 return xx_Join(from, to, delim);
3806 template<
typename TValue>
3810 return xx_Join(from, to, delim);
3813 template<
typename TIterator>
3818 return TransformJoin( from, to, delim, [](
const typename TIterator::value_type&
i){
return NumericToString(
i);});
3821 template<
typename TValue>
3825 return TransformJoin( from, to, delim, [](
const TValue&
i){
return NumericToString(
i);});
3835 #define NCBITOOLKIT_USE_LONG_UCS4 (SIZEOF_LONG == 4)
3836 #if NCBITOOLKIT_USE_LONG_UCS4
3894 return x_Append(u8,src,encoding,
validate);
3897 #if defined(HAVE_WSTRING)
3907 return x_Append(u8,src,lcl);
3917 template <
typename TChar>
3922 return x_Append(u8, src.data(), src.size());
3932 template <
typename TChar>
3937 return x_Append(u8, src, tchar_count);
3948 template <
typename TChar>
3952 return x_Append(dest, src.data(), src.size());
3966 template <
typename TChar>
3970 return x_Append(dest, src, tchar_count);
3981 template <
typename TChar>
3985 return x_Append(dest, &ch, 1);
4005 return x_Append(dest,src,encoding,
validate);
4008 #if defined(HAVE_WSTRING)
4023 return x_Append(dest,src,lcl);
4047 #if defined(HAVE_WSTRING)
4082 static string AsSingleByteString
4084 const char* substitute_on_error = 0, EValidate
validate = eNoValidate);
4086 #if defined(HAVE_WSTRING)
4087 static string AsSingleByteString
4089 const char* substitute_on_error = 0, EValidate
validate = eNoValidate);
4106 template <
typename TChar>
4110 return x_AsBasicString(src,substitute_on_error,
validate);
4113 template <
typename TChar>
4117 return x_AsBasicString<TChar>(src,
nullptr,eNoValidate);
4161 return x_EvalFirst(ch, more);
4171 return x_EvalNext(ch);
4201 static string EncodingToString(
EEncoding encoding);
4222 #if defined(HAVE_WSTRING)
4244 #if defined(HAVE_WSTRING)
4315 #ifndef NCBI_COMPILER_WORKSHOP
4355 #if defined(HAVE_WSTRING)
4358 template <
typename TChar>
4360 template <
typename TChar>
4363 template <
typename TChar>
4364 static basic_string<TChar> x_AsBasicString
4368 template <
typename TIterator>
4372 static bool x_EvalFirst(
char ch,
SIZE_TYPE& more);
4373 static bool x_EvalNext(
char ch);
4395 template <
class TBase>
4408 case eErr:
return "eErr";
4418 EErrCode err_code,
const string& message,
4420 : TBase(
info, prev_exception, message, severity, 0),
m_Pos(pos)
4444 out <<
"m_Pos = " << (
unsigned long)
m_Pos;
4451 {
return "CParseTemplException"; }
4468 const string& message,
4470 : TBase(
info, prev_exception, message, severity,
flags),
m_Pos(pos)
4516 virtual const char* GetErrCodeString(
void)
const override;
4592 template<
class TContainer>
4733 ITERATE(list<string>, it, lst) {
4773 const string& arg_sep,
4774 const string& val_sep,
4781 if ( !ret.empty() ) {
4790 ret += it->first + val_sep + it->second;
4839 {
return IsEncoded() ? *m_Encoded : m_Original; }
4842 bool IsEmpty(
void)
const {
return m_Original.empty(); }
4862 template <
typename T>
4866 int Compare(
const T& s1,
const T& s2)
const;
4869 bool Less(
const T& s1,
const T& s2)
const;
4872 bool Equals(
const T& s1,
const T& s2)
const;
4892 template <
typename T>
4922 template <
typename T>
4936 int Compare(
const T& s1,
const T& s2)
const;
4939 bool Less(
const T& s1,
const T& s2)
const;
4942 bool Equals(
const T& s1,
const T& s2)
const;
4963 template <
typename T>
4971 return this->
Equals(s1, s2);
4989 template <
typename T>
5003 return this->
Equals(s1, s2);
5022 size_t len1 = s1.
size(), len2 = s2.
size();
5023 return len1 < len2 ||
5024 (len1 == len2 && ::memcmp(s1.
data(), s2.
data(), len1) < 0);
5035 template<
class Arg1,
class Arg2,
class Pred>
5039 return pr.Equals(x, y);
5057 #if !defined(NCBI_OS_MSWIN) && \
5058 !(defined(NCBI_OS_LINUX) && \
5059 (defined(NCBI_COMPILER_GCC) || defined(NCBI_COMPILER_ANY_CLANG)))
5063 const string*
str = m_Str;
5064 return str ? *
str: FirstGet();
5067 # ifdef HAVE_WSTRING
5071 const wstring*
str = m_Str;
5072 return str ? *
str: FirstGet();
5179 unsigned int max_digits )
5198 unsigned int rc = ch -
'0';
5202 rc = (ch |
' ') -
'a';
5203 return rc <= 5 ?
int(rc + 10) : -1;
5222 #if defined(HAVE_STRICMP)
5223 #if NCBI_COMPILER_MSVC && (_MSC_VER >= 1400)
5224 return ::_stricmp(s1, s2);
5226 return ::stricmp(s1, s2);
5229 #elif defined(HAVE_STRCASECMP_LC)
5234 for ( ;; ++s1, ++s2) {
5237 diff =
tolower((
unsigned char) c1) -
tolower((
unsigned char)(*s2));
5249 #if defined(HAVE_STRICMP)
5250 #if NCBI_COMPILER_MSVC && (_MSC_VER >= 1400)
5251 return ::_strnicmp(s1, s2,
n);
5253 return ::strnicmp(s1, s2,
n);
5256 #elif defined(HAVE_STRCASECMP_LC)
5261 for ( ; ; ++s1, ++s2, --
n) {
5266 diff =
tolower((
unsigned char) c1) -
tolower((
unsigned char)(*s2));
5277 const struct tm* timeptr)
5281 return ::strftime(s, maxsize, x_format.c_str(), timeptr);
5298 const char* s2,
ECase use_case)
5327 return s1.
substr(pos,
n) == s2;
5333 return s1.
substr(pos,
n) == s2;
5339 size_t n = strlen(s1);
5340 if (
n != strlen(s2)) {
5367 size_t n = strlen(s1);
5368 if (
n != strlen(s2)) {
5385 const char* s2,
ECase use_case)
5414 return str.size() >= start.
size() &&
5421 return !
str.empty() &&
5422 (use_case ==
eCase ? (
str[0] == start)
5423 : (
str[0] == start ||
5432 return str.size() >= end.size() &&
5433 Equal(
str.substr(
str.size() - end.size(), end.size()), end, use_case);
5441 return use_case ==
eCase ? (
last == end)
5454 if (s1[
i] != s2[
i]) {
5468 if (s1[len1 -
i] != s2[len2 -
i]) {
5495 return (pos ==
NPOS || (pos + pattern.
length()) > end) ?
NPOS : pos;
5498 return (pos ==
NPOS || pos < start) ?
NPOS : pos;
5558 template<
typename TIterator,
typename FTransform>
5565 string result(fnTransform(*from++));
5566 for ( ; from != to; ++from) {
5567 result.append(delim).append(fnTransform(*from));
5572 template<
typename TIterator>
5580 size_t sz_all = 0, sz_delim = delim.
size();
5582 sz_all +=
string(*f).size() + sz_delim;
5585 for ( ; from != to; ++from) {
5586 result.append(delim).append(
string(*from));
5594 const string* prefix1)
5602 const string& prefix1)
5609 const string& delim, list<string>&
arr,
5611 const string* prefix1)
5618 const string& delim, list<string>&
arr,
5620 const string& prefix1)
5638 return Justify(
str, width, par, &pfx, &pfx1);
5660 return (err-src.
begin());
5665 #ifndef NCBI_COMPILER_WORKSHOP
5682 template <
typename TChar> basic_string<TChar>
5690 basic_string<TChar>
result;
5694 for (; src != to; ++src) {
5696 if (
sizeof(
TChar) > 2 && ch >= 0xD800 && ch <= 0xDBFF) {
5698 ch = (ch - 0xD800) * 0x400 + (
ch2 - 0xDC00) + 0x10000;
5700 if (ch > max_char) {
5701 if (
sizeof(
TChar) == 2) {
5709 if (substitute_on_error) {
5710 result.append(substitute_on_error);
5714 "Failed to convert symbol to wide character",
5715 (src -
str.begin()));
5723 template <
typename TChar>
bool
5726 if ( *src >= 0xD800 && *src <= 0xDBFF &&
5727 *(src+1) >= 0xDC00 && *(src+1) <= 0xDFFF &&
sizeof(
TChar) == 2) {
5728 ch = (*(src) - 0xD800) * 0x400 + (*(src+1) - 0xDC00) + 0x10000;
5738 const TChar* srcBuf;
5742 for (pos=0, srcBuf=src;
5743 (to ==
NPOS) ? (*srcBuf != 0) : (pos<to); ++pos, ++srcBuf) {
5754 u8str.reserve(
max(u8str.capacity(),u8str.length()+needed+1));
5755 for (pos=0, srcBuf=src;
5756 (to ==
NPOS) ? (*srcBuf != 0) : (pos<to); ++pos, ++srcBuf) {
5782 template <
typename T>
5789 template <
typename T>
5796 template <
typename T>
5803 template <
typename T>
5807 return Less(s1, s2);
5817 template <
typename T>
5824 template <
typename T>
5831 template <
typename T>
5838 template <
typename T>
5842 return Less(s1, s2);
5849 template <
typename T>
5852 : m_CaseSensitive(cs)
5855 template <
typename T>
5862 template <
typename T>
5869 template <
typename T>
5876 template <
typename T>
5880 return Less(s1, s2);
void x_Assign(CObject_id &dst, const CObject_id &src)
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
CParseTemplException –.
URL-decoder for string pairs parser.
URL-encoder for string pairs parser.
Template for parsing string into pairs of name and value or merging them back into a single string.
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 ...
Encoder interface. Names and values can be encoded with different rules.
static enable_if< is_integral< TNumeric >::value &&is_unsigned< TNumeric >::value &&(sizeof(TNumeric)< sizeof(unsigned int)), TNumeric >::type x_StringToNumeric(const CTempString str, TStringToNumFlags flags, int base)
static enable_if< is_integral< TNumeric >::value &&is_unsigned< TNumeric >::value &&(sizeof(TNumeric)<=sizeof(unsigned int) &&!is_same< TNumeric, unsigned long >::value), void >::type x_NumericToString(string &out_str, TNumeric value, TNumToStringFlags flags, int base)
static enable_if< is_arithmetic< TValue >::value, string >::type x_Join(TValue *from, TValue *to, const CTempString &delim)
static enable_if< is_convertible< typename TIterator::iterator_category, forward_iterator_tag >::value &&is_convertible< typename TIterator::value_type, string >::value, string >::type x_Join(TIterator from, TIterator to, const CTempString &delim)
static enable_if< is_integral< TNumeric >::value &&is_unsigned< TNumeric >::value &&(sizeof(TNumeric)< sizeof(unsigned int)), bool >::type x_StringToNumeric(const CTempString str, TNumeric *value, TStringToNumFlags flags, int base)
Define Case-insensitive string equality (not less-than) comparison method Case sensitivity can be tur...
Define Case-insensitive string equality (not less-than) comparison method.
Define Case-insensitive string comparison methods.
static vector< string > arr
std::ofstream out("events_result.xml")
main entry point for tests
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
static const char * str(char *buf, int n)
static const char * validate(DSNINFO *di)
Go looking for trouble.
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
element_type * get(void) const
Get pointer.
@ eTakeOwnership
An object can take ownership of another.
@ eNoOwnership
No ownership is assumed.
EDiagSev
Severity level for the posted diagnostics.
@ eDiag_Error
Error message.
#define NCBI_THROW2(exception_class, err_code, message, extra)
Throw exception with extra parameter.
EErrCode
Error types that an application can generate.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
#define EXCEPTION_VIRTUAL_BASE
Do not use virtual base classes in exception declaration at all, because in this case derived class s...
@ eInvalid
To be used ONLY as a return value; please, NEVER throw an exception with this code.
sequence::ECompare Compare(const CSeq_loc &loc1, const CSeq_loc &loc2, CScope *scope)
Returns the sequence::ECompare containment relationship between CSeq_locs.
uint32_t Uint4
4-byte (32-bit) unsigned integer
uint16_t Uint2
2-byte (16-bit) unsigned integer
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
EStringToNumFlags EConvErrFlags
Formerly split out.
EJsonEncode
Json-encode flags.
CParseTemplException(const CDiagCompileInfo &info, const CException *prev_exception, const string &message, string::size_type pos, EDiagSev severity, CException::TFlags flags)
bool operator()(const CTempString s1, const CTempString s2) const
static void NumericToString(string &out_str, TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
static bool x_StringToNumeric(const CTempString str, double *value, TStringToNumFlags flags, int)
static enable_if< is_integral< TNumeric >::value &&is_signed< TNumeric >::value &&(sizeof(TNumeric)< sizeof(int)), TNumeric >::type x_StringToNumeric(const CTempString str, TStringToNumFlags flags, int base)
static bool x_TCharToUnicodeSymbol(TUnicodeSymbol &u, const TChar *src)
static bool x_StringToNumeric(const CTempString str, unsigned long *value, TStringToNumFlags flags, int base)
static void x_Validate(const CTempString &str)
NCBI_NS_STD::string::size_type SIZE_TYPE
virtual void Append(const string &s)=0
static string SizetToString(size_t value, TNumToStringFlags flags=0, int base=10)
Convert size_t to string.
CParseTemplException(void)
Constructor.
PEqualNocase_Generic< const char * > PEqualNocase_CStr
vector< pair< string, string > > TStringPairsVector
static TUnicodeSymbol x_Decode(TIterator &src)
static enable_if< is_integral< TChar >::value &&(1< sizeof(TChar)), basic_string< TChar > >::type AsBasicString(const CTempString &src, const TChar *substitute_on_error, EValidate validate=eNoValidate)
Convert UTF8 string into Unicode.
static bool x_VerifyIntLimits(TSource v, const CTempString str, TStringToNumFlags flags)
static CStringUTF8 & AppendAsUTF8(CStringUTF8 &dest, const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert non-Unicode C++ string into UTF8 and append it to existing string.
EPrintableMode
How to display printable strings.
static void x_NumericToString(string &out_str, unsigned long value, TNumToStringFlags flags, int base)
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
EDedentFlags
Flags for Dedent() method.
int Compare(const T &s1, const T &s2) const
Return difference between "s1" and "s2".
PCase_Generic< string > PCase
PNocase_Generic< const char * > PNocase_CStr
ESS_Flags
Flags for Sanitize().
int TDedentFlags
Bitwise OR of EDedentFlags.
EStringToNumFlags
String to number conversion flags.
string::size_type m_Pos
Error position.
EErrCode
Error types that for exception class.
void Parse(const CTempString str, NStr::EMergeDelims merge_argsep=NStr::eMergeDelims)
Parse the string.
static CStringUTF8 & x_Append(CStringUTF8 &u8str, const CTempString &src, EEncoding encoding, EValidate validate)
CStringPairs(IStringDecoder *decoder=NULL, EOwnership own_decoder=eTakeOwnership, IStringEncoder *encoder=NULL, EOwnership own_encoder=eTakeOwnership)
Create parser with the specified decoder/encoder and default separators.
static string DoubleToString(double value, int precision=-1, TNumToStringFlags flags=0)
Convert double to string.
string Merge(void) const
Merge name-value pairs into a single string using the currently set separators and the provided encod...
CParseTemplException(const CDiagCompileInfo &info, const CException *prev_exception, EErrCode err_code, const string &message, string::size_type pos, EDiagSev severity=eDiag_Error)
Constructor.
static bool StringToNumeric(const CTempString str, TNumeric *value, TStringToNumFlags flags=0, int base=10)
Convert string to a numeric value.
static enable_if< is_integral< typename TStrictId::TId >::value &&is_member_function_pointer< decltype(&TStrictId::Get)>::value, void >::type x_NumericToString(string &out_str, TStrictId value, TNumToStringFlags flags, int base)
ESqlEncode
SQL encode flags.
ESplitFlags
Flags for Split*() methods.
EWrapFlags
How to wrap the words in a string to a new line.
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
CNcbiOstream & operator<<(CNcbiOstream &os, const TStringUCS2 &str)
Operator for writing TStringUCS2 to stream.
EUrlEncode
URL-encode flags.
EMergeDelims
Whether to merge adjacent delimiters.
AutoPtr< IStringDecoder > m_Decoder
CWrapDestStringList(list< string > &l)
EOccurrence
Whether it is the first or last occurrence.
static string Merge(const TStrPairs &pairs, const string &arg_sep, const string &val_sep, IStringEncoder *encoder=NULL, EOwnership own=eTakeOwnership)
Merge name-value pairs from the provided container, separators and encoder.
static void x_NumericToString(string &out_str, long value, TNumToStringFlags flags, int base)
static enable_if< is_integral< TChar >::value &&(1< sizeof(TChar)), CStringUTF8 >::type AsUTF8(const TChar *src, SIZE_TYPE tchar_count=NCBI_NS_STD::string::npos)
Convert into UTF8 from a Unicode character buffer.
const string & GetEncodedString(void) const
Get encoded string.
int TPrintableMode
Bitwise OR of EPrintableMode flags.
TStrPairs & GetPairs(void)
Get non-const data.
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.
virtual string Encode(const CTempString src, EStringType stype) const =0
Encode the string.
void SetDecoder(IStringDecoder *decoder, EOwnership own=eTakeOwnership)
Set string decoder.
CParseTemplException(const CParseTemplException< TBase > &other)
Constructor.
const char * impl_ToCString(const char *s)
CStringPairs(const CTempString arg_sep, const CTempString val_sep, IStringDecoder *decoder=NULL, EOwnership own_decoder=eTakeOwnership, IStringEncoder *encoder=NULL, EOwnership own_encoder=eTakeOwnership)
Create parser with the specified parameters.
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.
bool Less(const T &s1, const T &s2) const
Return TRUE if s1 < s2.
static CTempString TruncateSpaces_Unsafe(const CTempString &str, NStr::ETrunc side=NStr::eTrunc_Both)
Truncate spaces in the string.
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
static SIZE_TYPE x_BytesNeeded(TUnicodeSymbol ch)
static string LongToString(long value, TNumToStringFlags flags=0, int base=10)
Convert Int to string.
unique_ptr< string > m_Encoded
static int strcmp(const char *s1, const char *s2)
String compare.
EDirection
Search direction for Find() methods.
EXmlEncode
XML-encode flags.
NStr::ECase m_CaseSensitive
case sensitive when TRUE
static bool EvaluateNext(char ch)
Check that the character is valid continuation byte of an UTF8 byte sequence.
PEqualNocase_Conditional_Generic< string > PEqualNocase_Conditional
bool IsEmpty(void) const
Check if the string is empty.
virtual void Append(const CTempString &s)
static string TransformJoin(TIterator from, TIterator to, const CTempString &delim, FTransform fnTransform)
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...
Uint4 TUnicodeSymbol
Unicode character.
static CTempString TruncateSpaces(const CTempString str, ETrunc where=eTrunc_Both)
IStringEncoder * GetEncoder(void)
Get encoder or NULL. Does not affect encoder ownership.
static string Join(const initializer_list< TValue > &arr, const CTempString &delim)
PEqualNocase_Generic< string > PEqualNocase
static TNumeric StringToNumeric(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to a numeric value.
static string Join(TInputIterator from, TInputIterator to, const CTempString &delim)
static string JoinNumeric(TInputIterator from, TInputIterator to, const CTempString &delim)
ENumToStringFlags
Number to string conversion flags.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static CStringUTF8 TruncateSpaces(const CTempString &str, NStr::ETrunc side=NStr::eTrunc_Both)
Truncate spaces in the string.
static SIZE_TYPE CommonSuffixSize(const CTempString s1, const CTempString s2)
Determine the common suffix of two strings.
virtual const char * GetType(void) const override
Get exception class type.
string::size_type GetPos(void) const noexcept
Get error position.
int Compare(const T &s1, const T &s2) const
Return difference between "s1" and "s2".
virtual void ReportExtra(ostream &out) const override
Report error position.
void SetEncoder(IStringEncoder *encoder, EOwnership own=eTakeOwnership)
Set string encoder.
static string DedentR(const CTempString str)
const string & GetOriginalString(void) const
Get the original unencoded string.
NCBI_EXCEPTION_DEFAULT2(CStringException, CParseTemplException< CCoreException >, std::string::size_type)
CStringPairs(NStr::EUrlDecode decode_flag, NStr::EUrlEncode encode_flag)
Create parser with the selected URL-encoding/decoding options and default separators.
static string Dedent(const CTempString str, TDedentFlags flags=0)
Dedent multi-line string, removing common whitespace prefix for each line.
EErrCode
Error types that string classes can generate.
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.
static CStringUTF8 AsUTF8(const CTempString &src, const locale &lcl)
Convert into UTF8 from a C/C++ string.
PNocase_Generic< string > PNocase
const char * const_iterator
static SIZE_TYPE GetValidSymbolCount(const CTempString &src)
Get the number of valid UTF-8 symbols (code points) in buffer.
static int HexChar(char ch)
Convert character to integer.
static void ToUpper(const char *)
Privatized ToUpper() with const char* parameter to prevent passing of constant strings.
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
static void Parse(TStrPairs &pairs, const CTempString str, const CTempString arg_sep, const CTempString val_sep, IStringDecoder *decoder=NULL, EOwnership own=eTakeOwnership, NStr::EMergeDelims merge_argsep=NStr::eMergeDelims)
Parse the string using the provided decoder, put data into the container.
virtual ~IStringEncoder(void)
virtual ~IStringDecoder(void)
int TSplitFlags
Bitwise OR of ESplitFlags.
static enable_if< is_integral< typename TStrictId::TId >::value &&is_member_function_pointer< decltype(&TStrictId::Get)>::value, string >::type NumericToString(TStrictId value, TNumToStringFlags flags=0, int base=10)
ETrunc
Which end to truncate a string.
static bool EqualCase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-sensitive equality of a substring with another string.
static basic_string< TChar > x_AsBasicString(const CTempString &src, const TChar *substitute_on_error, EValidate validate)
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.
virtual ~CParseTemplException(void) noexcept
Destructor.
AutoPtr< IStringEncoder > m_Encoder
basic_string< TUnicodeSymbol > TStringUnicode
Unicode string.
const wchar_t *const kEmptyWCStr
bool operator()(const T &s1, const T &s2) const
Return TRUE if s1 < s2 ignoring case.
static TUnicodeSymbol DecodeFirst(char ch, SIZE_TYPE &more)
Begin converting first character of UTF8 sequence into Unicode.
static int strcasecmp(const char *s1, const char *s2)
Case-insensitive comparison of two zero-terminated strings.
EStringType
Type of string to be decoded.
TStringUnicode TStringUCS4
static enable_if< is_integral< TNumeric >::value &&is_signed< TNumeric >::value &&(sizeof(TNumeric)<=sizeof(int) &&!is_same< TNumeric, long >::value), void >::type x_NumericToString(string &out_str, TNumeric value, TNumToStringFlags flags, int base)
static bool x_VerifyFloatLimits(TSource v, const CTempString str, TStringToNumFlags flags)
bool AStrEquiv(const Arg1 &x, const Arg2 &y, Pred pr)
Check equivalence of arguments using predicate.
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.
virtual ~CStringPairs(void)
static SIZE_TYPE FindCase(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 sensitive search.
CStringPairs< TStringPairsVector > CStringPairsParser
static int Compare(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Compare of a substring with another string.
static size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
Wrapper for the function strftime() that corrects handling D and T time formats on MS Windows.
static CStringUTF8 SQLEncode(const CStringUTF8 &str)
Uint2 TCharUCS2
Type for character in UCS-2 encoding.
virtual const CException * x_Clone(void) const override
Helper clone method.
static CStringUTF8 & x_AppendChar(CStringUTF8 &u8str, TUnicodeSymbol ch)
virtual void Append(const string &s)
static enable_if< is_integral< TChar >::value &&(1< sizeof(TChar)), CStringUTF8 & >::type AppendAsUTF8(CStringUTF8 &dest, TChar ch)
Convert Unicode symbol into UTF8 and append it to existing string.
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
bool Equals(const T &s1, const T &s2) const
Return TRUE if s1 == s2.
basic_string< TCharUCS2 > TStringUCS2
Type for string in UCS-2 encoding.
EQuoted
Define that string is quoted or not.
IStringDecoder * GetDecoder(void)
Get decoder or NULL. Does not affect decoder ownership.
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 enable_if< is_integral< TChar >::value &&(1< sizeof(TChar)), CStringUTF8 & >::type AppendAsUTF8(CStringUTF8 &dest, const TChar *src, SIZE_TYPE tchar_count=NCBI_NS_STD::string::npos)
Convert Unicode character buffer into UTF8 and append it to existing string.
static string xx_Join(TIterator from, TIterator to, const CTempString &delim)
virtual void Append(const CTempString &s)=0
EStringType
Type of string to be decoded.
virtual string Decode(const CTempString src, EStringType stype) const =0
Decode the string.
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 bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
PNocase_Conditional_Generic(NStr::ECase case_sens=NStr::eCase)
Construction.
const TStrPairs & GetPairs(void) const
Read data.
static enable_if< is_integral< TChar >::value &&(1< sizeof(TChar)), basic_string< TChar > >::type AsBasicString(const CTempString &src)
bool IsEncoded(void) const
Check if the original string was encoded.
static enable_if< is_integral< typename TStrictId::TId >::value &&is_member_function_pointer< decltype(&TStrictId::Get)>::value, bool >::type x_StringToNumeric(const CTempString str, TStrictId *value, TStringToNumFlags flags, int base)
EHtmlEncode
HTML-decode flags.
bool Equals(const T &s1, const T &s2) const
Return TRUE if s1 == s2.
static enable_if< is_integral< TChar >::value &&(1< sizeof(TChar)), CStringUTF8 >::type AsUTF8(const basic_string< TChar > &src)
Convert into UTF8 from a Unicode C++ string.
bool operator()(const T &s1, const T &s2) const
Return TRUE if s1 < s2.
static TUnicodeSymbol DecodeNext(TUnicodeSymbol chU, char ch)
Convert next character of UTF8 sequence into Unicode.
static SIZE_TYPE FindWord(const CTempString str, const CTempString word, EOccurrence which, ECase use_case=eCase)
Find given word in the string.
static enable_if< is_convertible< TValue, string >::value, string >::type x_Join(TValue *from, TValue *to, const CTempString &delim)
static CStringUTF8 & AppendAsUTF8(CStringUTF8 &dest, char ch, const locale &lcl)
Convert non-Unicode character into UTF8 and append it to existing string.
static bool x_StringToNumeric(const CTempString str, float *value, TStringToNumFlags flags, int)
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.
bool Less(const T &s1, const T &s2) const
Return TRUE if s1 < s2.
size_type length(void) const
Return the length of the represented array.
bool Equals(const T &s1, const T &s2) const
Return TRUE if s1 == s2.
static string ULongToString(unsigned long value, TNumToStringFlags flags=0, int base=10)
Convert unsigned long to string.
static bool x_StringToNumeric(const CTempString str, long *value, TStringToNumFlags flags, int base)
TContainer::value_type TStrPair
The container's value type must be pair<string, string> or a compatible type.
int TSS_Flags
Bitwise OR of ESS_Flags.
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.
static const wstring & Get(void)
Get string.
static string Sanitize(CTempString str, TSS_Flags flags=fSS_print)
Sanitize a string, allowing only specified classes of characters.
PNocase_Conditional_Generic< string > PNocase_Conditional
CTempString substr(size_type pos) const
Obtain a substring from this string, beginning at a given offset.
static CStringUTF8 & AppendAsUTF8(CStringUTF8 &dest, char ch, EEncoding encoding, EValidate validate=eNoValidate)
Convert non-Unicode character into UTF8 and append it to existing string.
bool operator()(const T &s1, const T &s2) const
Return TRUE if s1 < s2 ignoring case.
static CTempString TruncateSpaces(const char *str, ETrunc where=eTrunc_Both)
static void ToLower(const char *)
Privatized ToLower() with const char* parameter to prevent passing of constant strings.
static TUnicodeSymbol Decode(const char *&src)
Convert sequence of UTF8 code units into Unicode code point.
static CStringUTF8 & AppendAsUTF8(CStringUTF8 &dest, const CTempString &src, const locale &lcl)
Convert non-Unicode C++ string into UTF8 and append it to existing string.
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
EHtmlDecode
HTML-decode flags.
void SetCase(NStr::ECase case_sens)
Set comparison type.
ECase
Which type of string comparison.
static int strncmp(const char *s1, const char *s2, size_t n)
String compare up to specified number of characters.
TErrCode GetErrCode(void) const
Get error code.
static enable_if< is_same< typename TIterator::iterator_category, input_iterator_tag >::value &&is_convertible< typename TIterator::value_type, string >::value, string >::type x_Join(TIterator from, TIterator to, const CTempString &delim)
int TWrapFlags
Bitwise OR of "EWrapFlags".
int TStringToNumFlags
Bitwise OR of "EStringToNumFlags".
bool Less(const T &s1, const T &s2) const
Return TRUE if s1 < s2.
NStr::ECase GetCase() const
Get comparison type.
static SIZE_TYPE GetValidBytesCount(const CTempString &src)
Get the number of valid UTF-8 bytes (code units) in buffer.
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.
int Compare(const T &s1, const T &s2) const
Return difference between "s1" and "s2".
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.
EValidate
How to verify character encoding of the source data.
static const string & Get(void)
Get string.
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.
bool operator()(const T &s1, const T &s2) const
Return TRUE if s1 < s2 ignoring case.
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.
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
PNocase_Conditional_Generic< const char * > PNocase_Conditional_CStr
bool operator()(const T &s1, const T &s2) const
Return TRUE if s1 < s2 ignoring case.
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, SIZE_TYPE start)
Wrapper for backward-compatibility.
size_type size(void) const
Return the length of the represented array.
static enable_if< is_integral< TNumeric >::value &&is_signed< TNumeric >::value &&(sizeof(TNumeric)< sizeof(int)), bool >::type x_StringToNumeric(const CTempString str, TNumeric *value, TStringToNumFlags flags, int base)
PCase_Generic< const char * > PCase_CStr
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.
TStringToNumFlags TConvErrFlags
Formerly split out.
PEqualNocase_Conditional_Generic< const char * > PEqualNocase_Conditional_CStr
PEqualNocase_Conditional_Generic(NStr::ECase case_sens=NStr::eCase)
Construction.
EEscSeqRange
C-style escape sequences parsing mode.
static bool EvaluateFirst(char ch, SIZE_TYPE &more)
Check that the character is valid first byte of an UTF8 byte sequence.
static SIZE_TYPE CommonPrefixSize(const CTempString s1, const CTempString s2)
Determine the common prefix of two strings.
const_iterator begin() const
Return an iterator to the string's starting position.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
static int StringToNumeric(const string &str)
@ eEncoding_ISO8859_1
Note: From the point of view of the C++.
@ fDedent_SkipEmptyFirstLine
Ignore first line and skip it from the result, if it is empty only.
@ eSqlEnc_Plain
Always produce '...', with no tag.
@ eUrlEnc_ProcessMarkChars
Convert all non-alphanumeric chars, spaces are converted to '+'.
@ 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.
@ eConvert
Failure to convert string.
@ 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.
@ eNocase
Case insensitive compare.
@ eCase
Case sensitive compare.
@ eEscSeqRange_Throw
Throw an exception.
@ eEscSeqRange_Errno
Set errno to ERANGE, return empty string.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
#define NCBI_XNCBI_EXPORT
unsigned int
A callback function used to compare two keys in a database.
vector< CSeq_align const * >::const_iterator TIterator
const TYPE & Get(const CNamedParameterList *param)
constexpr bool Equal(std::integral_constant< ncbi::NStr::ECase, case_sensitive > tag, const ct_basic_string< _CharType > &l, const ct_basic_string< _CharType > &r)
constexpr int CompareNocase(const std::string_view &l, const std::string_view &r)
double value_type
The numeric datatype used by the parser.
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
int strncmp(const char *str1, const char *str2, size_t count)
int strcmp(const char *str1, const char *str2)
static const BitmapCharRec ch2
Defines NCBI C++ Toolkit portable error codes.
double f(double x_, const double &y_)
static bool IsWhiteSpace(char c)
static const char * suffix[]
static const char * prefix[]
static const char delimiter[]
Define Case-sensitive string comparison methods.
Define Case-insensitive string comparison methods.
PQuickStringLess implements an ordering of strings, that is more efficient than usual lexicographical...
void Encode(const CRawScoreVector< Key, Score > &, vector< char > &)
void Decode(const vector< char > &, CRawScoreVector< Key, Score > &)