| 834 | } |
| 835 | |
| 836 | std::string string_replace( std::string text, const std::string &before, const std::string &after ) |
| 837 | { |
| 838 | // Check if there's something to replace (mandatory) and it's necessary (optional) |
| 839 | // Second condition assumes that text is much longer than both &before and &after. |
| 840 | if( before.empty() || before == after ) { |
| 841 | return text; |
| 842 | } |
| 843 | |
| 844 | const size_t before_len = before.length(); |
| 845 | const size_t after_len = after.length(); |
| 846 | size_t pos = 0; |
| 847 | |
| 848 | while( ( pos = text.find( before, pos ) ) != std::string::npos ) { |
| 849 | text.replace( pos, before_len, after ); |
| 850 | pos += after_len; |
| 851 | } |
| 852 | |
| 853 | return text; |
| 854 | } |
| 855 | |
| 856 | std::string replace_colors( std::string text ) |
| 857 | { |
no test coverage detected