diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-07-28 09:41:47 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-07-28 09:41:47 +0100 |
| commit | a7005ec74be9eef4595031bfe9191cc8bd5a08e3 (patch) | |
| tree | 497e00c33a89230efce4cc14b02868be7fc2eab6 /src | |
| parent | 74c3f101cd60e213962026f0bb0235102f7bc833 (diff) | |
Add a char_length(Buffer&, const ByteCoord&, const ByteCoord&) util
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer_utils.hh | 5 | ||||
| -rw-r--r-- | src/display_buffer.cc | 4 | ||||
| -rw-r--r-- | src/window.cc | 8 |
3 files changed, 10 insertions, 7 deletions
diff --git a/src/buffer_utils.hh b/src/buffer_utils.hh index a8226660..58192f31 100644 --- a/src/buffer_utils.hh +++ b/src/buffer_utils.hh @@ -31,6 +31,11 @@ inline CharCount char_length(const Buffer& buffer, const Selection& range) buffer.iterator_at(buffer.char_next(range.max()))); } +inline CharCount char_length(const Buffer& buffer, const ByteCoord& begin, const ByteCoord& end) +{ + return utf8::distance(buffer.iterator_at(begin), buffer.iterator_at(end)); +} + inline bool is_bol(ByteCoord coord) { return coord.column == 0; diff --git a/src/display_buffer.cc b/src/display_buffer.cc index c112679d..c26ca8da 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -2,6 +2,7 @@ #include "assert.hh" #include "buffer.hh" +#include "buffer_utils.hh" #include "utf8.hh" #include "face_registry.hh" @@ -62,8 +63,7 @@ CharCount DisplayAtom::length() const switch (m_type) { case BufferRange: - return utf8::distance(m_buffer->iterator_at(m_range.begin), - m_buffer->iterator_at(m_range.end)); + return char_length(*m_buffer, m_range.begin, m_range.end); case Text: case ReplacedBufferRange: return m_text.char_length(); diff --git a/src/window.cc b/src/window.cc index efffe1e1..487cf927 100644 --- a/src/window.cc +++ b/src/window.cc @@ -200,9 +200,8 @@ static CharCount adapt_view_pos(const DisplayBuffer& display_buffer, CharCount o if (atom.type() == DisplayAtom::BufferRange) { auto& buf = atom.buffer(); - pos_beg = buffer_column - + utf8::distance(buf.iterator_at(atom.begin()), - buf.iterator_at(pos)); + pos_beg = buffer_column + + char_length(buf, atom.begin(), pos); pos_end = pos_beg+1; } else @@ -273,8 +272,7 @@ CharCount find_display_column(const DisplayLine& line, const Buffer& buffer, coord >= atom.begin() and coord < atom.end()) { if (atom.type() == DisplayAtom::BufferRange) - column += utf8::distance(buffer.iterator_at(atom.begin()), - buffer.iterator_at(coord)); + column += char_length(buffer, atom.begin(), coord); return column; } column += atom.length(); |
