stringutil.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef COIL_STRINGUTIL_H
21 #define COIL_STRINGUTIL_H
22 
23 #include <string>
24 #include <vector>
25 #include <sstream>
26 
27 // Cygwin's gcc does not provide wstring type
28 #if defined(Cygwin) && ( __GNUC__ < 4 )
29 namespace std
30 {
31  typedef basic_string<wchar_t> wstring;
32 }
33 #endif
34 
35 namespace coil
36 {
37  typedef std::vector<std::string> vstring;
38 
58  std::wstring string2wstring(std::string str);
59 
79  std::string wstring2string(std::wstring wstr);
80 
98  void toUpper(std::string& str);
99 
117  void toLower(std::string& str);
118 
145  int getlinePortable(std::istream& istr, std::string& line);
146 
170  bool isEscaped(const std::string& str, std::string::size_type pos);
171 
204  std::string escape(const std::string str);
205 
242  std::string unescape(const std::string str);
243 
263  void eraseBlank(std::string& str);
264 
284  void eraseHeadBlank(std::string& str);
285 
306  void eraseTailBlank(std::string& str);
307 
328  void eraseBothEndsBlank(std::string& str);
329 
351  std::string normalize(std::string& str);
352 
374  unsigned int replaceString(std::string& str, const std::string from,
375  const std::string to);
376 
400  vstring split(const std::string& input,
401  const std::string& delimiter,
402  bool ignore_empty = false);
403 
432  bool toBool(std::string str, std::string yes, std::string no,
433  bool default_value = true);
457  bool includes(const vstring& list, std::string value,
458  bool ignore_case = true);
459 
483  bool includes(const std::string& list, std::string value,
484  bool ignore_case = true);
485 
515  bool isAbsolutePath(const std::string& str);
516 
542  bool isURL(const std::string& str);
543 
565  template <class Printable>
566  std::string otos(Printable n)
567  {
568  std::stringstream str_stream;
569  str_stream << n;
570  return str_stream.str();
571  };
572 
596  template <typename To>
597  bool stringTo(To& val, const char* str)
598  {
599  if (str == 0) { return false; }
600 
601  std::stringstream s;
602  if ((s << str).fail()) { return false; }
603  if ((s >> val).fail()) { return false; }
604  return true;
605  }
606 
630  template<>
631  bool stringTo<std::string>(std::string& val, const char* str);
632 
655  vstring unique_sv(vstring sv);
656 
681  std::string flatten(vstring sv);
682 
706  char** toArgv(const vstring& args);
707 
708 
730  std::string sprintf(char const * __restrict fmt, ...);
731 
732 }; // namepsace coil
733 #endif // COIL_STRINGUTIL_H
std::string normalize(std::string &str)
Erase the head/tail blank and replace upper case to lower case.
Definition: stringutil.cpp:308
void toUpper(std::string &str)
Uppercase String Transformation.
Definition: stringutil.cpp:73
std::string otos(Printable n)
Convert the given object to std::string.
Definition: stringutil.h:566
bool stringTo(To &val, const char *str)
Convert the given std::string to object.
Definition: stringutil.h:597
void eraseBlank(std::string &str)
Erase blank characters of string.
Definition: stringutil.cpp:242
void eraseHeadBlank(std::string &str)
Erase the head blank characters of string.
Definition: stringutil.cpp:267
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:346
vstring unique_sv(vstring sv)
Eliminate duplication from the given string list.
Definition: stringutil.cpp:542
void eraseBothEndsBlank(std::string &str)
Erase the head blank and the tail blank characters of string.
Definition: stringutil.cpp:295
bool isAbsolutePath(const std::string &str)
Investigate whether the given string is absolute path or not.
Definition: stringutil.cpp:470
std::vector< std::string > vstring
Definition: stringutil.h:37
void eraseTailBlank(std::string &str)
Erase the tail blank characters of string.
Definition: stringutil.cpp:280
std::string flatten(vstring sv)
Create CSV file from the given string list.
Definition: stringutil.cpp:554
char ** toArgv(const vstring &args)
Convert the given string list into the argument list.
Definition: stringutil.cpp:573
bool isURL(const std::string &str)
Investigate whether the given string is URL or not.
Definition: stringutil.cpp:489
unsigned int replaceString(std::string &str, const std::string from, const std::string to)
Replace string.
Definition: stringutil.cpp:322
void toLower(std::string &str)
Lowercase String Transformation.
Definition: stringutil.cpp:86
bool toBool(std::string str, std::string yes, std::string no, bool default_value)
Convert given string into bool value.
Definition: stringutil.cpp:415
std::string wstring2string(std::wstring wstr)
wstring to string conversion
Definition: stringutil.cpp:59
int getlinePortable(std::istream &istr, std::string &line)
Read a line from input stream.
Definition: stringutil.cpp:99
std::string sprintf(char const *__restrict fmt,...)
Convert it into a format given with an argumen.
Definition: stringutil.cpp:598
std::wstring string2wstring(std::string str)
string to wstring conversion
Definition: stringutil.cpp:45
bool isEscaped(const std::string &str, std::string::size_type pos)
Check whether the character is escaped or not.
Definition: stringutil.cpp:134
bool includes(const vstring &list, std::string value, bool ignore_case)
Include if a string is included in string list.
Definition: stringutil.cpp:437
std::string unescape(const std::string str)
Unescape string.
Definition: stringutil.cpp:230
std::string escape(const std::string str)
Escape string.
Definition: stringutil.cpp:174
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:45