diff options
| author | Jeff Epler <jepler@gmail.com> | 2020-09-08 19:07:53 -0500 |
|---|---|---|
| committer | Jeff Epler <jepler@gmail.com> | 2020-09-08 19:07:53 -0500 |
| commit | bdb07adfccaf25576a8f1e074db7f8b7e48890b2 (patch) | |
| tree | e39e4c954e03677ee2fb57d1f22f22227bfaebbb /supervisor | |
| parent | cbfd38d1ce8839e11e828b0e8742d5d983446313 (diff) | |
translations: Make decompression clearer
Now this gets filled in with values e.g., 128 (0x80) and 159 (0x9f).
Diffstat (limited to 'supervisor')
| -rw-r--r-- | supervisor/shared/translate.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/supervisor/shared/translate.c b/supervisor/shared/translate.c index 49ee8f143..0235293be 100644 --- a/supervisor/shared/translate.c +++ b/supervisor/shared/translate.c @@ -47,19 +47,18 @@ STATIC int put_utf8(char *buf, int u) { if(u <= 0x7f) { *buf = u; return 1; - } else if(MP_ARRAY_SIZE(ngrams) <= 64 && u <= 0xbf) { + } else if(bigram_start <= u && u <= bigram_end) { int n = (u - 0x80) * 2; - int ret = put_utf8(buf, ngrams[n]); - return ret + put_utf8(buf + ret, ngrams[n+1]); + // (note that at present, entries in the bigrams table are + // guaranteed not to represent bigrams themselves, so this adds + // at most 1 level of recursive call + int ret = put_utf8(buf, bigrams[n]); + return ret + put_utf8(buf + ret, bigrams[n+1]); } else if(u <= 0x07ff) { *buf++ = 0b11000000 | (u >> 6); *buf = 0b10000000 | (u & 0b00111111); return 2; - } else if(MP_ARRAY_SIZE(ngrams) > 64 && u >= 0xe000 && u <= 0xf8ff) { - int n = (u - 0xe000) * 2; - int ret = put_utf8(buf, ngrams[n]); - return ret + put_utf8(buf + ret, ngrams[n+1]); - } else { // u <= 0xffff) + } else { // u <= 0xffff *buf++ = 0b11000000 | (u >> 12); *buf = 0b10000000 | ((u >> 6) & 0b00111111); *buf = 0b10000000 | (u & 0b00111111); |
