diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-06-22 13:56:00 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-06-22 13:56:00 +0100 |
| commit | 68708953744b9e98d78cd28e1904af4f9c16d1e0 (patch) | |
| tree | afe435034c6d4d69ee28c5f23e402527a38aa010 /src | |
| parent | 7e6b02f26a00bf58a638e50841915dcd33cadcc6 (diff) | |
Add support for hex formatting
Diffstat (limited to 'src')
| -rw-r--r-- | src/highlighters.cc | 8 | ||||
| -rw-r--r-- | src/string.cc | 7 | ||||
| -rw-r--r-- | src/string.hh | 4 |
3 files changed, 13 insertions, 6 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc index f1c871d2..cd13daad 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -17,7 +17,6 @@ #include "utf8.hh" #include "utf8_iterator.hh" -#include <sstream> #include <locale> namespace Kakoune @@ -834,15 +833,12 @@ void expand_unprintable(const Context& context, HighlightFlags flags, DisplayBuf auto next = utf8::next(it, end); if (cp != '\n' and not iswprint(cp)) { - std::ostringstream oss; - oss << "U+" << std::hex << cp; - const auto& stdstr = oss.str(); - String str{stdstr.begin(), stdstr.end()}; if (it.coord() != atom_it->begin()) atom_it = ++line.split(atom_it, it.coord()); if (next.coord() < atom_it->end()) atom_it = line.split(atom_it, next.coord()); - atom_it->replace(str); + + atom_it->replace(format("U+{}", hex(cp))); atom_it->face = { Color::Red, Color::Black }; break; } diff --git a/src/string.cc b/src/string.cc index 8d675388..2ed77156 100644 --- a/src/string.cc +++ b/src/string.cc @@ -137,6 +137,13 @@ InplaceString<24> to_string(size_t val) return res; } +InplaceString<24> to_string(Hex val) +{ + InplaceString<24> res; + res.m_length = sprintf(res.m_data, "%zx", val.val); + return res; +} + InplaceString<24> to_string(float val) { InplaceString<24> res; diff --git a/src/string.hh b/src/string.hh index 5d3855f1..424e994c 100644 --- a/src/string.hh +++ b/src/string.hh @@ -270,8 +270,12 @@ struct InplaceString char m_data[N]; }; +struct Hex { size_t val; }; +inline Hex hex(size_t val) { return {val}; } + InplaceString<16> to_string(int val); InplaceString<24> to_string(size_t val); +InplaceString<24> to_string(Hex val); InplaceString<24> to_string(float val); template<typename RealType, typename ValueType> |
