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 bool includes(const std::string& list, std::string value,
00452 bool ignore_case = true);
00453
00483 bool isAbsolutePath(const std::string& str);
00484
00510 bool isURL(const std::string& str);
00511
00533 template <class Printable>
00534 std::string otos(Printable n)
00535 {
00536 std::stringstream str_stream;
00537 str_stream << n;
00538 return str_stream.str();
00539 };
00540
00564 template <typename To>
00565 bool stringTo(To& val, const char* str)
00566 {
00567 if (str == 0) { return false; }
00568
00569 std::stringstream s;
00570 if ((s << str).fail()) { return false; }
00571 if ((s >> val).fail()) { return false; }
00572 return true;
00573 }
00574
00575 template<>
00576 bool stringTo<std::string>(std::string& val, const char* str);
00577
00600 vstring unique_sv(vstring sv);
00601
00626 std::string flatten(vstring sv);
00627
00651 char** toArgv(const vstring& args);
00652
00653
00654 std::string sprintf(char const * __restrict fmt, ...);
00655
00656 };
00657 #endif // COIL_STRINGUTIL_H