26 #include <coil/stringutil.h> 42 std::wstring wstr(str.length(), L
' ');
43 std::copy(str.begin(),str.end(),wstr.begin());
56 std::string str(wstr.length(),
' ');
57 std::copy(wstr.begin(), wstr.end(), str.begin());
70 std::transform(str.begin(), str.end(), str.begin(),
71 (int (*)(int))std::toupper);
83 std::transform(str.begin(), str.end(), str.begin(),
84 (int (*)(int))std::tolower);
107 if (istr.peek() ==
'\n')
119 return static_cast<int>(line.size());
129 bool isEscaped(
const std::string& str, std::string::size_type pos)
133 for (i = 0; (pos >= 0) && str[pos] ==
'\\'; --pos, ++i) ;
150 if (c ==
'\t')
str +=
"\\t";
151 else if (c ==
'\n')
str +=
"\\n";
152 else if (c ==
'\f')
str +=
"\\f";
153 else if (c ==
'\r')
str +=
"\\r";
154 else if (c ==
'\\')
str +=
"\\\\";
157 else str.push_back(c);
196 if (count > 0 && (count % 2))
199 if (c ==
't')
str.push_back(
'\t');
200 else if (c ==
'n')
str.push_back(
'\n');
201 else if (c ==
'f')
str.push_back(
'\f');
202 else if (c ==
'r')
str.push_back(
'\r');
203 else if (c ==
'\"')
str.push_back(
'\"');
204 else if (c ==
'\'')
str.push_back(
'\'');
205 else str.push_back(c);
239 std::string::iterator it(str.begin());
241 while (it != str.end())
243 if (*it ==
' ' || *it ==
'\t')
264 if (str.empty())
return;
265 while (str[0] ==
' ' || str[0] ==
'\t') str.erase(0, 1);
277 if (str.empty())
return;
278 while ((str[str.size() - 1] ==
' ' || str[str.size() - 1] ==
'\t') &&
280 str.erase(str.size() - 1, 1);
318 const std::string to)
320 std::string::size_type pos(0);
323 while (pos != std::string::npos)
325 pos = str.find(from, pos);
326 if (pos == std::string::npos)
break;
327 str.replace(pos, from.size(), to);
342 const std::string& delimiter,
345 typedef std::string::size_type size;
347 size delim_size = delimiter.size();
348 size found_pos(0), begin_pos(0), pre_pos(0), substr_size(0);
350 if (input.empty())
return results;
358 found_pos = input.find(delimiter, begin_pos);
359 if (found_pos == std::string::npos)
361 std::string substr(input.substr(pre_pos));
364 if (!(substr.empty() && ignore_empty)) results.push_back(substr);
374 substr_size = found_pos - pre_pos;
375 if (substr_size >= 0)
377 std::string substr(input.substr(pre_pos, substr_size));
380 if (!(substr.empty() && ignore_empty)) results.push_back(substr);
382 begin_pos = found_pos + delim_size;
383 pre_pos = found_pos + delim_size;
410 bool toBool(std::string
str, std::string yes, std::string no,
417 if (str.find(yes) != std::string::npos)
419 else if (str.find(no) != std::string::npos)
422 return default_value;
434 if (ignore_case) {
toLower(value); }
436 for (
int i(0), len(static_cast<int>(list.size())); i < len; ++i)
438 std::string
str(list[i]);
439 if (ignore_case) {
toLower(str); }
440 if (str == value)
return true;
452 bool includes(
const std::string& list, std::string value,
bool ignore_case)
455 return includes(vlist, value, ignore_case);
468 if (str[0] ==
'/')
return true;
470 if (isalpha(str[0]) && (str[1] ==
':') && str[2] ==
'\\')
return true;
472 if (str[0] ==
'\\' && str[1] ==
'\\')
return true;
486 typedef std::string::size_type size;
488 if (str.empty())
return false;
491 (pos != std::string::npos) &&
492 (str[pos + 1] ==
'/') &&
493 (str[pos + 2] ==
'/'))
510 return str.push_back(s);
523 bool stringTo<std::string>(std::string& val,
const char*
str)
525 if (
str == 0) {
return false; }
551 if (sv.size() == 0)
return "";
554 for (
size_t i(0), len(sv.size() - 1); i < len; ++i)
558 return str + sv.back();
571 size_t argc(args.size());
573 argv =
new char*[argc + 1];
575 for (
size_t i(0); i < argc; ++i)
577 size_t sz(args[i].size());
578 argv[i] =
new char[sz + 1];
579 strncpy(argv[i], args[i].c_str(), sz);
593 std::string
sprintf(
char const * __restrict fmt, ...)
596 #define LINE_MAX 1024 603 _vsnprintf(str,
LINE_MAX - 1, fmt, ap);
605 vsnprintf(str,
LINE_MAX - 1, fmt, ap);
608 return std::string(str);
std::string normalize(std::string &str)
Erase the head/tail blank and replace upper case to lower case.
void operator()(const std::string &s)
void toUpper(std::string &str)
Uppercase String Transformation.
void eraseBlank(std::string &str)
Erase blank characters of string.
void eraseHeadBlank(std::string &str)
Erase the head blank characters of string.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
vstring unique_sv(vstring sv)
Eliminate duplication from the given string list.
void operator()(const char c)
void eraseBothEndsBlank(std::string &str)
Erase the head blank and the tail blank characters of string.
bool isAbsolutePath(const std::string &str)
Investigate whether the given string is absolute path or not.
std::vector< std::string > vstring
void eraseTailBlank(std::string &str)
Erase the tail blank characters of string.
std::string flatten(vstring sv)
Create CSV file from the given string list.
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
char ** toArgv(const vstring &args)
Convert the given string list into the argument list.
bool isURL(const std::string &str)
Investigate whether the given string is URL or not.
Functor to escape string.
unsigned int replaceString(std::string &str, const std::string from, const std::string to)
Replace string.
void toLower(std::string &str)
Lowercase String Transformation.
bool toBool(std::string str, std::string yes, std::string no, bool default_value)
Convert given string into bool value.
std::string wstring2string(std::wstring wstr)
wstring to string conversion
int getlinePortable(std::istream &istr, std::string &line)
Read a line from input stream.
std::string sprintf(char const *__restrict fmt,...)
Convert it into a format given with an argumen.
std::wstring string2wstring(std::string str)
string to wstring conversion
bool isEscaped(const std::string &str, std::string::size_type pos)
Check whether the character is escaped or not.
Functor to unescape string.
bool includes(const vstring &list, std::string value, bool ignore_case)
Include if a string is included in string list.
std::string unescape(const std::string str)
Unescape string.
Functor for_each(CorbaSequence &seq, Functor f)
Apply the functor to all CORBA sequence elements.
std::string escape(const std::string str)
Escape string.
Functor to convert to capital letters.
Common Object Interface Layer.
Functor to find string in a list.