FastLED 3.10.6
Loading...
Searching...
No Matches

◆ parse_format_spec()

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

Definition at line 130 of file stdio.h.

130 {
131 FormatSpec spec;
132
133 if (*format != '%') {
134 return spec;
135 }
136
137 ++format; // Skip the '%'
138
139 // Handle literal '%'
140 if (*format == '%') {
141 spec.type = '%';
142 ++format;
143 return spec;
144 }
145
146 // Parse flags: -, +, space, #, 0 (can be in any order)
147 bool parsing_flags = true;
148 while (parsing_flags) {
149 switch (*format) {
150 case '-':
151 spec.left_align = true;
152 ++format;
153 break;
154 case '+':
155 spec.show_sign = true;
156 ++format;
157 break;
158 case ' ':
159 spec.space_sign = true;
160 ++format;
161 break;
162 case '#':
163 spec.alt_form = true;
164 ++format;
165 break;
166 case '0':
167 spec.zero_pad = true;
168 ++format;
169 break;
170 default:
171 parsing_flags = false;
172 break;
173 }
174 }
175
176 // Parse width (decimal number)
177 if (*format >= '0' && *format <= '9') {
178 spec.width = 0;
179 while (*format >= '0' && *format <= '9') {
180 spec.width = spec.width * 10 + (*format - '0');
181 ++format;
182 }
183 }
184
185 // Parse precision for floating point
186 if (*format == '.') {
187 ++format; // Skip the '.'
188 spec.precision = 0;
189 while (*format >= '0' && *format <= '9') {
190 spec.precision = spec.precision * 10 + (*format - '0');
191 ++format;
192 }
193 }
194
195 // Skip length modifiers (l, ll, h, hh, L, z, t, j)
196 // We don't use them in our simple printf, but we need to skip them
197 // to get to the actual type character
198 if (*format == 'h' || *format == 'l') {
199 char first = *format;
200 ++format;
201 // Check for double character modifiers (hh, ll)
202 if (*format == first) {
203 ++format;
204 }
205 } else if (*format == 'L' || *format == 'z' || *format == 't' || *format == 'j') {
206 ++format;
207 }
208
209 // Get the format type
210 spec.type = *format;
211 if (spec.type == 'X') {
212 spec.uppercase = true;
213 spec.type = 'x'; // Normalize to lowercase for processing
214 }
215
216 // Only advance past the type character if there actually is one. A format
217 // string ending in a bare '%' leaves spec.type == '\0'; advancing here
218 // would step past the NUL terminator and make the caller's loop read out
219 // of bounds.
220 if (spec.type != '\0') {
221 ++format;
222 }
223 return spec;
224}
fl::string format(const char *fmt)
Format with no arguments.
Definition format.h:439

References fl::printf_detail::FormatSpec::alt_form, fl::FL_NO_EXCEPT, 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(), format_impl(), fl::printf(), and fl::snprintf().

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