stringutil.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef COIL_STRINGUTIL_H
00021 #define COIL_STRINGUTIL_H
00022 
00023 #include <string>
00024 #include <vector>
00025 #include <sstream>
00026 
00027 // Cygwin's gcc does not provide wstring type
00028 #if defined(Cygwin) && ( __GNUC__ < 4 )
00029 namespace std
00030 {
00031   typedef basic_string<wchar_t> wstring;
00032 }
00033 #endif
00034 
00035 namespace coil
00036 {
00037   typedef std::vector<std::string> vstring;
00038 
00058   std::wstring string2wstring(std::string str);
00059 
00079   std::string wstring2string(std::wstring wstr);
00080 
00098   void toUpper(std::string& str);
00099 
00117   void toLower(std::string& str);
00118 
00145   int getlinePortable(std::istream& istr, std::string& line);
00146   
00170   bool isEscaped(const std::string& str, std::string::size_type pos);
00171   
00204   std::string escape(const std::string str);
00205   
00242   std::string unescape(const std::string str);
00243 
00263   void eraseBlank(std::string& str);
00264 
00284   void eraseHeadBlank(std::string& str);
00285   
00306   void eraseTailBlank(std::string& str);
00307 
00328   void eraseBothEndsBlank(std::string& str);
00329 
00351   std::string normalize(std::string& str);
00352   
00374   unsigned int replaceString(std::string& str, const std::string from,
00375                              const std::string to);
00376   
00400   vstring split(const std::string& input,
00401                 const std::string& delimiter,
00402                 bool ignore_empty = false);
00403   
00432   bool toBool(std::string str, std::string yes, std::string no, 
00433               bool default_value = true);
00457   bool includes(const vstring& list, std::string value,
00458                 bool ignore_case = true);
00459 
00483   bool includes(const std::string& list, std::string value,
00484                 bool ignore_case = true);
00485   
00515   bool isAbsolutePath(const std::string& str);
00516   
00542   bool isURL(const std::string& str);
00543   
00565   template <class Printable>
00566   std::string otos(Printable n)
00567   {
00568     std::stringstream str_stream;
00569     str_stream << n;
00570     return str_stream.str();
00571   };
00572   
00596   template <typename To>
00597   bool stringTo(To& val, const char* str)
00598   {
00599     if (str == 0) { return false; }
00600 
00601     std::stringstream s;
00602     if ((s << str).fail()) { return false; }
00603     if ((s >> val).fail()) { return false; }
00604     return true;
00605   }
00606   
00630   template<>
00631   bool stringTo<std::string>(std::string& val, const char* str);
00632 
00655   vstring unique_sv(vstring sv);
00656   
00681   std::string flatten(vstring sv);
00682   
00706   char** toArgv(const vstring& args); 
00707 
00708 
00730   std::string sprintf(char const * __restrict fmt, ...);
00731   
00732 }; // namepsace coil
00733 #endif // COIL_STRINGUTIL_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:07