mark each byte with its utf8 unit number. returns the number of utf8 characters. e.g. when bytes == '\x61\xD0\xB0\x62', then utf8_units will become [0,0,1,0] utf8_nunits will become [1,2,2,1] and 3 is returned. bytes where utf8_units is zero, are the begin of an utf8 character.
| 804 | // utf8_nunits will become [1,2,2,1] and 3 is returned. |
| 805 | // bytes where utf8_units is zero, are the begin of an utf8 character. |
| 806 | static size_t mark_utf8_units(const char* bytes, int * utf8_units, int * utf8_nunits, size_t count) { |
| 807 | size_t offs = 0; |
| 808 | size_t count_utf8 = 0; |
| 809 | while(offs < count) { |
| 810 | int len = (int) utf8_len(bytes[offs]); |
| 811 | for (int i=0; i<len; ++i) { |
| 812 | utf8_units[offs+i] = i; |
| 813 | utf8_nunits[offs+i] = len; |
| 814 | } |
| 815 | offs += len; |
| 816 | ++count_utf8; |
| 817 | } |
| 818 | return count_utf8; |
| 819 | } |
| 820 | |
| 821 | size_t tokenize_file( |
| 822 | struct llama_context * lctx, |
no test coverage detected