From 68708953744b9e98d78cd28e1904af4f9c16d1e0 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 22 Jun 2015 13:56:00 +0100 Subject: [PATCH] Add support for hex formatting --- src/highlighters.cc | 8 ++------ src/string.cc | 7 +++++++ 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 #include 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