summaryrefslogtreecommitdiff
path: root/src/buffer_utils.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-12-23 21:43:07 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-12-23 22:20:25 +0000
commit1d748a401726999959c9bc69e819c2fbbd97a565 (patch)
treed522dc354bb9117b59c8636982561bd8f7f206da /src/buffer_utils.hh
parent669fccc5e9c5327122fc9d653091e2de3a62d544 (diff)
Pass flags to the regex engine to correct anchors
Current behaviour was matching ^ $ for the current search start/end (and \b was always matching begin/end as well). Fixes #536
Diffstat (limited to 'src/buffer_utils.hh')
-rw-r--r--src/buffer_utils.hh22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/buffer_utils.hh b/src/buffer_utils.hh
index 3851ee65..8e7fe5dc 100644
--- a/src/buffer_utils.hh
+++ b/src/buffer_utils.hh
@@ -4,6 +4,9 @@
#include "buffer.hh"
#include "selection.hh"
+#include "utf8_iterator.hh"
+#include "unicode.hh"
+
namespace Kakoune
{
@@ -24,6 +27,25 @@ inline CharCount char_length(const Buffer& buffer, const Selection& range)
buffer.iterator_at(buffer.char_next(range.max())));
}
+inline bool is_bol(ByteCoord coord)
+{
+ return coord.column == 0;
+}
+
+inline bool is_eol(const Buffer& buffer, ByteCoord coord)
+{
+ return buffer.is_end(coord) or buffer[coord.line].length() == coord.column+1;
+}
+
+inline bool is_eow(const Buffer& buffer, ByteCoord coord)
+{
+ if (buffer.is_end(coord) or coord == ByteCoord{0,0})
+ return true;
+
+ auto it = utf8::iterator<BufferIterator>(buffer.iterator_at(coord), buffer);
+ return is_word(*(it-1)) and not is_word(*it);
+}
+
CharCount get_column(const Buffer& buffer,
CharCount tabstop, ByteCoord coord);