common_util
Loading...
Searching...
No Matches
strfmt.h
Go to the documentation of this file.
1
19#pragma once
20
21#include <string>
22#include <cstdint>
23#include <sstream>
24#include <iomanip>
25#include "timeutil.h"
26
27namespace cutl
28{
37 std::string fmt_uint(uint64_t val, uint8_t width = 0, char fill = '0');
45 std::string fmt_double(double val, int precision = 2);
46
55 std::string fmt_filesize(uint64_t size, bool simplify = true, int precision = 1);
56
63 std::string fmt_timeduration_s(uint64_t seconds);
70 std::string fmt_timeduration_ms(uint64_t microseconds);
77 std::string fmt_timeduration_us(uint64_t nanoseconds);
78
88 std::string fmt_timestamp(uint64_t second, bool local, const std::string &fmt);
97 std::string fmt_timestamp_s(uint64_t second, bool local = true);
106 std::string fmt_timestamp_ms(uint64_t ms, bool local = true);
115 std::string fmt_timestamp_us(uint64_t us, bool local = true);
116
126 std::string to_hex(const uint8_t *data, size_t len, bool upper = true, char separator = ' ');
135 std::string to_hex(uint8_t value, bool upper = true, const std::string &prefix = "");
144 std::string to_hex(uint16_t value, bool upper = true, const std::string &prefix = "");
153 std::string to_hex(uint32_t value, bool upper = true, const std::string &prefix = "");
162 std::string to_hex(uint64_t value, bool upper = true, const std::string &prefix = "");
163
171 std::string to_bin(uint8_t value, char separator = ',');
179 std::string to_bin(uint16_t value, char separator = ' ');
187 std::string to_bin(uint32_t value, char separator = ' ');
195 std::string to_bin(uint64_t value, char separator = ' ');
196
197} // namespace
std::string fmt_timestamp_ms(uint64_t ms, bool local=true)
Format a timestamp to a human-readable string.
std::string fmt_timestamp_s(uint64_t second, bool local=true)
Format a timestamp to a human-readable string.
std::string fmt_uint(uint64_t val, uint8_t width=0, char fill='0')
Format uint64 value to a string with a given width and fill character.
std::string fmt_timestamp(uint64_t second, bool local, const std::string &fmt)
Format a timestamp to a human-readable string with a given format.
std::string fmt_timeduration_us(uint64_t nanoseconds)
Format a time duration to a human-readable string.
std::string fmt_filesize(uint64_t size, bool simplify=true, int precision=1)
Format a file size to a human-readable string with a given precision.
std::string fmt_double(double val, int precision=2)
Format double value to a string with a given precision.
std::string fmt_timeduration_s(uint64_t seconds)
Format a time duration to a human-readable string.
std::string fmt_timestamp_us(uint64_t us, bool local=true)
Format a timestamp to a human-readable string.
std::string to_bin(uint8_t value, char separator=',')
Format uint8_t value to a binary string.
std::string fmt_timeduration_ms(uint64_t microseconds)
Format a time duration to a human-readable string.
std::string to_hex(const uint8_t *data, size_t len, bool upper=true, char separator=' ')
Format data to a hex string.
Common time utilities.