Fix wrong implicit conversions from int/Codepoint to StringView

This commit is contained in:
Maxime Coste 2015-03-30 13:33:46 +01:00
parent adaf6ecc40
commit 8439059758
3 changed files with 12 additions and 5 deletions

View File

@ -32,7 +32,7 @@ inline void option_from_string(StringView str, bool& opt)
throw runtime_error("boolean values are either true, yes, false or no"); throw runtime_error("boolean values are either true, yes, false or no");
} }
constexpr Codepoint list_separator = ':'; constexpr char list_separator = ':';
template<typename T, MemoryDomain domain> template<typename T, MemoryDomain domain>
String option_to_string(const Vector<T, domain>& opt) String option_to_string(const Vector<T, domain>& opt)
@ -98,7 +98,7 @@ void option_from_string(StringView str, UnorderedMap<Key, Value, domain>& opt)
} }
} }
constexpr Codepoint tuple_separator = ','; constexpr char tuple_separator = ',';
template<size_t I, typename... Types> template<size_t I, typename... Types>
struct TupleOptionDetail struct TupleOptionDetail

View File

@ -148,16 +148,22 @@ String expand_tabs(StringView line, CharCount tabstop, CharCount col)
{ {
String res; String res;
res.reserve(line.length()); res.reserve(line.length());
using Utf8It = utf8::iterator<const char*>; for (auto it = line.begin(), end = line.end(); it != end; )
for (Utf8It it = line.begin(); it.base() < line.end(); ++it)
{ {
if (*it == '\t') if (*it == '\t')
{ {
CharCount end_col = (col / tabstop + 1) * tabstop; CharCount end_col = (col / tabstop + 1) * tabstop;
res += String{' ', end_col - col}; res += String{' ', end_col - col};
col = end_col;
++it;
} }
else else
res += *it; {
auto char_end = utf8::next(it, end);
res += {it, char_end};
++col;
it = char_end;
}
} }
return res; return res;
} }

View File

@ -150,6 +150,7 @@ public:
constexpr StringView(const char* begin, const char* end) : m_data{begin}, m_length{(int)(end - begin)} {} constexpr StringView(const char* begin, const char* end) : m_data{begin}, m_length{(int)(end - begin)} {}
StringView(const String& str) : m_data{str.data()}, m_length{(int)str.length()} {} StringView(const String& str) : m_data{str.data()}, m_length{(int)str.length()} {}
StringView(const char& c) : m_data(&c), m_length(1) {} StringView(const char& c) : m_data(&c), m_length(1) {}
StringView(int c) = delete;
[[gnu::always_inline]] [[gnu::always_inline]]
constexpr const char* data() const { return m_data; } constexpr const char* data() const { return m_data; }