indent cleanup, correct erroneous 3 spaces indent
This commit is contained in:
parent
9679b17b16
commit
04ae48c346
|
@ -731,9 +731,9 @@ ByteCount Buffer::offset(BufferCoord c) const
|
||||||
|
|
||||||
bool Buffer::is_valid(BufferCoord c) const
|
bool Buffer::is_valid(BufferCoord c) const
|
||||||
{
|
{
|
||||||
return (c.line < line_count() and c.column < m_lines[c.line].length()) or
|
return (c.line < line_count() and c.column < m_lines[c.line].length()) or
|
||||||
(c.line == line_count() - 1 and c.column == m_lines.back().length()) or
|
(c.line == line_count() - 1 and c.column == m_lines.back().length()) or
|
||||||
(c.line == line_count() and c.column == 0);
|
(c.line == line_count() and c.column == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Buffer::is_end(BufferCoord c) const
|
bool Buffer::is_end(BufferCoord c) const
|
||||||
|
|
|
@ -78,7 +78,7 @@ bool is_command_separator(char c)
|
||||||
|
|
||||||
bool is_horizontal_blank(char c)
|
bool is_horizontal_blank(char c)
|
||||||
{
|
{
|
||||||
return c == ' ' or c == '\t';
|
return c == ' ' or c == '\t';
|
||||||
}
|
}
|
||||||
|
|
||||||
struct unterminated_string : parse_error
|
struct unterminated_string : parse_error
|
||||||
|
|
|
@ -745,7 +745,7 @@ void select_to_next_char(Context& context, int param)
|
||||||
std::bind(flags & SelectFlags::Reverse ? select_to_reverse : select_to,
|
std::bind(flags & SelectFlags::Reverse ? select_to_reverse : select_to,
|
||||||
_1, _2, key.key, param, flags & SelectFlags::Inclusive),
|
_1, _2, key.key, param, flags & SelectFlags::Inclusive),
|
||||||
flags & SelectFlags::Extend ? SelectMode::Extend : SelectMode::Replace);
|
flags & SelectFlags::Extend ? SelectMode::Extend : SelectMode::Replace);
|
||||||
}, "select to next char","enter char to select to");
|
}, "select to next char","enter char to select to");
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_or_end_macro_recording(Context& context, int)
|
void start_or_end_macro_recording(Context& context, int)
|
||||||
|
|
|
@ -16,47 +16,47 @@ typedef boost::regex Regex;
|
||||||
class String : public std::string
|
class String : public std::string
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
String() {}
|
String() {}
|
||||||
String(const char* content) : std::string(content) {}
|
String(const char* content) : std::string(content) {}
|
||||||
String(std::string content) : std::string(std::move(content)) {}
|
String(std::string content) : std::string(std::move(content)) {}
|
||||||
explicit String(char content, CharCount count = 1) : std::string((size_t)(int)count, content) {}
|
explicit String(char content, CharCount count = 1) : std::string((size_t)(int)count, content) {}
|
||||||
explicit String(Codepoint cp, CharCount count = 1)
|
explicit String(Codepoint cp, CharCount count = 1)
|
||||||
{
|
{
|
||||||
while (count-- > 0)
|
while (count-- > 0)
|
||||||
utf8::dump(back_inserter(*this), cp);
|
utf8::dump(back_inserter(*this), cp);
|
||||||
}
|
}
|
||||||
template<typename Iterator>
|
template<typename Iterator>
|
||||||
String(Iterator begin, Iterator end) : std::string(begin, end) {}
|
String(Iterator begin, Iterator end) : std::string(begin, end) {}
|
||||||
|
|
||||||
std::string& stdstr() { return *this; }
|
std::string& stdstr() { return *this; }
|
||||||
const std::string& stdstr() const { return *this; }
|
const std::string& stdstr() const { return *this; }
|
||||||
|
|
||||||
char operator[](ByteCount pos) const { return std::string::operator[]((int)pos); }
|
char operator[](ByteCount pos) const { return std::string::operator[]((int)pos); }
|
||||||
char& operator[](ByteCount pos) { return std::string::operator[]((int)pos); }
|
char& operator[](ByteCount pos) { return std::string::operator[]((int)pos); }
|
||||||
ByteCount length() const { return ByteCount{(int)std::string::length()}; }
|
ByteCount length() const { return ByteCount{(int)std::string::length()}; }
|
||||||
CharCount char_length() const { return utf8::distance(begin(), end()); }
|
CharCount char_length() const { return utf8::distance(begin(), end()); }
|
||||||
ByteCount byte_count_to(CharCount count) const { return utf8::advance(begin(), end(), (int)count) - begin(); }
|
ByteCount byte_count_to(CharCount count) const { return utf8::advance(begin(), end(), (int)count) - begin(); }
|
||||||
CharCount char_count_to(ByteCount count) const { return utf8::distance(begin(), begin() + (int)count); }
|
CharCount char_count_to(ByteCount count) const { return utf8::distance(begin(), begin() + (int)count); }
|
||||||
|
|
||||||
String operator+(const String& other) const { return String{stdstr() + other.stdstr()}; }
|
String operator+(const String& other) const { return String{stdstr() + other.stdstr()}; }
|
||||||
String& operator+=(const String& other) { std::string::operator+=(other); return *this; }
|
String& operator+=(const String& other) { std::string::operator+=(other); return *this; }
|
||||||
String operator+(const char* other) const { return String{stdstr() + other}; }
|
String operator+(const char* other) const { return String{stdstr() + other}; }
|
||||||
String& operator+=(const char* other) { std::string::operator+=(other); return *this; }
|
String& operator+=(const char* other) { std::string::operator+=(other); return *this; }
|
||||||
String operator+(char other) const { return String{stdstr() + other}; }
|
String operator+(char other) const { return String{stdstr() + other}; }
|
||||||
String& operator+=(char other) { std::string::operator+=(other); return *this; }
|
String& operator+=(char other) { std::string::operator+=(other); return *this; }
|
||||||
String operator+(Codepoint cp) const { String res = *this; utf8::dump(back_inserter(res), cp); return res; }
|
String operator+(Codepoint cp) const { String res = *this; utf8::dump(back_inserter(res), cp); return res; }
|
||||||
String& operator+=(Codepoint cp) { utf8::dump(back_inserter(*this), cp); return *this; }
|
String& operator+=(Codepoint cp) { utf8::dump(back_inserter(*this), cp); return *this; }
|
||||||
|
|
||||||
memoryview<char> data() const { return memoryview<char>(std::string::data(), size()); }
|
memoryview<char> data() const { return memoryview<char>(std::string::data(), size()); }
|
||||||
|
|
||||||
String substr(ByteCount pos, ByteCount length = -1) const { return String{std::string::substr((int)pos, (int)length)}; }
|
String substr(ByteCount pos, ByteCount length = -1) const { return String{std::string::substr((int)pos, (int)length)}; }
|
||||||
String substr(CharCount pos, CharCount length = INT_MAX) const
|
String substr(CharCount pos, CharCount length = INT_MAX) const
|
||||||
{
|
{
|
||||||
auto b = utf8::advance(begin(), end(), (int)pos);
|
auto b = utf8::advance(begin(), end(), (int)pos);
|
||||||
auto e = utf8::advance(b, end(), (int)length);
|
auto e = utf8::advance(b, end(), (int)length);
|
||||||
return String(b,e);
|
return String(b,e);
|
||||||
}
|
}
|
||||||
String replace(const Regex& expression, const String& replacement) const;
|
String replace(const Regex& expression, const String& replacement) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline String operator+(const char* lhs, const String& rhs)
|
inline String operator+(const char* lhs, const String& rhs)
|
||||||
|
|
|
@ -101,27 +101,27 @@ void test_utf8()
|
||||||
|
|
||||||
void test_string()
|
void test_string()
|
||||||
{
|
{
|
||||||
kak_assert(String("youpi ") + "matin" == "youpi matin");
|
kak_assert(String("youpi ") + "matin" == "youpi matin");
|
||||||
|
|
||||||
std::vector<String> splited = split("youpi:matin::tchou\\:kanaky:hihi\\:", ':', '\\');
|
std::vector<String> splited = split("youpi:matin::tchou\\:kanaky:hihi\\:", ':', '\\');
|
||||||
kak_assert(splited[0] == "youpi");
|
kak_assert(splited[0] == "youpi");
|
||||||
kak_assert(splited[1] == "matin");
|
kak_assert(splited[1] == "matin");
|
||||||
kak_assert(splited[2] == "");
|
kak_assert(splited[2] == "");
|
||||||
kak_assert(splited[3] == "tchou:kanaky");
|
kak_assert(splited[3] == "tchou:kanaky");
|
||||||
kak_assert(splited[4] == "hihi:");
|
kak_assert(splited[4] == "hihi:");
|
||||||
|
|
||||||
String escaped = escape("youpi:matin:tchou:", ':', '\\');
|
String escaped = escape("youpi:matin:tchou:", ':', '\\');
|
||||||
kak_assert(escaped == "youpi\\:matin\\:tchou\\:");
|
kak_assert(escaped == "youpi\\:matin\\:tchou\\:");
|
||||||
|
|
||||||
kak_assert(prefix_match("tchou kanaky", "tchou"));
|
kak_assert(prefix_match("tchou kanaky", "tchou"));
|
||||||
kak_assert(prefix_match("tchou kanaky", "tchou kanaky"));
|
kak_assert(prefix_match("tchou kanaky", "tchou kanaky"));
|
||||||
kak_assert(prefix_match("tchou kanaky", "t"));
|
kak_assert(prefix_match("tchou kanaky", "t"));
|
||||||
kak_assert(not prefix_match("tchou kanaky", "c"));
|
kak_assert(not prefix_match("tchou kanaky", "c"));
|
||||||
|
|
||||||
kak_assert(subsequence_match("tchou kanaky", "tknky"));
|
kak_assert(subsequence_match("tchou kanaky", "tknky"));
|
||||||
kak_assert(subsequence_match("tchou kanaky", "knk"));
|
kak_assert(subsequence_match("tchou kanaky", "knk"));
|
||||||
kak_assert(subsequence_match("tchou kanaky", "tchou kanaky"));
|
kak_assert(subsequence_match("tchou kanaky", "tchou kanaky"));
|
||||||
kak_assert(not subsequence_match("tchou kanaky", "tchou kanaky"));
|
kak_assert(not subsequence_match("tchou kanaky", "tchou kanaky"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_keys()
|
void test_keys()
|
||||||
|
|
|
@ -85,7 +85,7 @@ public:
|
||||||
explicit constexpr operator ValueType() const { return m_value; }
|
explicit constexpr operator ValueType() const { return m_value; }
|
||||||
explicit constexpr operator bool() const { return m_value; }
|
explicit constexpr operator bool() const { return m_value; }
|
||||||
private:
|
private:
|
||||||
ValueType m_value;
|
ValueType m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LineCount : public StronglyTypedNumber<LineCount, int>
|
struct LineCount : public StronglyTypedNumber<LineCount, int>
|
||||||
|
|
58
src/utils.hh
58
src/utils.hh
|
@ -96,52 +96,52 @@ public:
|
||||||
#endif
|
#endif
|
||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_ptr& operator=(safe_ptr&& other)
|
safe_ptr& operator=(safe_ptr&& other)
|
||||||
{
|
{
|
||||||
#ifdef KAK_DEBUG
|
#ifdef KAK_DEBUG
|
||||||
if (m_ptr)
|
if (m_ptr)
|
||||||
m_ptr->dec_safe_count();
|
m_ptr->dec_safe_count();
|
||||||
#endif
|
#endif
|
||||||
m_ptr = other.m_ptr;
|
m_ptr = other.m_ptr;
|
||||||
other.m_ptr = nullptr;
|
other.m_ptr = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset(T* ptr)
|
void reset(T* ptr)
|
||||||
{
|
{
|
||||||
*this = safe_ptr(ptr);
|
*this = safe_ptr(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator== (const safe_ptr& other) const { return m_ptr == other.m_ptr; }
|
bool operator== (const safe_ptr& other) const { return m_ptr == other.m_ptr; }
|
||||||
bool operator!= (const safe_ptr& other) const { return m_ptr != other.m_ptr; }
|
bool operator!= (const safe_ptr& other) const { return m_ptr != other.m_ptr; }
|
||||||
bool operator== (T* ptr) const { return m_ptr == ptr; }
|
bool operator== (T* ptr) const { return m_ptr == ptr; }
|
||||||
bool operator!= (T* ptr) const { return m_ptr != ptr; }
|
bool operator!= (T* ptr) const { return m_ptr != ptr; }
|
||||||
|
|
||||||
T& operator* () const { return *m_ptr; }
|
T& operator* () const { return *m_ptr; }
|
||||||
T* operator-> () const { return m_ptr; }
|
T* operator-> () const { return m_ptr; }
|
||||||
|
|
||||||
T* get() const { return m_ptr; }
|
T* get() const { return m_ptr; }
|
||||||
|
|
||||||
explicit operator bool() const { return m_ptr; }
|
explicit operator bool() const { return m_ptr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T* m_ptr;
|
T* m_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SafeCountable
|
class SafeCountable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#ifdef KAK_DEBUG
|
#ifdef KAK_DEBUG
|
||||||
SafeCountable() : m_count(0) {}
|
SafeCountable() : m_count(0) {}
|
||||||
~SafeCountable() { kak_assert(m_count == 0); }
|
~SafeCountable() { kak_assert(m_count == 0); }
|
||||||
|
|
||||||
void inc_safe_count() const { ++m_count; }
|
void inc_safe_count() const { ++m_count; }
|
||||||
void dec_safe_count() const { --m_count; kak_assert(m_count >= 0); }
|
void dec_safe_count() const { --m_count; kak_assert(m_count >= 0); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable int m_count;
|
mutable int m_count;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user