19 void tokenize(
const string& str,
const string& delimiters, vector< string >& tokens )
22 string::size_type begin = str.find_first_not_of( delimiters, 0 );
23 string::size_type end = str.find_first_of( delimiters, begin );
25 while ( string::npos != begin || string::npos != end )
28 tokens.push_back( str.substr( begin, end - begin ) );
31 begin = str.find_first_not_of( delimiters, end );
32 end = str.find_first_of( delimiters, begin );
38 for (
size_t pos = arg.find(
' '); pos != string::npos; pos = arg.find(
' '))
40 arg.replace(pos, 1, 1,
'_');
42 for (
size_t pos = arg.find(
'<'); pos != string::npos; pos = arg.find(
'<'))
44 arg.replace(pos, 1, 1,
'_');
46 for (
size_t pos = arg.find(
'>'); pos != string::npos; pos = arg.find(
'>'))
48 arg.replace(pos, 1, 1,
'_');
53 std::string
trim(
const std::string myString,
const string& delimiters)
55 if (myString.length() == 0 )
60 string::size_type end = myString.find_last_not_of(delimiters);
61 string::size_type begin = myString.find_first_not_of(delimiters);
63 if(begin != string::npos)
65 return std::string(myString, begin, end-begin+1);
71 std::string
fix(
const std::string userPath,
const string& delimiters)
73 string trimmedPath =
trim(userPath, delimiters);
80 for(
unsigned int i = 0; i < trimmedPath.size(); ++i)
82 const char c = trimmedPath[i];
83 if(c !=
'/' || c != prev)
84 fixedPath.push_back(c);
93 std::string testStrings [] =
95 " space at beginning",
97 " space at both sides ",
100 "\ttab at both sides\t",
101 "\nnewline at beginning",
103 "\nnewline at both sides\n",
104 "\n\tnewline and tab at beginning",
105 "space and tab at end \t",
106 " \rtab and return at both sides \r"
109 std::string results[] =
111 "space at beginning",
113 "space at both sides",
117 "newline at beginning",
119 "newline at both sides",
120 "newline and tab at beginning",
121 "space and tab at end",
122 "tab and return at both sides"
127 for (
unsigned int i = 0; i <
sizeof(testStrings)/
sizeof(*testStrings); ++i )
129 std::string trimmed =
trim(testStrings[i]);
130 success = (results[i].compare(trimmed)==0);
132 cout <<
"'" << trimmed <<
"'" << (success ?
" SUCCESS":
"FAILED") << endl;
138 bool endswith(
const string & full,
const string & ending)
140 if (full.length() < ending.length())
144 return (0 == full.compare(full.length() - ending.length(), ending.length(), ending));
150 for(
size_t i = 0; i < std::min(n, b.size()); ++i )
151 if( tolower(a[i]) != tolower(b[i]) )
152 return tolower(a[i]) - tolower(b[i]);
155 return a.size() - b.size();
164 static const char alphanum[] =
166 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
167 "abcdefghijklmnopqrstuvwxyz";
170 for (
unsigned i = 0; i < len; ++i)
172 s[i] = alphanum[rand() % (
sizeof(alphanum) - 1)];
bool endswith(const string &full, const string &ending)
int strncasecmp(const string &a, const string &b, size_t n)
Compares the two strings a and b for first n characters, ignoring the case of the characters...
std::string fix(const std::string userPath, const string &delimiters)
string & clean_type_name(string &arg)
void tokenize(const string &str, const string &delimiters, vector< string > &tokens)
std::string trim(const std::string myString, const string &delimiters)
string random_string(const unsigned len)