** Output string zUtf to stream pOut as w characters. If w is negative, ** then right-justify the text. W is the width in UTF-8 characters, not ** in bytes. This is different from the %*.*s specification in printf ** since with %*.*s the width is measured in bytes, not characters. */
| 568 | ** since with %*.*s the width is measured in bytes, not characters. |
| 569 | */ |
| 570 | static void utf8_width_print(FILE *pOut, int w, const char *zUtf){ |
| 571 | int i; |
| 572 | int n; |
| 573 | int aw = w<0 ? -w : w; |
| 574 | for(i=n=0; zUtf[i]; i++){ |
| 575 | if( (zUtf[i]&0xc0)!=0x80 ){ |
| 576 | n++; |
| 577 | if( n==aw ){ |
| 578 | do{ i++; }while( (zUtf[i]&0xc0)==0x80 ); |
| 579 | break; |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | if( n>=aw ){ |
| 584 | utf8_printf(pOut, "%.*s", i, zUtf); |
| 585 | }else if( w<0 ){ |
| 586 | utf8_printf(pOut, "%*s%s", aw-n, "", zUtf); |
| 587 | }else{ |
| 588 | utf8_printf(pOut, "%s%*s", zUtf, aw-n, ""); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | |
| 593 | /* |
no test coverage detected