31template<
typename... Args>
32void printf(
const char* format,
const Args&...
args);
56template<
typename... Args>
57int snprintf(
char* buffer, fl::size size,
const char* format,
const Args&...
args);
74template<fl::size N,
typename... Args>
75int sprintf(
char (&buffer)[N],
const char* format,
const Args&...
args);
105 if (*format ==
'%') {
112 if (*format ==
'.') {
115 while (*format >=
'0' && *format <=
'9') {
123 if (spec.
type ==
'X') {
143 if (precision == 0) {
144 int int_part =
static_cast<int>(value + 0.5f);
152 for (
int i = 0; i < precision; ++i) {
156 int scaled =
static_cast<int>(value * multiplier + 0.5f);
157 int int_part = scaled / multiplier;
158 int frac_part = scaled % multiplier;
165 int temp_multiplier = multiplier / 10;
166 while (temp_multiplier > frac_part && temp_multiplier > 1) {
168 temp_multiplier /= 10;
186 const char* digits = uppercase ?
"0123456789ABCDEF" :
"0123456789abcdef";
189 bool negative =
false;
196 char ch = digits[value % 16];
198 char temp_ch_str[2] = {ch,
'\0'};
232 stream <<
"<type_error>";
239 unsigned int val =
static_cast<unsigned int>(arg);
245 char digit =
'0' + (val % 10);
246 char temp_str[2] = {digit,
'\0'};
256 stream <<
"<type_error>";
263 stream << format_float(static_cast<float>(arg), spec.
precision);
268 stream <<
"<type_error>";
274 char ch =
static_cast<char>(arg);
276 char temp_str[2] = {ch,
'\0'};
279 stream <<
"<type_error>";
292 stream <<
"<unknown_format>";
304 stream <<
"<string_not_hex>";
311 stream <<
"<type_error>";
314 stream <<
"<unknown_format>";
322 format_arg(stream, spec,
static_cast<const char*
>(arg));
328 if (*format ==
'%') {
330 if (spec.
type ==
'%') {
334 stream <<
"<missing_arg>";
338 char temp_str[2] = {*format,
'\0'};
346template<
typename T,
typename... Args>
349 if (*format ==
'%') {
351 if (spec.
type ==
'%') {
361 char temp_str[2] = {*format,
'\0'};
392template<
typename... Args>
421template<
typename... Args>
422int snprintf(
char* buffer, fl::size size,
const char* format,
const Args&...
args) {
424 if (!buffer || size == 0) {
434 fl::size formatted_len =
result.size();
437 fl::size copy_len = (formatted_len < size - 1) ? formatted_len : size - 1;
440 for (fl::size i = 0; i < copy_len; ++i) {
445 buffer[copy_len] =
'\0';
449 return static_cast<int>(copy_len);
467template<fl::size N,
typename... Args>
468int sprintf(
char (&buffer)[N],
const char* format,
const Args&...
args) {
const char * c_str() const
const string & str() const
Result type for promise operations.
Implements the FastLED namespace macros.
fl::string format_float(float value, int precision)
void format_impl(StrStream &stream, const char *format)
FormatSpec parse_format_spec(const char *&format)
void format_arg(StrStream &stream, const FormatSpec &spec, const T &arg)
fl::enable_if< fl::is_integral< T >::value, fl::string >::type to_hex(T value, bool uppercase)
void print(const char *str)
int snprintf(char *buffer, fl::size size, const char *format, const Args &... args)
Snprintf-like formatting function that writes to a buffer.
void printf(const char *format, const Args &... args)
Printf-like formatting function that prints directly to the platform output.
int sprintf(char(&buffer)[N], const char *format, const Args &... args)
Sprintf-like formatting function that writes to a buffer.
static constexpr bool value
static constexpr bool value
static constexpr bool value