mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-28 09:07:19 +03:00
Add an expand_tabs string utility function
This commit is contained in:
parent
7190791927
commit
53cb626f49
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user