feat: added max and min values to tokens

This commit is contained in:
NBonaparte
2016-11-20 14:09:08 -08:00
parent d0915b82f4
commit 4179f8b7f9
4 changed files with 64 additions and 5 deletions

View File

@ -78,6 +78,20 @@ namespace string_util {
return replaced;
}
/**
* Replace all occurrences with bounded replacement
*/
string replace_all_bounded(const string& haystack, string needle, string replacement,
size_t min, size_t max, size_t start, size_t end) {
if (max != 0 && replacement.length() > max) {
replacement = replacement.erase(max);
}
else if (min != 0 && replacement.length() < min) {
replacement.insert(0, min - replacement.length(), ' ');
}
return replace_all(haystack, needle, replacement, start, end);
}
/**
* Replace all consecutive occurrences of needle in haystack
*/