FastLED 3.9.15
Loading...
Searching...
No Matches
charconv.h
Go to the documentation of this file.
1#pragma once
2
4// FastLED Character Conversion Functions (charconv.h equivalents)
5//
6// Provides character/string conversion utilities similar to C++17 <charconv>
7// but adapted for embedded platforms and FastLED's needs.
8//
9// All functions are in the fl:: namespace.
11
12#include "fl/stl/stdint.h" // For u64, uint8_t
13#include "fl/stl/cstddef.h" // For fl::size_t
14#include "fl/stl/noexcept.h"
16
17namespace fl {
18
19// Forward declaration to avoid circular dependency
20class string;
21
36template<typename T>
37fl::string to_hex(T value, bool uppercase = false, bool pad_to_width = false) FL_NOEXCEPT;
38
39namespace detail {
40
42enum class HexIntWidth : u8 {
43 Width8 = 8,
44 Width16 = 16,
45 Width32 = 32,
47};
48
56fl::string hex(u64 value, HexIntWidth width, bool is_negative, bool uppercase, bool pad_to_width) FL_NOEXCEPT;
57
59template<size_t Size>
61 FL_STATIC_ASSERT(Size == 0, "Unsupported type size for hex conversion");
62 return HexIntWidth::Width8; // Unreachable, but needed for compilation
63}
64
66template<>
70
72template<>
76
78template<>
82
84template<>
88
89} // namespace detail
90
91// Low-level integer to string conversion functions
92// These provide the foundational conversion logic for fl::string and fl::sstream
93
99int itoa(i32 value, char *buffer, int radix) FL_NOEXCEPT;
100
106int itoa64(i64 value, char *buffer, int radix) FL_NOEXCEPT;
107
113int utoa32(u32 value, char *buffer, int radix) FL_NOEXCEPT;
114
120int utoa64(u64 value, char *buffer, int radix) FL_NOEXCEPT;
121
126void ftoa(float value, char *buffer, int precision = 2) FL_NOEXCEPT;
127
132float parseFloat(const char *str, fl::size len) FL_NOEXCEPT;
133
138int parseInt(const char *str, fl::size len) FL_NOEXCEPT;
139
143int parseInt(const char *str) FL_NOEXCEPT;
144
145} // namespace fl
146
148// Template Implementation Section
149//
150// NOTE: The template implementation for to_hex<T>() is defined at the END of
151// fl/stl/string.h (after the fl::string class definition is complete).
152// This avoids circular dependency issues where charconv.h is included by
153// string.h before the string class is fully defined.
fl::i64 i64
Definition s16x16x4.h:222
fl::u64 u64
Definition s16x16x4.h:221
constexpr HexIntWidth get_hex_int_width() FL_NOEXCEPT
Compile-time integer width determination (default - triggers error)
Definition charconv.h:60
HexIntWidth
Integer width classification for hex conversion.
Definition charconv.h:42
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
unsigned char u8
Definition stdint.h:131
constexpr int type_rank< T >::value
int itoa(i32 value, char *sp, int radix)
Convert signed 32-bit integer to string buffer in given radix.
int utoa64(u64 value, char *sp, int radix)
Convert unsigned 64-bit integer to string buffer in given radix.
int parseInt(const char *str, fl::size len)
Parse an integer from a character buffer.
int utoa32(u32 value, char *sp, int radix)
Convert unsigned 32-bit integer to string buffer in given radix.
fl::string to_hex(T value, bool uppercase=false, bool pad_to_width=false) FL_NOEXCEPT
Convert an integer value to hexadecimal string representation.
Definition string.h:517
const hex_t hex
Definition ios.cpp.hpp:6
u8 width
Definition blur.h:186
int itoa64(i64 value, char *sp, int radix)
Convert signed 64-bit integer to string buffer in given radix.
float parseFloat(const char *str, fl::size len)
Parse a floating point number from a character buffer.
fl::u64 u64
Definition s16x16x4.h:221
void ftoa(float value, char *buffer, int precision)
Convert floating point number to string buffer.
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_STATIC_ASSERT(...)
#define FL_NOEXCEPT
Portable compile-time assertion wrapper.