mirror of
https://github.com/polybar/polybar.git
synced 2026-02-19 19:35:38 +00:00
feat: added max and min values to tokens
This commit is contained in:
@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user