* @brief Removes @c n @c leading characters from the given string @c s and * returns the result. * * @param s String from which leading characters are tp be removed. * @param leading Leading character to remove. * @param n Max number of characters to remove. If not set, remove as much * as possible. */
| 963 | * as possible. |
| 964 | */ |
| 965 | std::string removeLeadingCharacter(const std::string &s, char leading, std::size_t n) { |
| 966 | if (n == 0) { |
| 967 | return s; |
| 968 | } |
| 969 | |
| 970 | std::string ret(s); |
| 971 | std::size_t counter = 0; |
| 972 | while (ret[0] == leading) { |
| 973 | ret.erase(0, 1); |
| 974 | if (n == ++counter) { |
| 975 | return ret; |
| 976 | } |
| 977 | } |
| 978 | return ret; |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * @return @c True if character @a c is a control character, @c false otherwise. |