an analogue of tr/$from/$to/
| 157 | |
| 158 | // an analogue of tr/$from/$to/ |
| 159 | class Tr { |
| 160 | public: |
| 161 | Tr(const char* from, const char* to); |
| 162 | |
| 163 | char ConvertChar(char ch) const { |
| 164 | return Map[(ui8)ch]; |
| 165 | } |
| 166 | |
| 167 | void Do(char* s) const { |
| 168 | for (; *s; s++) { |
| 169 | *s = ConvertChar(*s); |
| 170 | } |
| 171 | } |
| 172 | void Do(const char* src, char* dst) const { |
| 173 | for (; *src; src++) { |
| 174 | *dst++ = ConvertChar(*src); |
| 175 | } |
| 176 | *dst = 0; |
| 177 | } |
| 178 | void Do(char* s, size_t l) const { |
| 179 | for (size_t i = 0; i < l && s[i]; i++) { |
| 180 | s[i] = ConvertChar(s[i]); |
| 181 | } |
| 182 | } |
| 183 | void Do(TString& str) const; |
| 184 | |
| 185 | private: |
| 186 | char Map[256]; |
| 187 | |
| 188 | size_t FindFirstChangePosition(const TString& str) const; |
| 189 | }; |
| 190 | |
| 191 | // Removes all occurrences of given character from string |
| 192 | template <typename TStringType> |
no outgoing calls
no test coverage detected