** 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. */
| 674 | ** since with %*.*s the width is measured in bytes, not characters. |
| 675 | */ |
| 676 | static void utf8_width_print(FILE *pOut, int w, const char *zUtf){ |
| 677 | int i; |
| 678 | int n; |
| 679 | int aw = w<0 ? -w : w; |
| 680 | if( zUtf==0 ) zUtf = ""; |
| 681 | for(i=n=0; zUtf[i]; i++){ |
| 682 | if( (zUtf[i]&0xc0)!=0x80 ){ |
| 683 | n++; |
| 684 | if( n==aw ){ |
| 685 | do{ i++; }while( (zUtf[i]&0xc0)==0x80 ); |
| 686 | break; |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | if( n>=aw ){ |
| 691 | utf8_printf(pOut, "%.*s", i, zUtf); |
| 692 | }else if( w<0 ){ |
| 693 | utf8_printf(pOut, "%*s%s", aw-n, "", zUtf); |
| 694 | }else{ |
| 695 | utf8_printf(pOut, "%s%*s", zUtf, aw-n, ""); |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | |
| 700 | /* |
no test coverage detected