72 typedef std::string tstring; 73 typedef std::ostringstream tostringstream; 74 typedef std::istringstream tistringstream; 75 typedef std::stringstream tstringstream; 76 typedef std::istream tistream; 77 typedef std::ostream tostream; 78 typedef std::iostream tiostream; 79 typedef std::ios tios; 80 81 typedef const char* LPCTSTR; 82 typedef char TCHAR; 83 #endif 84 85 // frequently used "array of tstrings" type 86 typedef std::vector<tstring> tstring_array; 87 88 namespace tstrings { 89 tstring unsafe_format(tstring::const_pointer format, ...); 90 91 enum CompareType {CASE_SENSITIVE, IGNORE_CASE}; 92 bool equals(const tstring& a, const tstring& b, const CompareType ct=CASE_SENSITIVE); 93 bool startsWith(const tstring &str, const tstring &substr, const CompareType ct=CASE_SENSITIVE); 94 bool endsWith(const tstring &str, const tstring &substr, const CompareType ct=CASE_SENSITIVE); 95 96 enum SplitType {ST_ALL, ST_EXCEPT_EMPTY_STRING}; 97 void split(tstring_array &strVector, const tstring &str, 98 const tstring &delimiter, const SplitType st = ST_ALL); 99 inline tstring_array split(const tstring &str, const tstring &delimiter, const SplitType st = ST_ALL) { 100 tstring_array result; 101 split(result, str, delimiter, st); 102 return result; 103 } 104 tstring trim(const tstring& str, const tstring& whitespace = _T(" \t")); 105 106 /** 107 * Writes sequence of values from [b, e) range into string buffer inserting 108 * 'delimiter' after each value except of the last one. 109 * Returns contents of string buffer. 110 */ 111 template <class It> 112 tstring join(It b, It e, const tstring& delimiter=tstring()) { 113 tostringstream buf; 114 if (b != e) { 115 for (;;) { 116 buf << *b; 117 if (++b == e) { 118 break; 119 } 120 buf << delimiter; 121 } 122 } 123 return buf.str(); 124 } 125 126 tstring toLower(const tstring& str); 127 128 tstring replace(const tstring &str, const tstring &search, const tstring &replace); 129 } 130 131 132 namespace tstrings { 133 inline std::string toUtf8(const std::string& utf8str) { return utf8str; } 134 135 #ifdef TSTRINGS_WITH_WCHAR 136 // conversion to Utf8 137 std::string toUtf8(const std::wstring& utf16str); 138 139 // conversion to Utf16 140 std::wstring toUtf16(const std::string& utf8str); 141 142 inline std::wstring fromUtf8(const std::string& utf8str) { return toUtf16(utf8str); } 143 144 #else 145 inline std::string fromUtf8(const std::string& utf8str) { return utf8str; } 146 #endif 147 } // namespace tstrings 148 149 150 namespace tstrings { 151 namespace format_detail { 152 153 template <class T> 154 struct str_arg_value { 155 const tstring value; 156 157 str_arg_value(const std::string& v): value(fromUtf8(v)) { 158 } 159 160 #ifdef TSTRINGS_WITH_WCHAR 161 str_arg_value(const std::wstring& v): value(v) { 162 } 163 #endif 164 165 tstring::const_pointer operator () () const { | 72 typedef std::string tstring; 73 typedef std::ostringstream tostringstream; 74 typedef std::istringstream tistringstream; 75 typedef std::stringstream tstringstream; 76 typedef std::istream tistream; 77 typedef std::ostream tostream; 78 typedef std::iostream tiostream; 79 typedef std::ios tios; 80 81 typedef const char* LPCTSTR; 82 typedef char TCHAR; 83 #endif 84 85 // frequently used "array of tstrings" type 86 typedef std::vector<tstring> tstring_array; 87 88 namespace tstrings { 89 tstring unsafe_format(tstring::const_pointer format, ...); 90 91 enum CompareType {CASE_SENSITIVE, IGNORE_CASE}; 92 bool equals(const tstring& a, const tstring& b, 93 const CompareType ct=CASE_SENSITIVE); 94 bool startsWith(const tstring &str, const tstring &substr, 95 const CompareType ct=CASE_SENSITIVE); 96 bool endsWith(const tstring &str, const tstring &substr, 97 const CompareType ct=CASE_SENSITIVE); 98 99 enum SplitType {ST_ALL, ST_EXCEPT_EMPTY_STRING}; 100 void split(tstring_array &strVector, const tstring &str, 101 const tstring &delimiter, const SplitType st = ST_ALL); 102 inline tstring_array split(const tstring &str, const tstring &delimiter, 103 const SplitType st = ST_ALL) { 104 tstring_array result; 105 split(result, str, delimiter, st); 106 return result; 107 } 108 tstring trim(const tstring& str, const tstring& whitespace = _T(" \t")); 109 110 /** 111 * Writes sequence of values from [b, e) range into string buffer inserting 112 * 'delimiter' after each value except of the last one. 113 * Returns contents of string buffer. 114 */ 115 template <class It> 116 tstring join(It b, It e, const tstring& delimiter=tstring()) { 117 tostringstream buf; 118 if (b != e) { 119 for (;;) { 120 buf << *b; 121 if (++b == e) { 122 break; 123 } 124 buf << delimiter; 125 } 126 } 127 return buf.str(); 128 } 129 130 tstring toLower(const tstring& str); 131 132 tstring replace(const tstring &str, const tstring &search, 133 const tstring &replace); 134 } 135 136 137 namespace tstrings { 138 inline std::string toUtf8(const std::string& utf8str) { 139 return utf8str; 140 } 141 142 #ifdef TSTRINGS_WITH_WCHAR 143 // conversion to Utf8 144 std::string toUtf8(const std::wstring& utf16str); 145 146 // conversion to Utf16 147 std::wstring toUtf16(const std::string& utf8str); 148 149 inline std::wstring fromUtf8(const std::string& utf8str) { 150 return toUtf16(utf8str); 151 } 152 153 #else 154 inline std::string fromUtf8(const std::string& utf8str) { 155 return utf8str; 156 } 157 #endif 158 } // namespace tstrings 159 160 161 namespace tstrings { 162 namespace format_detail { 163 164 template <class T> 165 struct str_arg_value { 166 const tstring value; 167 168 str_arg_value(const std::string& v): value(fromUtf8(v)) { 169 } 170 171 #ifdef TSTRINGS_WITH_WCHAR 172 str_arg_value(const std::wstring& v): value(v) { 173 } 174 #endif 175 176 tstring::const_pointer operator () () const { |