1 #ifndef FUNCTIONS_STRING_H
2 #define FUNCTIONS_STRING_H
6 #include "functions_type.h"
12 namespace functions_string {
19 inline tString& ltrim(tString& s) {
20 s=std::regex_replace(s, std::regex(
"^\\s+"), std::string(
""));
27 inline tString& rtrim(tString& s) {
28 s=std::regex_replace(s, std::regex(
"\\s+$"), std::string(
""));
36 inline tString& trim(tString& s) {
37 return ltrim(rtrim(s));
46 inline void replaceAll(
const tString& word,
const tString& rWord,tString& str) {
47 tIndex pos = str.find(word);
48 tIndex lWord=word.length();
49 tIndex lrWord=rWord.length();
51 while( pos != std::string::npos)
54 str.replace(pos, lWord , rWord);
56 pos =str.find(word, pos + lrWord);
65 inline void replace(
const tString& word,
const tString& rWord,tString& str) {
66 tIndex pos = str.find(word);
67 tIndex lWord=word.length();
69 if ( pos != std::string::npos) {
71 str.replace(pos, lWord , rWord);
78 inline void toLower(tString& s) {
79 std::transform(s.cbegin(), s.cend(), s.begin(),
80 [](
unsigned char c){ return std::tolower(c);});
85 inline void toUpper(tString& s) {
87 std::transform(s.cbegin(), s.cend(), s.begin(),
88 [](
unsigned char c){ return std::toupper(c);});
97 inline void tokenize(tString& str,
99 std::vector<tString>& words) {
104 while ( (token = strtok_r(rest,delim.c_str(),&rest))) {
106 words.push_back(trim(word));