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