diff options
Diffstat (limited to 'src/string_utils.cc')
| -rw-r--r-- | src/string_utils.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/string_utils.cc b/src/string_utils.cc index 3ce98940..2ae8ea6f 100644 --- a/src/string_utils.cc +++ b/src/string_utils.cc @@ -111,6 +111,16 @@ String replace(StringView str, StringView substr, StringView replacement) return res; } +String left_pad(StringView str, ColumnCount size, Codepoint c) +{ + return String(c, std::max(0_col, size - str.column_length())) + str.substr(0, size); +} + +String right_pad(StringView str, ColumnCount size, Codepoint c) +{ + return str.substr(0, size) + String(c, std::max(0_col, size - str.column_length())); +} + Optional<int> str_to_int_ifp(StringView str) { bool negative = not str.empty() and str[0] == '-'; |
