00001
00020 #ifndef COIL_STRINGUTIL_H
00021 #define COIL_STRINGUTIL_H
00022
00023 #include <string>
00024 #include <vector>
00025 #include <sstream>
00026
00027 namespace coil
00028 {
00029 typedef std::vector<std::string> vstring;
00030
00050 std::wstring string2wstring(std::string str);
00051
00071 std::string wstring2string(std::wstring wstr);
00072
00090 void toUpper(std::string& str);
00091
00109 void toLower(std::string& str);
00110
00137 int getlinePortable(std::istream& istr, std::string& line);
00138
00162 bool isEscaped(const std::string& str, std::string::size_type pos);
00163
00196 std::string escape(const std::string str);
00197
00234 std::string unescape(const std::string str);
00235
00255 void eraseBlank(std::string& str);
00256
00276 void eraseHeadBlank(std::string& str);
00277
00298 void eraseTailBlank(std::string& str);
00299
00320 void eraseBothEndsBlank(std::string& str);
00321
00343 std::string normalize(std::string& str);
00344
00366 void replaceString(std::string& str, const std::string from,
00367 const std::string to);
00368
00392 vstring split(const std::string& input,
00393 const std::string& delimiter,
00394 bool ignore_empty = false);
00395
00424 bool toBool(std::string str, std::string yes, std::string no,
00425 bool default_value = true);
00449 bool includes(const vstring& list, std::string value,
00450 bool ignore_case = true);
00451
00475 bool includes(const std::string& list, std::string value,
00476 bool ignore_case = true);
00477
00507 bool isAbsolutePath(const std::string& str);
00508
00534 bool isURL(const std::string& str);
00535
00557 template <class Printable>
00558 std::string otos(Printable n)
00559 {
00560 std::stringstream str_stream;
00561 str_stream << n;
00562 return str_stream.str();
00563 };
00564
00588 template <typename To>
00589 bool stringTo(To& val, const char* str)
00590 {
00591 if (str == 0) { return false; }
00592
00593 std::stringstream s;
00594 if ((s << str).fail()) { return false; }
00595 if ((s >> val).fail()) { return false; }
00596 return true;
00597 }
00598
00622 template<>
00623 bool stringTo<std::string>(std::string& val, const char* str);
00624
00647 vstring unique_sv(vstring sv);
00648
00673 std::string flatten(vstring sv);
00674
00698 char** toArgv(const vstring& args);
00699
00700
00722 std::string sprintf(char const * __restrict fmt, ...);
00723
00724 };
00725 #endif // COIL_STRINGUTIL_H