Support adding ByteCount to void/char pointers without casting
This commit is contained in:
parent
8279a3776f
commit
20278ed52b
|
@ -604,7 +604,7 @@ BufferCoord Buffer::char_prev(BufferCoord coord) const
|
||||||
return { coord.line - 1, m_lines[coord.line - 1].length() - 1 };
|
return { coord.line - 1, m_lines[coord.line - 1].length() - 1 };
|
||||||
|
|
||||||
auto line = m_lines[coord.line];
|
auto line = m_lines[coord.line];
|
||||||
auto column = (int)(utf8::character_start(line.begin() + (int)coord.column - 1, line.begin()) - line.begin());
|
auto column = (int)(utf8::character_start(line.begin() + coord.column - 1, line.begin()) - line.begin());
|
||||||
return { coord.line, column };
|
return { coord.line, column };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -719,7 +719,7 @@ Completions CommandManager::complete(const Context& context,
|
||||||
{
|
{
|
||||||
auto prefix = command_line.substr(0_byte, cursor_pos);
|
auto prefix = command_line.substr(0_byte, cursor_pos);
|
||||||
CommandParser parser{prefix};
|
CommandParser parser{prefix};
|
||||||
const char* cursor = prefix.begin() + (int)cursor_pos;
|
const char* cursor = prefix.begin() + cursor_pos;
|
||||||
Vector<Token> tokens;
|
Vector<Token> tokens;
|
||||||
|
|
||||||
bool is_last_token = true;
|
bool is_last_token = true;
|
||||||
|
|
|
@ -139,7 +139,7 @@ struct BufferedWriter
|
||||||
{
|
{
|
||||||
const ByteCount length = data.length();
|
const ByteCount length = data.length();
|
||||||
const ByteCount write_len = std::min(length, size - m_pos);
|
const ByteCount write_len = std::min(length, size - m_pos);
|
||||||
memcpy(m_buffer + (int)m_pos, data.data(), (int)write_len);
|
memcpy(m_buffer + m_pos, data.data(), (int)write_len);
|
||||||
m_pos += write_len;
|
m_pos += write_len;
|
||||||
if (m_pos == size)
|
if (m_pos == size)
|
||||||
flush();
|
flush();
|
||||||
|
|
|
@ -991,8 +991,8 @@ struct TabulationHighlighter : Highlighter
|
||||||
column = 0;
|
column = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
kak_assert(pos != nullptr and pos <= line_data + (int)begin.column);
|
kak_assert(pos != nullptr and pos <= line_data + begin.column);
|
||||||
for (auto end = line_data + (int)atom_it->end().column; pos != end; ++pos)
|
for (auto end = line_data + atom_it->end().column; pos != end; ++pos)
|
||||||
{
|
{
|
||||||
const char* next_tab = std::find(pos, end, '\t');
|
const char* next_tab = std::find(pos, end, '\t');
|
||||||
if (next_tab == end)
|
if (next_tab == end)
|
||||||
|
@ -1006,9 +1006,9 @@ struct TabulationHighlighter : Highlighter
|
||||||
const ColumnCount tabwidth = tabstop - (column % tabstop);
|
const ColumnCount tabwidth = tabstop - (column % tabstop);
|
||||||
column += tabwidth;
|
column += tabwidth;
|
||||||
|
|
||||||
if (pos >= line_data + (int)atom_it->begin().column)
|
if (pos >= line_data + atom_it->begin().column)
|
||||||
{
|
{
|
||||||
if (pos != line_data + (int)atom_it->begin().column)
|
if (pos != line_data + atom_it->begin().column)
|
||||||
atom_it = ++line.split(atom_it, {begin.line, ByteCount(pos - line_data)});
|
atom_it = ++line.split(atom_it, {begin.line, ByteCount(pos - line_data)});
|
||||||
if (pos + 1 != end)
|
if (pos + 1 != end)
|
||||||
atom_it = line.split(atom_it, {begin.line, ByteCount(pos + 1 - line_data)});
|
atom_it = line.split(atom_it, {begin.line, ByteCount(pos + 1 - line_data)});
|
||||||
|
|
|
@ -36,10 +36,10 @@ public:
|
||||||
const_iterator begin() const { return type().data(); }
|
const_iterator begin() const { return type().data(); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
iterator end() { return type().data() + (int)type().length(); }
|
iterator end() { return type().data() + type().length(); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
const_iterator end() const { return type().data() + (int)type().length(); }
|
const_iterator end() const { return type().data() + type().length(); }
|
||||||
|
|
||||||
reverse_iterator rbegin() { return reverse_iterator{end()}; }
|
reverse_iterator rbegin() { return reverse_iterator{end()}; }
|
||||||
const_reverse_iterator rbegin() const { return const_reverse_iterator{end()}; }
|
const_reverse_iterator rbegin() const { return const_reverse_iterator{end()}; }
|
||||||
|
@ -77,10 +77,10 @@ public:
|
||||||
{ return utf8::advance(begin(), end(), count) - begin(); }
|
{ return utf8::advance(begin(), end(), count) - begin(); }
|
||||||
|
|
||||||
CharCount char_count_to(ByteCount count) const
|
CharCount char_count_to(ByteCount count) const
|
||||||
{ return utf8::distance(begin(), begin() + (int)count); }
|
{ return utf8::distance(begin(), begin() + count); }
|
||||||
|
|
||||||
ColumnCount column_count_to(ByteCount count) const
|
ColumnCount column_count_to(ByteCount count) const
|
||||||
{ return utf8::column_distance(begin(), begin() + (int)count); }
|
{ return utf8::column_distance(begin(), begin() + count); }
|
||||||
|
|
||||||
StringView substr(ByteCount from, ByteCount length = -1) const;
|
StringView substr(ByteCount from, ByteCount length = -1) const;
|
||||||
StringView substr(CharCount from, CharCount length = -1) const;
|
StringView substr(CharCount from, CharCount length = -1) const;
|
||||||
|
|
|
@ -107,7 +107,7 @@ String replace(StringView str, StringView substr, StringView replacement)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
res += replacement;
|
res += replacement;
|
||||||
it = match + (int)substr.length();
|
it = match + substr.length();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,10 @@ inline constexpr ByteCount operator"" _byte(unsigned long long int value)
|
||||||
return ByteCount(value);
|
return ByteCount(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Byte>
|
||||||
|
requires (std::is_same_v<std::remove_cv_t<Byte>, char> or std::is_same_v<std::remove_cv_t<Byte>, void>)
|
||||||
|
Byte* operator+(Byte* ptr, ByteCount count) { return ptr + (int)count; }
|
||||||
|
|
||||||
struct CharCount : public StronglyTypedNumber<CharCount, int>
|
struct CharCount : public StronglyTypedNumber<CharCount, int>
|
||||||
{
|
{
|
||||||
CharCount() = default;
|
CharCount() = default;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user