diff --git a/src/string.cc b/src/string.cc index 46d492f1..91a31802 100644 --- a/src/string.cc +++ b/src/string.cc @@ -1,6 +1,7 @@ #include "string.hh" #include "exception.hh" +#include "utf8_iterator.hh" namespace Kakoune { @@ -111,4 +112,21 @@ bool subsequence_match(StringView str, StringView subseq) return true; } +String expand_tabs(StringView line, CharCount tabstop, CharCount col) +{ + String res; + using Utf8It = utf8::utf8_iterator; + for (Utf8It it = line.begin(); it.base() < line.end(); ++it) + { + if (*it == '\t') + { + CharCount end_col = (col / tabstop + 1) * tabstop; + res += String{' ', end_col - col}; + } + else + res += *it; + } + return res; +} + } diff --git a/src/string.hh b/src/string.hh index fd10c23f..954436e4 100644 --- a/src/string.hh +++ b/src/string.hh @@ -279,6 +279,8 @@ String to_string(const StronglyTypedNumber& val) bool prefix_match(StringView str, StringView prefix); bool subsequence_match(StringView str, StringView subseq); +String expand_tabs(StringView line, CharCount tabstop, CharCount col = 0); + } namespace std