File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed
Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change 22#define HERB_UTF8_H
33
44#include <stdbool.h>
5+ #include <stdint.h>
56#include <stdlib.h>
67
7- int utf8_char_byte_length (unsigned char first_byte );
8- int utf8_sequence_length (const char * str , size_t position , size_t max_length );
8+ uint32_t utf8_char_byte_length (unsigned char first_byte );
9+ uint32_t utf8_sequence_length (const char * str , size_t position , size_t max_length );
910bool utf8_is_valid_continuation_byte (unsigned char byte );
1011
1112#endif
Original file line number Diff line number Diff line change 55// 110xxxxx = 2 bytes
66// 1110xxxx = 3 bytes
77// 11110xxx = 4 bytes
8- int utf8_char_byte_length (unsigned char first_byte ) {
8+ uint32_t utf8_char_byte_length (unsigned char first_byte ) {
99 if ((first_byte & 0x80 ) == 0 ) {
1010 return 1 ;
1111 } else if ((first_byte & 0xE0 ) == 0xC0 ) {
@@ -24,18 +24,18 @@ bool utf8_is_valid_continuation_byte(unsigned char byte) {
2424 return (byte & 0xC0 ) == 0x80 ;
2525}
2626
27- int utf8_sequence_length (const char * str , size_t position , size_t max_length ) {
27+ uint32_t utf8_sequence_length (const char * str , size_t position , size_t max_length ) {
2828 if (position >= max_length ) { return 0 ; }
2929
3030 unsigned char first_byte = (unsigned char ) str [position ];
31- int expected_length = utf8_char_byte_length (first_byte );
31+ uint32_t expected_length = utf8_char_byte_length (first_byte );
3232
3333 if (position + expected_length > max_length ) {
3434 return 1 ; // Not enough bytes, treat as single byte
3535 }
3636
3737 if (expected_length > 1 ) {
38- for (int i = 1 ; i < expected_length ; i ++ ) {
38+ for (uint32_t i = 1 ; i < expected_length ; i ++ ) {
3939 if (!utf8_is_valid_continuation_byte ((unsigned char ) str [position + i ])) {
4040 return 1 ; // Invalid continuation byte, treat first byte as single byte
4141 }
You can’t perform that action at this time.
0 commit comments