From 790e671f6cd34fc955dfc458b0a26a20a3fd8089 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 10 Feb 2015 23:09:30 +0000 Subject: Replace some function usage with c++ algorithms --- src/string.hh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/string.hh') diff --git a/src/string.hh b/src/string.hh index 62cbe5cc..7166c8b3 100644 --- a/src/string.hh +++ b/src/string.hh @@ -8,7 +8,6 @@ #include #include -#include namespace Kakoune { @@ -18,6 +17,11 @@ class StringView; using StringBase = std::basic_string, Allocator>; +constexpr ByteCount strlen(const char* s) +{ + return *s == 0 ? 0 : strlen(s+1) + 1; +} + class String : public StringBase { public: @@ -65,7 +69,7 @@ public: constexpr StringView() : m_data{nullptr}, m_length{0} {} constexpr StringView(const char* data, ByteCount length) : m_data{data}, m_length{length} {} - StringView(const char* data) : m_data{data}, m_length{(int)strlen(data)} {} + constexpr StringView(const char* data) : m_data{data}, m_length{strlen(data)} {} constexpr StringView(const char* begin, const char* end) : m_data{begin}, m_length{(int)(end - begin)} {} template StringView(const std::basic_string& str) : m_data{str.data()}, m_length{(int)str.length()} {} @@ -136,7 +140,8 @@ private: inline bool operator==(StringView lhs, StringView rhs) { - return lhs.m_length == rhs.m_length and memcmp(lhs.m_data, rhs.m_data, (int)lhs.m_length) == 0; + return lhs.m_length == rhs.m_length and + std::equal(lhs.begin(), lhs.end(), rhs.begin()); } inline bool operator!=(StringView lhs, StringView rhs) -- cgit v1.2.3