Get the byte position corresponding to a character position for a non-empty utf8 sequence
| 224 | // Get the byte position corresponding to a character position for a non-empty utf8 |
| 225 | // sequence |
| 226 | FORCE_INLINE |
| 227 | gdv_int32 utf8_byte_pos(gdv_int64 context, const char* str, gdv_int32 str_len, |
| 228 | gdv_int32 char_pos) { |
| 229 | int char_len = 0; |
| 230 | int byte_index = 0; |
| 231 | for (gdv_int32 char_index = 0; char_index < char_pos && byte_index < str_len; |
| 232 | char_index++) { |
| 233 | char_len = utf8_char_length(str[byte_index]); |
| 234 | if (char_len == 0 || |
| 235 | byte_index + char_len > str_len) { // invalid byte or incomplete glyph |
| 236 | set_error_for_invalid_utf(context, str[byte_index]); |
| 237 | return -1; |
| 238 | } |
| 239 | byte_index += char_len; |
| 240 | } |
| 241 | return byte_index; |
| 242 | } |
| 243 | |
| 244 | #define UTF8_LENGTH(NAME, TYPE) \ |
| 245 | FORCE_INLINE \ |
no outgoing calls
no test coverage detected