1 /////////////////////////////////////////////////////////////////////////////
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 /////////////////////////////////////////////////////////////////////////////
19 * @file UnicodeString.h
21 * @brief Unicode string based on std::wstring.
40 # ifndef _TCHAR_DEFINED
42 typedef wchar_t TCHAR;
47 # define _TCHAR_DEFINED
51 #define std_tchar(type) std::w##type
53 #define std_tchar(type) std::type
56 typedef std_tchar(string) String;
61 String makelower(const String &str);
62 String makeupper(const String &str);
64 void replace(String &target, const String &find, const String &replace);
67 int compare_nocase(const String &str1, const String &str2);
70 String trim_ws(const String & str);
71 String trim_ws_begin(const String & str);
72 String trim_ws_end(const String & str);
75 String format_arg_list(const TCHAR *fmt, va_list args);
76 String format(const TCHAR *fmt, ...);
77 String format_strings(const String& fmt, const String *args[], size_t nargs);
78 String format_string1(const String& fmt, const String& arg1);
79 String format_string2(const String& fmt, const String& arg1, const String& arg2);
81 template <class InputIterator>
82 String join(const InputIterator& begin, const InputIterator& end, const String& delim)
84 size_t sum = 0, delim_len = delim.length();
85 for (InputIterator it = begin; it != end; ++it)
87 if (sum != 0) sum += delim_len;
88 sum += (*it).length();
92 for (InputIterator it = begin; it != end; ++it)
94 if (!result.empty()) result.append(delim);
100 template <class Formatter, class InputIterator>
101 String join(const InputIterator& begin, const InputIterator& end, const String& delim, Formatter func)
104 for (InputIterator it = begin; it != end; ++it)
106 if (!result.empty()) result.append(delim);
112 inline String to_str(int val) { return strutils::format(_T("%d"), val); }
113 inline String to_str(unsigned val) { return strutils::format(_T("%u"), val); }
114 inline String to_str(long val) { return strutils::format(_T("%ld"), val); }
115 inline String to_str(unsigned long val) { return strutils::format(_T("%lu"), val); }
116 inline String to_str(long long val) { return strutils::format(_T("%I64d"), val); }
117 inline String to_str(unsigned long long val) { return strutils::format(_T("%I64u"), val); }
118 inline String to_str(float val) { return strutils::format(_T("%f"), val); }
119 inline String to_str(double val) { return strutils::format(_T("%f"), val); }