diff options
| author | Maxime Coste <mawww@kakoune.org> | 2022-02-22 20:14:47 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2022-03-06 10:13:14 +1100 |
| commit | 70610017284af7effd675bd927ae25b084b3e4b9 (patch) | |
| tree | a7c883a919f64d4d3828b074f4707b3272460cd0 /src/string.hh | |
| parent | b915e4e11b666b72607b8c22044f5e20d9107cdd (diff) | |
Add a complete-command command to configure command completion
This makes it possible to change command completion in hooks and
paves the way to more flexibility in how custom commands can be
completed
Diffstat (limited to 'src/string.hh')
| -rw-r--r-- | src/string.hh | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/string.hh b/src/string.hh index d14929f4..c3e7401f 100644 --- a/src/string.hh +++ b/src/string.hh @@ -67,6 +67,9 @@ public: [[gnu::always_inline]] bool empty() const { return type().length() == 0_byte; } + bool starts_with(StringView str) const; + bool ends_with(StringView str) const; + ByteCount byte_count_to(CharCount count) const { return utf8::advance(begin(), end(), count) - begin(); } @@ -306,6 +309,22 @@ inline StringView StringOps<Type, CharType>::substr(ColumnCount from, ColumnCoun return StringView{ beg, utf8::advance(beg, end(), length) }; } +template<typename Type, typename CharType> +inline bool StringOps<Type, CharType>::starts_with(StringView str) const +{ + if (type().length() < str.length()) + return false; + return substr(0, str.length()) == str; +} + +template<typename Type, typename CharType> +inline bool StringOps<Type, CharType>::ends_with(StringView str) const +{ + if (type().length() < str.length()) + return false; + return substr(type().length() - str.length()) == str; +} + inline String& operator+=(String& lhs, StringView rhs) { lhs.append(rhs.data(), rhs.length()); |
