FastLED 3.9.15
Loading...
Searching...
No Matches

◆ parse_format_spec()

FormatSpec fl::printf_detail::parse_format_spec ( const char *& format)
inline

Definition at line 109 of file stdio.h.

109 {
110 FormatSpec spec;
111
112 if (*format != '%') {
113 return spec;
114 }
115
116 ++format; // Skip the '%'
117
118 // Handle literal '%'
119 if (*format == '%') {
120 spec.type = '%';
121 ++format;
122 return spec;
123 }
124
125 // Parse flags: -, +, space, #, 0 (can be in any order)
126 bool parsing_flags = true;
127 while (parsing_flags) {
128 switch (*format) {
129 case '-':
130 spec.left_align = true;
131 ++format;
132 break;
133 case '+':
134 spec.show_sign = true;
135 ++format;
136 break;
137 case ' ':
138 spec.space_sign = true;
139 ++format;
140 break;
141 case '#':
142 spec.alt_form = true;
143 ++format;
144 break;
145 case '0':
146 spec.zero_pad = true;
147 ++format;
148 break;
149 default:
150 parsing_flags = false;
151 break;
152 }
153 }
154
155 // Parse width (decimal number)
156 if (*format >= '0' && *format <= '9') {
157 spec.width = 0;
158 while (*format >= '0' && *format <= '9') {
159 spec.width = spec.width * 10 + (*format - '0');
160 ++format;
161 }
162 }
163
164 // Parse precision for floating point
165 if (*format == '.') {
166 ++format; // Skip the '.'
167 spec.precision = 0;
168 while (*format >= '0' && *format <= '9') {
169 spec.precision = spec.precision * 10 + (*format - '0');
170 ++format;
171 }
172 }
173
174 // Skip length modifiers (l, ll, h, hh, L, z, t, j)
175 // We don't use them in our simple printf, but we need to skip them
176 // to get to the actual type character
177 if (*format == 'h' || *format == 'l') {
178 char first = *format;
179 ++format;
180 // Check for double character modifiers (hh, ll)
181 if (*format == first) {
182 ++format;
183 }
184 } else if (*format == 'L' || *format == 'z' || *format == 't' || *format == 'j') {
185 ++format;
186 }
187
188 // Get the format type
189 spec.type = *format;
190 if (spec.type == 'X') {
191 spec.uppercase = true;
192 spec.type = 'x'; // Normalize to lowercase for processing
193 }
194
195 ++format;
196 return spec;
197}
fl::string format(const char *fmt)
Format with no arguments.
Definition format.h:439

References fl::printf_detail::FormatSpec::alt_form, FL_NOEXCEPT, fl::format(), fl::printf_detail::FormatSpec::left_align, fl::printf_detail::FormatSpec::precision, fl::printf_detail::FormatSpec::show_sign, fl::printf_detail::FormatSpec::space_sign, fl::printf_detail::FormatSpec::type, fl::printf_detail::FormatSpec::uppercase, fl::printf_detail::FormatSpec::width, and fl::printf_detail::FormatSpec::zero_pad.

Referenced by format_impl(), and format_impl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: