summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2022-12-15 13:29:45 +1100
committerMaxime Coste <mawww@kakoune.org>2022-12-15 13:29:45 +1100
commit20278ed52b175de20b57090f3087a23060a39e24 (patch)
tree11e6b67f3794d6c2845cc7b9044c9594ac4e68f9
parent8279a3776f38c875ef58da7823f56fb5ef3407bb (diff)
Support adding ByteCount to void/char pointers without casting
-rw-r--r--src/buffer.cc2
-rw-r--r--src/command_manager.cc2
-rw-r--r--src/file.hh2
-rw-r--r--src/highlighters.cc8
-rw-r--r--src/string.hh8
-rw-r--r--src/string_utils.cc2
-rw-r--r--src/units.hh4
7 files changed, 16 insertions, 12 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index 4d7d432d..fd8e0c4c 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -604,7 +604,7 @@ BufferCoord Buffer::char_prev(BufferCoord coord) const
return { coord.line - 1, m_lines[coord.line - 1].length() - 1 };
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 };
}
diff --git a/src/command_manager.cc b/src/command_manager.cc
index 5e2253bd..ff7a143b 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -719,7 +719,7 @@ Completions CommandManager::complete(const Context& context,
{
auto prefix = command_line.substr(0_byte, cursor_pos);
CommandParser parser{prefix};
- const char* cursor = prefix.begin() + (int)cursor_pos;
+ const char* cursor = prefix.begin() + cursor_pos;
Vector<Token> tokens;
bool is_last_token = true;
diff --git a/src/file.hh b/src/file.hh
index 7f30c0b2..1d9391fb 100644
--- a/src/file.hh
+++ b/src/file.hh
@@ -139,7 +139,7 @@ struct BufferedWriter
{
const ByteCount length = data.length();
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;
if (m_pos == size)
flush();
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 32f27e84..fcd7650b 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -991,8 +991,8 @@ struct TabulationHighlighter : Highlighter
column = 0;
}
- kak_assert(pos != nullptr and pos <= line_data + (int)begin.column);
- for (auto end = line_data + (int)atom_it->end().column; pos != end; ++pos)
+ kak_assert(pos != nullptr and pos <= line_data + begin.column);
+ for (auto end = line_data + atom_it->end().column; pos != end; ++pos)
{
const char* next_tab = std::find(pos, end, '\t');
if (next_tab == end)
@@ -1006,9 +1006,9 @@ struct TabulationHighlighter : Highlighter
const ColumnCount tabwidth = tabstop - (column % tabstop);
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)});
if (pos + 1 != end)
atom_it = line.split(atom_it, {begin.line, ByteCount(pos + 1 - line_data)});
diff --git a/src/string.hh b/src/string.hh
index 4af99c80..9a7e39f0 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -36,10 +36,10 @@ public:
const_iterator begin() const { return type().data(); }
[[gnu::always_inline]]
- iterator end() { return type().data() + (int)type().length(); }
+ iterator end() { return type().data() + type().length(); }
[[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()}; }
const_reverse_iterator rbegin() const { return const_reverse_iterator{end()}; }
@@ -77,10 +77,10 @@ public:
{ return utf8::advance(begin(), end(), count) - begin(); }
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
- { 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(CharCount from, CharCount length = -1) const;
diff --git a/src/string_utils.cc b/src/string_utils.cc
index f34bde03..0b0de19e 100644
--- a/src/string_utils.cc
+++ b/src/string_utils.cc
@@ -107,7 +107,7 @@ String replace(StringView str, StringView substr, StringView replacement)
break;
res += replacement;
- it = match + (int)substr.length();
+ it = match + substr.length();
}
return res;
}
diff --git a/src/units.hh b/src/units.hh
index 4842f32c..3bdfe253 100644
--- a/src/units.hh
+++ b/src/units.hh
@@ -137,6 +137,10 @@ inline constexpr ByteCount operator"" _byte(unsigned long long int 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>
{
CharCount() = default;