10void intToHex(uint32_t number,
char* output, int32_t numChars = 8);
12uint32_t hexToIntFixedLength(
char const* __restrict__ hexChars, int32_t length);
19 StringBuf(
char* buf,
size_t capacity) : capacity_(capacity), buf_(buf) { memset(buf_,
'\0', capacity_); }
20 void append(std::string_view str);
21 void append(
char c) { ::strncat(buf_, &c, 1); }
25 for (
size_t i = 0; i <= size(); i++) {
26 if (isspace(buf_[i])) {
30 buf_[i - removed] = buf_[i];
34 void clear() { buf_[0] = 0; }
35 void truncate(
size_t newSize) {
36 if (newSize < capacity_) {
42 void appendInt(
int i,
int minChars = 1) { intToString(i, buf_ + size(), minChars); }
43 void appendHex(
int i,
int minChars = 1) { intToHex(i, buf_ + size(), minChars); }
44 void appendFloat(
float f, int32_t minDecimals, int32_t maxDecimals) {
45 floatToString(f, buf_ + size(), minDecimals, maxDecimals);
48 [[nodiscard]]
char* data() {
return buf_; }
49 [[nodiscard]]
const char* data()
const {
return buf_; }
50 [[nodiscard]]
const char* c_str()
const {
return buf_; }
52 [[nodiscard]]
size_t capacity()
const {
return capacity_; }
53 [[nodiscard]]
size_t size()
const {
return std::strlen(buf_); }
54 [[nodiscard]]
size_t length()
const {
return std::strlen(buf_); }
56 [[nodiscard]]
bool empty()
const {
return buf_[0] ==
'\0'; }
58 bool operator==(
const char* rhs)
const {
return std::strcmp(buf_, rhs) == 0; }
59 bool operator==(
const StringBuf& rhs)
const {
return std::strcmp(buf_, rhs.c_str()) == 0; }
61 operator std::string_view()
const {
return std::string_view{buf_}; }