Print wide string. * * @param str Wide string to be printed. * @param width Width modifier. * @param precision Precision modifier. * @param flags Flags that modify the way the string is printed. * * @return Number of wide characters printed, negative value on failure. */
| 326 | * @return Number of wide characters printed, negative value on failure. |
| 327 | */ |
| 328 | static int print_wstr(char32_t *str, int width, unsigned int precision, |
| 329 | uint32_t flags, printf_spec_t *ps) |
| 330 | { |
| 331 | if (str == NULL) |
| 332 | return printf_putstr(nullstr, ps); |
| 333 | |
| 334 | /* Print leading spaces. */ |
| 335 | size_t strw = wstr_length(str); |
| 336 | if ((precision == 0) || (precision > strw)) |
| 337 | precision = strw; |
| 338 | |
| 339 | /* Left padding */ |
| 340 | size_t counter = 0; |
| 341 | width -= precision; |
| 342 | if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { |
| 343 | while (width-- > 0) { |
| 344 | if (printf_putchar(' ', ps) == 1) |
| 345 | counter++; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /* Part of @a wstr fitting into the alloted space. */ |
| 350 | int retval; |
| 351 | size_t size = wstr_lsize(str, precision); |
| 352 | if ((retval = printf_wputnchars(str, size, ps)) < 0) |
| 353 | return -counter; |
| 354 | |
| 355 | counter += retval; |
| 356 | |
| 357 | /* Right padding */ |
| 358 | while (width-- > 0) { |
| 359 | if (printf_putchar(' ', ps) == 1) |
| 360 | counter++; |
| 361 | } |
| 362 | |
| 363 | return ((int) counter); |
| 364 | } |
| 365 | |
| 366 | /** Print a number in a given base. |
| 367 | * |
no test coverage detected