Rev 4205 | Rev 4207 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4205 | Rev 4206 | ||
---|---|---|---|
Line 250... | Line 250... | ||
250 | static int print_utf8(char *str, int width, unsigned int precision, |
250 | static int print_utf8(char *str, int width, unsigned int precision, |
251 | uint32_t flags, printf_spec_t *ps) |
251 | uint32_t flags, printf_spec_t *ps) |
252 | { |
252 | { |
253 | if (str == NULL) |
253 | if (str == NULL) |
254 | return printf_putstr(nullstr, ps); |
254 | return printf_putstr(nullstr, ps); |
255 | 255 | ||
256 | /* Print leading spaces */ |
256 | /* Print leading spaces. */ |
257 | size_t size = str_length(str); |
257 | count_t strw = str_length(str); |
258 | if (precision == 0) |
258 | if (precision == 0) |
259 | precision = size; |
259 | precision = strw; |
260 | 260 | ||
261 | count_t counter = 0; |
261 | count_t counter = 0; |
262 | width -= precision; |
262 | width -= precision; |
263 | if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { |
263 | if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { |
264 | while (width-- > 0) { |
264 | while (width-- > 0) { |
Line 266... | Line 266... | ||
266 | counter++; |
266 | counter++; |
267 | } |
267 | } |
268 | } |
268 | } |
269 | 269 | ||
270 | int retval; |
270 | int retval; |
271 | size_t bytes = str_lsize(str, min(size, precision)); |
271 | size_t size = str_lsize(str, precision); |
272 | if ((retval = printf_putnchars_utf8(str, bytes, ps)) < 0) |
272 | if ((retval = printf_putnchars_utf8(str, size, ps)) < 0) |
273 | return -counter; |
273 | return -counter; |
274 | 274 | ||
275 | counter += retval; |
275 | counter += retval; |
276 | 276 | ||
277 | while (width-- > 0) { |
277 | while (width-- > 0) { |
278 | if (printf_putchar(' ', ps) == 1) |
278 | if (printf_putchar(' ', ps) == 1) |
279 | counter++; |
279 | counter++; |
280 | } |
280 | } |
281 | 281 | ||
282 | return ((int) counter); |
282 | return ((int) counter); |
- | 283 | ||
283 | } |
284 | } |
284 | 285 | ||
285 | /** Print UTF-32 string. |
286 | /** Print UTF-32 string. |
286 | * |
287 | * |
287 | * @param str UTF-32 string to be printed. |
288 | * @param str UTF-32 string to be printed. |
Line 289... | Line 290... | ||
289 | * @param precision Precision modifier. |
290 | * @param precision Precision modifier. |
290 | * @param flags Flags that modify the way the string is printed. |
291 | * @param flags Flags that modify the way the string is printed. |
291 | * |
292 | * |
292 | * @return Number of UTF-32 characters printed, negative value on failure. |
293 | * @return Number of UTF-32 characters printed, negative value on failure. |
293 | */ |
294 | */ |
294 | static int print_utf32(wchar_t *str, int width, unsigned int precision, |
295 | static int print_utf32(wchar_t *wstr, int width, unsigned int precision, |
295 | uint32_t flags, printf_spec_t *ps) |
296 | uint32_t flags, printf_spec_t *ps) |
296 | { |
297 | { |
297 | if (str == NULL) |
298 | if (wstr == NULL) |
298 | return printf_putstr(nullstr, ps); |
299 | return printf_putstr(nullstr, ps); |
299 | 300 | ||
300 | /* Print leading spaces */ |
301 | /* Print leading spaces. */ |
301 | size_t size = wstr_length(str); |
302 | size_t strw = wstr_length(wstr); |
302 | if (precision == 0) |
303 | if (precision == 0) |
303 | precision = size; |
304 | precision = strw; |
304 | 305 | ||
305 | count_t counter = 0; |
306 | count_t counter = 0; |
306 | width -= precision; |
307 | width -= precision; |
307 | if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { |
308 | if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { |
308 | while (width-- > 0) { |
309 | while (width-- > 0) { |
309 | if (printf_putchar(' ', ps) == 1) |
310 | if (printf_putchar(' ', ps) == 1) |
310 | counter++; |
311 | counter++; |
311 | } |
312 | } |
312 | } |
313 | } |
313 | 314 | ||
314 | int retval; |
315 | int retval; |
315 | size_t bytes = min(size, precision) * sizeof(wchar_t); |
316 | size_t size = min(strw, precision) * sizeof(wchar_t); |
316 | if ((retval = printf_putnchars_utf32(str, bytes, ps)) < 0) |
317 | if ((retval = printf_putnchars_utf32(wstr, size, ps)) < 0) |
317 | return -counter; |
318 | return -counter; |
318 | 319 | ||
319 | counter += retval; |
320 | counter += retval; |
320 | 321 | ||
321 | while (width-- > 0) { |
322 | while (width-- > 0) { |
322 | if (printf_putchar(' ', ps) == 1) |
323 | if (printf_putchar(' ', ps) == 1) |
323 | counter++; |
324 | counter++; |
324 | } |
325 | } |
325 | 326 | ||
326 | return ((int) counter); |
327 | return ((int) counter); |
327 | } |
328 | } |
328 | 329 | ||
329 | /** Print a number in a given base. |
330 | /** Print a number in a given base. |
330 | * |
331 | * |
Line 582... | Line 583... | ||
582 | * @return Number of UTF-8 characters printed, negative value on failure. |
583 | * @return Number of UTF-8 characters printed, negative value on failure. |
583 | * |
584 | * |
584 | */ |
585 | */ |
585 | int printf_core(const char *fmt, printf_spec_t *ps, va_list ap) |
586 | int printf_core(const char *fmt, printf_spec_t *ps, va_list ap) |
586 | { |
587 | { |
587 | index_t i = 0; /* Index of the currently processed character from fmt */ |
588 | size_t i = 0; /* Index of the currently processed character from fmt */ |
588 | index_t nxt = 0; |
589 | size_t nxt = 0; |
589 | index_t j = 0; /* Index to the first not printed nonformating character */ |
590 | size_t j = 0; /* Index to the first not printed nonformating character */ |
590 | 591 | ||
591 | wchar_t uc; /* Current UTF-32 character decoded from fmt */ |
592 | wchar_t uc; /* Current UTF-32 character decoded from fmt */ |
592 | count_t counter = 0; /* Number of UTF-8 characters printed */ |
593 | count_t counter = 0; /* Number of UTF-8 characters printed */ |
593 | int retval; /* Return values from nested functions */ |
594 | int retval; /* Return values from nested functions */ |
594 | 595 |