36template<
typename... Args>
63template<
typename... Args>
81template<fl::size N,
typename... Args>
126 bool parsing_flags =
true;
127 while (parsing_flags) {
150 parsing_flags =
false;
190 if (spec.
type ==
'X') {
210 unsigned long long val =
static_cast<unsigned long long>(
value);
212 buffer[--
pos] =
'0' + (val & 7);
221 int len =
static_cast<int>(str.
length());
224 if (spec.
width <= len) {
228 int padding = spec.
width - len;
236 if (!str.
empty() && (str[0] ==
'-' || str[0] ==
'+' || str[0] ==
' ')) {
239 for (
int i = 0; i < padding; ++i) {
242 for (
size_t i = 1; i < str.
length(); ++i) {
249 if (str.
length() >= 2 && str[0] ==
'0' && (str[1] ==
'x' || str[1] ==
'X')) {
253 for (
int i = 0; i < padding; ++i) {
256 for (
size_t i = 2; i < str.
length(); ++i) {
267 for (
int i = 0; i < padding; ++i) {
272 for (
int i = 0; i < padding; ++i) {
292 if (precision == 0) {
293 int int_part =
static_cast<int>(
value + 0.5f);
301 for (
int i = 0; i < precision; ++i) {
306 float scaled_float =
value * multiplier;
308 if (scaled_float >= 0) {
309 scaled =
static_cast<int>(scaled_float + 0.5f);
311 scaled =
static_cast<int>(scaled_float - 0.5f);
314 int int_part = scaled / multiplier;
315 int frac_part = scaled % multiplier;
319 frac_part = -frac_part;
325 if (
value < 0 && int_part == 0) {
336 int temp_multiplier = multiplier / 10;
337 while (temp_multiplier > 0) {
338 int digit = (frac_part / temp_multiplier) % 10;
339 stream << static_cast<char>(
'0' + digit);
340 temp_multiplier /= 10;
350 const void* vptr =
static_cast<const void*
>(ptr);
351 return reinterpret_cast<fl::uptr
>(vptr);
366 bool is_numeric =
false;
385 if (spec.show_sign) {
387 }
else if (spec.space_sign) {
419 if (spec.alt_form && arg != 0) {
432 if (spec.alt_form && arg != 0) {
445 if (spec.precision >= 0) {
449 temp << static_cast<float>(arg);
461 char ch =
static_cast<char>(arg);
462 char temp_str[2] = {ch,
'\0'};
475 result =
"<unknown_format>";
491 bool is_numeric =
false;
493 if (spec.type ==
'p') {
517 bool is_numeric =
false;
530 const void* ptr =
static_cast<const void*
>(arg);
531 fl::uptr addr =
reinterpret_cast<fl::uptr
>(ptr);
536 result =
"<string_not_hex>";
547 result =
"<unknown_format>";
559 format_arg(stream, spec,
static_cast<const char*
>(arg));
567 if (spec.
type ==
'%') {
572 stream <<
"<missing_arg>";
577 char temp_str[2] = {*
format,
'\0'};
585template<
typename T,
typename... Args>
590 if (spec.
type ==
'%') {
601 char temp_str[2] = {*
format,
'\0'};
634template<
typename... Args>
665template<
typename... Args>
668 if (!buffer || size == 0) {
678 fl::size formatted_len =
result.size();
681 fl::size copy_len = (formatted_len < size - 1) ? formatted_len : size - 1;
684 for (fl::size i = 0; i < copy_len; ++i) {
689 buffer[copy_len] =
'\0';
693 return static_cast<int>(copy_len);
711template<fl::size N,
typename... Args>
fl::size length() const FL_NOEXCEPT
bool empty() const FL_NOEXCEPT
const char * c_str() const FL_NOEXCEPT
string str() const FL_NOEXCEPT
fl::enable_if<!fl::is_pointer< T >::value >::type format_arg(sstream &stream, const FormatSpec &spec, const T &arg) FL_NOEXCEPT
fl::string to_octal(T value) FL_NOEXCEPT
fl::string format_float(float value, int precision) FL_NOEXCEPT
fl::string apply_width(const fl::string &str, const FormatSpec &spec, bool is_numeric=false) FL_NOEXCEPT
FormatSpec parse_format_spec(const char *&format) FL_NOEXCEPT
fl::enable_if< fl::is_pointer< T >::value, fl::uptr >::type pointer_to_uptr(const T &ptr) FL_NOEXCEPT
void format_impl(sstream &stream, const char *format) FL_NOEXCEPT
constexpr int type_rank< T >::value
void print(const char *str)
void printf(const char *format, const Args &... args) FL_NOEXCEPT
Printf-like formatting function that prints directly to the platform output.
int snprintf(char *buffer, fl::size size, const char *format, const Args &... args) FL_NOEXCEPT
Snprintf-like formatting function that writes to a buffer.
fl::string to_hex(T value, bool uppercase=false, bool pad_to_width=false) FL_NOEXCEPT
Convert an integer value to hexadecimal string representation.
int sprintf(char(&buffer)[N], const char *format, const Args &... args) FL_NOEXCEPT
Sprintf-like formatting function that writes to a buffer.
expected< T, E > result
Alias for expected (Rust-style naming)
fl::string format(const char *fmt)
Format with no arguments.
Base definition for an LED controller.