* Return the byte length of a UTF8 character pointed to by s * * Note: in the current implementation we do not support UTF8 sequences * of more than 4 bytes; hence do NOT return a value larger than 4. * We return "1" for any leading byte that is either flat-out illegal or * indicates a length larger than we support. * * pg_utf2wchar_with_len(), utf8_to_unicode(), pg_utf8_islegal(), and perh
| 565 | * other places would need to be fixed to change this. |
| 566 | */ |
| 567 | int |
| 568 | pg_utf_mblen(const unsigned char *s) |
| 569 | { |
| 570 | int len; |
| 571 | |
| 572 | if ((*s & 0x80) == 0) |
| 573 | len = 1; |
| 574 | else if ((*s & 0xe0) == 0xc0) |
| 575 | len = 2; |
| 576 | else if ((*s & 0xf0) == 0xe0) |
| 577 | len = 3; |
| 578 | else if ((*s & 0xf8) == 0xf0) |
| 579 | len = 4; |
| 580 | #ifdef NOT_USED |
| 581 | else if ((*s & 0xfc) == 0xf8) |
| 582 | len = 5; |
| 583 | else if ((*s & 0xfe) == 0xfc) |
| 584 | len = 6; |
| 585 | #endif |
| 586 | else |
| 587 | len = 1; |
| 588 | return len; |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * This is an implementation of wcwidth() and wcswidth() as defined in |
no outgoing calls
no test coverage detected