2014-04-28 20:48:23 +02:00
|
|
|
#ifndef buffer_utils_hh_INCLUDED
|
|
|
|
#define buffer_utils_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "buffer.hh"
|
|
|
|
#include "selection.hh"
|
|
|
|
|
2015-12-23 22:43:07 +01:00
|
|
|
#include "utf8_iterator.hh"
|
|
|
|
#include "unicode.hh"
|
|
|
|
|
2014-04-28 20:48:23 +02:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
inline String content(const Buffer& buffer, const Selection& range)
|
|
|
|
{
|
|
|
|
return buffer.string(range.min(), buffer.char_next(range.max()));
|
|
|
|
}
|
|
|
|
|
2016-03-16 14:59:30 +01:00
|
|
|
inline ByteCoord erase(Buffer& buffer, const Selection& range)
|
2014-04-28 20:48:23 +02:00
|
|
|
{
|
2016-03-16 14:59:30 +01:00
|
|
|
return buffer.erase(range.min(), buffer.char_next(range.max()));
|
2014-04-28 20:48:23 +02:00
|
|
|
}
|
|
|
|
|
2016-03-16 14:59:30 +01:00
|
|
|
inline ByteCoord replace(Buffer& buffer, const Selection& range, StringView content)
|
2016-03-16 14:48:11 +01:00
|
|
|
{
|
2016-03-16 14:59:30 +01:00
|
|
|
return buffer.replace(range.min(), buffer.char_next(range.max()), content);
|
2016-03-16 14:48:11 +01:00
|
|
|
}
|
|
|
|
|
2014-04-28 20:48:23 +02:00
|
|
|
inline CharCount char_length(const Buffer& buffer, const Selection& range)
|
|
|
|
{
|
|
|
|
return utf8::distance(buffer.iterator_at(range.min()),
|
2014-09-22 14:45:07 +02:00
|
|
|
buffer.iterator_at(buffer.char_next(range.max())));
|
2014-04-28 20:48:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 10:41:47 +02:00
|
|
|
inline CharCount char_length(const Buffer& buffer, const ByteCoord& begin, const ByteCoord& end)
|
|
|
|
{
|
|
|
|
return utf8::distance(buffer.iterator_at(begin), buffer.iterator_at(end));
|
|
|
|
}
|
|
|
|
|
2015-12-23 22:43:07 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-18 00:40:14 +01:00
|
|
|
inline bool is_bow(const Buffer& buffer, ByteCoord coord)
|
|
|
|
{
|
|
|
|
auto it = utf8::iterator<BufferIterator>(buffer.iterator_at(coord), buffer);
|
|
|
|
if (coord == ByteCoord{0,0})
|
|
|
|
return is_word(*it);
|
|
|
|
|
|
|
|
return not is_word(*(it-1)) and is_word(*it);
|
|
|
|
}
|
|
|
|
|
2015-12-23 22:43:07 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-04-28 20:48:23 +02:00
|
|
|
CharCount get_column(const Buffer& buffer,
|
2014-05-07 20:51:01 +02:00
|
|
|
CharCount tabstop, ByteCoord coord);
|
2014-04-28 20:48:23 +02:00
|
|
|
|
2015-02-25 14:40:19 +01:00
|
|
|
ByteCount get_byte_to_column(const Buffer& buffer, CharCount tabstop,
|
|
|
|
CharCoord coord);
|
|
|
|
|
2015-10-16 02:33:17 +02:00
|
|
|
Buffer* create_fifo_buffer(String name, int fd, bool scroll = false);
|
2015-10-16 14:58:56 +02:00
|
|
|
Buffer* open_file_buffer(StringView filename);
|
|
|
|
Buffer* open_or_create_file_buffer(StringView filename);
|
|
|
|
void reload_file_buffer(Buffer& buffer);
|
2014-08-15 14:21:54 +02:00
|
|
|
|
2015-06-06 12:54:48 +02:00
|
|
|
void write_to_debug_buffer(StringView str);
|
|
|
|
|
2014-04-28 20:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // buffer_utils_hh_INCLUDED
|