Add an expand_tabs string utility function

This commit is contained in:
Maxime Coste 2014-04-28 19:49:00 +01:00
parent 7190791927
commit 53cb626f49
2 changed files with 20 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -279,6 +279,8 @@ String to_string(const StronglyTypedNumber<RealType, ValueType>& 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