26 #include <coil/stringutil.h> 47 std::wstring wstr(str.length(), L
' ');
48 std::copy(str.begin(),str.end(),wstr.begin());
61 std::string str(wstr.length(),
' ');
62 std::copy(wstr.begin(), wstr.end(), str.begin());
75 std::transform(str.begin(), str.end(), str.begin(),
76 (int (*)(int))std::toupper);
88 std::transform(str.begin(), str.end(), str.begin(),
89 (int (*)(int))std::tolower);
112 if (istr.peek() ==
'\n')
124 return static_cast<int>(line.size());
134 bool isEscaped(
const std::string& str, std::string::size_type pos)
138 for (i = 0; (pos >= 0) && str[pos] ==
'\\'; --pos, ++i) ;
155 if (c ==
'\t')
str +=
"\\t";
156 else if (c ==
'\n')
str +=
"\\n";
157 else if (c ==
'\f')
str +=
"\\f";
158 else if (c ==
'\r')
str +=
"\\r";
159 else if (c ==
'\\')
str +=
"\\\\";
162 else str.push_back(c);
201 if (count > 0 && (count % 2))
204 if (c ==
't')
str.push_back(
'\t');
205 else if (c ==
'n')
str.push_back(
'\n');
206 else if (c ==
'f')
str.push_back(
'\f');
207 else if (c ==
'r')
str.push_back(
'\r');
208 else if (c ==
'\"')
str.push_back(
'\"');
209 else if (c ==
'\'')
str.push_back(
'\'');
210 else str.push_back(c);
244 std::string::iterator it(str.begin());
246 while (it != str.end())
248 if (*it ==
' ' || *it ==
'\t')
269 if (str.empty())
return;
270 while (str[0] ==
' ' || str[0] ==
'\t') str.erase(0, 1);
282 if (str.empty())
return;
283 while ((str[str.size() - 1] ==
' ' || str[str.size() - 1] ==
'\t') &&
285 str.erase(str.size() - 1, 1);
323 const std::string to)
325 std::string::size_type pos(0);
328 while (pos != std::string::npos)
330 pos = str.find(from, pos);
331 if (pos == std::string::npos)
break;
332 str.replace(pos, from.size(), to);
347 const std::string& delimiter,
350 typedef std::string::size_type size;
352 size delim_size = delimiter.size();
353 size found_pos(0), begin_pos(0), pre_pos(0), substr_size(0);
355 if (input.empty())
return results;
363 found_pos = input.find(delimiter, begin_pos);
364 if (found_pos == std::string::npos)
366 std::string substr(input.substr(pre_pos));
369 if (!(substr.empty() && ignore_empty)) results.push_back(substr);
379 substr_size = found_pos - pre_pos;
380 if (substr_size >= 0)
382 std::string substr(input.substr(pre_pos, substr_size));
385 if (!(substr.empty() && ignore_empty)) results.push_back(substr);
387 begin_pos = found_pos + delim_size;
388 pre_pos = found_pos + delim_size;
415 bool toBool(std::string
str, std::string yes, std::string no,
422 if (str.find(yes) != std::string::npos)
424 else if (str.find(no) != std::string::npos)
427 return default_value;
439 if (ignore_case) {
toLower(value); }
441 for (
int i(0), len(static_cast<int>(list.size())); i < len; ++i)
443 std::string
str(list[i]);
444 if (ignore_case) {
toLower(str); }
445 if (str == value)
return true;
457 bool includes(
const std::string& list, std::string value,
bool ignore_case)
460 return includes(vlist, value, ignore_case);
473 if (str[0] ==
'/')
return true;
475 if (isalpha(str[0]) && (str[1] ==
':') && str[2] ==
'\\')
return true;
477 if (str[0] ==
'\\' && str[1] ==
'\\')
return true;
491 typedef std::string::size_type size;
493 if (str.empty())
return false;
496 (pos != std::string::npos) &&
497 (str[pos + 1] ==
'/') &&
498 (str[pos + 2] ==
'/'))
515 return str.push_back(s);
528 bool stringTo<std::string>(std::string& val,
const char*
str)
530 if (
str == 0) {
return false; }
556 if (sv.size() == 0)
return "";
559 for (
size_t i(0), len(sv.size() - 1); i < len; ++i)
563 return str + sv.back();
576 size_t argc(args.size());
578 argv =
new char*[argc + 1];
580 for (
size_t i(0); i < argc; ++i)
582 size_t sz(args[i].size());
583 argv[i] =
new char[sz + 1];
584 strncpy(argv[i], args[i].c_str(), sz);
598 std::string
sprintf(
char const * __restrict fmt, ...)
601 #define LINE_MAX 1024 608 _vsnprintf(str,
LINE_MAX - 1, fmt, ap);
610 vsnprintf(str,
LINE_MAX - 1, fmt, ap);
613 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.