| 55 | } |
| 56 | |
| 57 | void trim(std::string &s) |
| 58 | { |
| 59 | if (s.empty()) return; |
| 60 | unsigned int pos1 = 0, pos2 = (unsigned int) s.size() - 1; |
| 61 | while ((pos1 < s.size()) && s[pos1] < 33) ++pos1; |
| 62 | while ((pos2 > 0) && s[pos2] < 33) --pos2; |
| 63 | ++pos2; |
| 64 | if (pos2 > pos1) s = std::string(s.begin() + pos1, s.begin() + pos2); |
| 65 | } |
| 66 | |
| 67 | void replaceAll(std::string& s, const std::string& item, const std::string& replacement) { |
| 68 | size_t pos = 0; |