Add a char_length(Buffer&, const ByteCoord&, const ByteCoord&) util

This commit is contained in:
Maxime Coste 2016-07-28 09:41:47 +01:00
parent 74c3f101cd
commit a7005ec74b
3 changed files with 10 additions and 7 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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();