summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-02-04 23:52:06 +0000
committerMaxime Coste <frrrwww@gmail.com>2016-02-04 23:54:22 +0000
commita8eddd03f0e328b08d23ec9f83c5c61e9a9b202a (patch)
tree785b26eafd774e82a24ffca1c3b5cf9534e2a2b3
parent80f7a350e41bdf9c3011bb1e5ce0cf23bd405b5e (diff)
String usage cleanups
-rw-r--r--src/backtrace.cc2
-rw-r--r--src/insert_completer.cc6
-rw-r--r--src/normal.cc2
-rw-r--r--src/regex.cc3
-rw-r--r--src/regex.hh2
-rw-r--r--src/selectors.hh3
-rw-r--r--src/string.hh20
7 files changed, 18 insertions, 20 deletions
diff --git a/src/backtrace.cc b/src/backtrace.cc
index 677702c8..2fc99e8e 100644
--- a/src/backtrace.cc
+++ b/src/backtrace.cc
@@ -32,7 +32,7 @@ String Backtrace::desc() const
char** symbols = backtrace_symbols(stackframes, num_frames);
ByteCount size = 0;
for (int i = 0; i < num_frames; ++i)
- size += StringView::strlen(symbols[i]) + 1;
+ size += strlen(symbols[i]) + 1;
String res; res.reserve(size);
for (int i = 0; i < num_frames; ++i)
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index fe219399..f1ccf9ac 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -88,12 +88,12 @@ InsertCompletion complete_word(const Buffer& buffer, ByteCoord cursor_pos, const
if (not is_word(*begin))
++begin;
- String prefix{begin.base(), end.base()};
+ auto prefix = buffer.string(begin.base().coord(), end.base().coord());
while (end != buffer.end() and is_word(*end))
++end;
- String current_word{begin.base(), end.base()};
+ auto current_word = buffer.string(begin.base().coord(), end.base().coord());
struct RankedMatchAndBuffer : RankedMatch
{
@@ -189,7 +189,7 @@ InsertCompletion complete_filename(const Buffer& buffer, ByteCoord cursor_pos,
if (begin == pos)
return {};
- String prefix{begin, pos};
+ auto prefix = buffer.string(begin.coord(), pos.coord());
if (require_slash and not contains(prefix, '/'))
return {};
diff --git a/src/normal.cc b/src/normal.cc
index 60b8a23c..c33c2ec2 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -366,7 +366,7 @@ void command(Context& context, NormalParams params)
{
EnvVarMap env_vars = {
{ "count", to_string(params.count) },
- { "register", String{params.reg} }
+ { "register", String{&params.reg, 1} }
};
CommandManager::instance().execute(
cmdline, context, { {}, env_vars });
diff --git a/src/regex.cc b/src/regex.cc
index 39a298cc..686e94c4 100644
--- a/src/regex.cc
+++ b/src/regex.cc
@@ -7,8 +7,7 @@ namespace Kakoune
String option_to_string(const Regex& re)
{
- const auto& str = re.str();
- return {str.begin(), str.end()};
+ return re.str();
}
void option_from_string(StringView str, Regex& re)
diff --git a/src/regex.hh b/src/regex.hh
index 93c5d462..a26daab7 100644
--- a/src/regex.hh
+++ b/src/regex.hh
@@ -59,7 +59,7 @@ struct Regex : boost::regex
: boost::regex(begin, end, flags) {}
catch (std::runtime_error& err) { throw regex_error(err.what()); }
- String str() const { auto s = boost::regex::str(); return {s.begin(), s.end()}; }
+ String str() const { auto s = boost::regex::str(); return {s.data(), (int)s.length()}; }
};
namespace regex_ns = boost;
#endif
diff --git a/src/selectors.hh b/src/selectors.hh
index a75cb35b..dc28dfd8 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -289,7 +289,8 @@ Selection find_next_match(const Buffer& buffer, const Selection& sel, const Rege
begin = ensure_char_start(buffer, matches[0].first);
end = ensure_char_start(buffer, matches[0].second);
for (auto& match : matches)
- captures.emplace_back(match.first, match.second);
+ captures.push_back(buffer.string(match.first.coord(),
+ match.second.coord()));
}
if (not found or begin == buffer.end())
throw runtime_error(format("'{}': no matches found", regex.str()));
diff --git a/src/string.hh b/src/string.hh
index a5fb8ab3..5b62bf12 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -85,6 +85,12 @@ private:
const Type& type() const { return *static_cast<const Type*>(this); }
};
+[[gnu::optimize(3)]] // this is recursive for constexpr reason
+constexpr ByteCount strlen(const char* s)
+{
+ return *s == 0 ? 0 : strlen(s+1) + 1;
+}
+
class String : public StringOps<String, char>
{
public:
@@ -92,16 +98,14 @@ public:
Allocator<char, MemoryDomain::String>>;
String() {}
- String(const char* content) : m_data(content) {}
+ String(const char* content) : m_data(content, (size_t)(int)strlen(content)) {}
String(const char* content, ByteCount len) : m_data(content, (size_t)(int)len) {}
- explicit String(char content, CharCount count = 1) : m_data((size_t)(int)count, content) {}
explicit String(Codepoint cp, CharCount count = 1)
{
while (count-- > 0)
utf8::dump(std::back_inserter(*this), cp);
}
- template<typename Iterator>
- String(Iterator begin, Iterator end) : m_data(begin, end) {}
+ String(const char* begin, const char* end) : m_data(begin, end-begin) {}
[[gnu::always_inline]]
char* data() { return &m_data[0]; }
@@ -148,7 +152,7 @@ public:
[[gnu::always_inline]]
constexpr ByteCount length() const { return m_length; }
- String str() const { return {begin(), end()}; }
+ String str() const { return {m_data, m_length}; }
struct ZeroTerminatedString
{
@@ -168,12 +172,6 @@ public:
};
ZeroTerminatedString zstr() const { return {begin(), end()}; }
- [[gnu::optimize(3)]] // this is recursive for constexpr reason
- static constexpr ByteCount strlen(const char* s)
- {
- return *s == 0 ? 0 : strlen(s+1) + 1;
- }
-
private:
const char* m_data = nullptr;
ByteCount m_length = 0;