Add support for hex formatting
This commit is contained in:
parent
7e6b02f26a
commit
6870895374
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user