Changeset 1016 for cpp/common/util-string.cpp
- Timestamp:
- 07/20/20 14:15:14 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/util-string.cpp
r913 r1016 79 79 bool str_starts_with(const char *str, const char *prefix) 80 80 { 81 return strncmp(str, prefix,strlen(prefix))==0;81 return strncmp(str, prefix, strlen(prefix)) == 0; 82 82 } 83 83 … … 132 132 return filename.substr(0, slash); 133 133 } 134 135 //trimming functions, https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring 136 137 void ltrim_inplace(string &s) 138 { 139 s.erase(s.begin(), find_if(s.begin(), s.end(), [](int ch) { 140 return !isspace(ch); 141 })); 142 } 143 144 void rtrim_inplace(string &s) 145 { 146 s.erase(find_if(s.rbegin(), s.rend(), [](int ch) { 147 return !isspace(ch); 148 }).base(), s.end()); 149 } 150 151 void trim_inplace(string &s) 152 { 153 ltrim_inplace(s); 154 rtrim_inplace(s); 155 } 156 157 string ltrim(string s) 158 { 159 ltrim_inplace(s); 160 return s; 161 } 162 163 string rtrim(string s) 164 { 165 rtrim_inplace(s); 166 return s; 167 } 168 169 string trim(string s) 170 { 171 trim_inplace(s); 172 return s; 173 }
Note: See TracChangeset
for help on using the changeset viewer.