size_t display_wstr(t_mod *m, wchar_t *buf) { size_t cnt; char tmp[5]; size_t sizew; size_t prec; cnt = sizew_to_print(m, buf); prec = MIN(m->prec, cnt); if (!GET(m->flag, F_MINUS)) cnt += display_space_w(m, cnt); sizew = 0; while (GET(m->flag, F_PREC) ? sizew <= prec : *buf) { if ((prec - sizew) < size_wc(*buf) && GET(m->flag, F_PREC)) break ; ft_widetoa(tmp, 5, (int)(*buf)); ft_putstr(tmp); sizew += size_wc(*buf); buf++; } if (GET(m->flag, F_MINUS)) cnt += display_space_w(m, cnt); return (cnt); }
static size_t size_wc(int wc) { char tmp[5]; ft_widetoa(tmp, 5, wc); return (ft_strlen(tmp)); }
size_t display_c(t_mod *m, int arg) { size_t cnt; char buf[5]; cnt = 0; ft_widetoa(buf, 5, arg); if (!GET(m->flag, F_MINUS)) cnt += display_space(m, buf); if (!GET(m->modif, MOD_L) && arg > 127) { ft_putchar(arg); cnt += 1; } else { ft_putstr(buf); cnt += (ft_strlen(buf) ? ft_strlen(buf) : 1); } if (!*buf) ft_putchar('\0'); if (GET(m->flag, F_MINUS)) cnt += display_space(m, buf); return (cnt); }
int ft_wstrconv(char *buff, wchar_t *wstr) { int i; int len; len = 0; i = -1; while (wstr[++i] != 0) len += ft_widetoa(buff + len, wstr[i]); return (len); }
int ft_wstrnconv(char *buff, wchar_t *wstr, int n) { int i; int tmp; int len; len = 0; i = -1; while (wstr[++i] != 0) { tmp = ft_widetoa(buff + len, wstr[i]); if ((tmp + len) > n) break ; len += tmp; } return (len); }
static size_t sizew_to_print(t_mod *m, wchar_t *buf) { int i; size_t sizew; char tmp[5]; int flag; int tmprec; i = 0; sizew = 0; flag = 0; tmprec = (int)m->prec; if (GET(m->flag, F_PREC)) flag = 1; while (buf[i] && (flag ? (int)sizew < tmprec : 1)) { if ((tmprec - sizew) < size_wc(buf[i]) && GET(m->flag, F_PREC)) break ; ft_widetoa(tmp, 5, (int)(buf[i])); sizew += ft_strlen(tmp); i++; } return (sizew); }