10#ifndef M5_UTILITY_STRING_HPP
11#define M5_UTILITY_STRING_HPP
28std::string&
trimLeft(std::string& s);
30std::string&
trim(std::string& s);
39template <
bool Case = true>
42 return (v & 0x0F) < 10 ?
'0' + (v & 0x0F) : (Case ?
'A' :
'a') + ((v & 0x0F) - 10);
49template <
typename T,
bool Case = true>
52 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
"T must be unsigned integer");
54 for (
size_t i =
sizeof(T); i > 0; --i) {
55 uint8_t u8 = (v >> ((i - 1) * 8)) & 0xFF;
56 s += uintToHexChar<Case>((u8 >> 4) & 0x0F);
57 s += uintToHexChar<Case>(u8 & 0x0F);
Top level namespace of M5.
Definition bit_segment.hpp:17
std::string formatString(const char *fmt,...)
@ brief Create a string in a format similar to printf
Definition string.cpp:17
std::string & trim(std::string &s)
Trim both ends.
Definition string.cpp:47
std::string & trimRight(std::string &s)
Trim right.
Definition string.cpp:34
std::string & trimLeft(std::string &s)
Trim left.
Definition string.cpp:40
constexpr char uintToHexChar(const uint8_t v)
Convert from 0~15 to hexadecimal character.
Definition string.hpp:40
std::string unsignedToHexString(const T &v)
Convert any one unsigned integer to a hexadecimal string.
Definition string.hpp:50