diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-04-28 19:49:00 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-04-28 19:49:00 +0100 |
| commit | 53cb626f49dc202186adf34c585403dc4df54318 (patch) | |
| tree | 9fe46d9dae2f4ca46c2822340d339b4392228413 /src/string.cc | |
| parent | 7190791927e0e1bc20e2c301ae4e0ba7169e990d (diff) | |
Add an expand_tabs string utility function
Diffstat (limited to 'src/string.cc')
| -rw-r--r-- | src/string.cc | 18 |
1 files changed, 18 insertions, 0 deletions
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<const char*>; + 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; +} + } |
