From 7190791927e0e1bc20e2c301ae4e0ba7169e990d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 28 Apr 2014 19:48:23 +0100 Subject: Move some buffer related utility functions to buffer_utils.{cc,hh} --- src/buffer_utils.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/buffer_utils.cc (limited to 'src/buffer_utils.cc') diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc new file mode 100644 index 00000000..af61cb19 --- /dev/null +++ b/src/buffer_utils.cc @@ -0,0 +1,23 @@ +#include "buffer_utils.hh" + +namespace Kakoune +{ + +CharCount get_column(const Buffer& buffer, + CharCount tabstop, BufferCoord coord) +{ + auto& line = buffer[coord.line]; + auto col = 0_char; + for (auto it = line.begin(); + it != line.end() and coord.column > (int)(it - line.begin()); + it = utf8::next(it)) + { + if (*it == '\t') + col = (col / tabstop + 1) * tabstop; + else + ++col; + } + return col; +} + +} -- cgit v1.2.3