Unified · Split
| @@ -2,11 +2,15 @@ · 1 unmodified line | ||
| 2 | 2 | #include "tagspriv.h" |
| 3 | 3 | |
| 4 | 4 | int |
| 5 | −iso88591toutf8(uint8_t *o, int osz, const uint8_t *s, int sz) | |
| 5 | +iso88591toutf8(uint8_t *o0, int osz, const uint8_t *s, int sz) | |
| 6 | 6 | { |
| 7 | + uint8_t *o; | |
| 7 | 8 | int i; |
| 8 | 9 | |
| 10 | + o = o0; | |
| 9 | 11 | for(i = 0; i < sz && osz > 1 && s[i] != 0; i++){ |
| 12 | + if(s[i] >= 0x7f && s[i] <= 0x9f) /* not expecting control chars */ | |
| 13 | + goto asis; | |
| 10 | 14 | if(s[i] >= 0xa0 && osz < 3) |
| 11 | 15 | break; |
| 12 | 16 | |
| @@ -26,4 +30,12 @@ iso88591toutf8(uint8_t *o, int osz, const uint8_t *s, int sz) · 13 unmodified lines | ||
| 26 | 30 | |
| 27 | 31 | *o = 0; |
| 28 | 32 | return i; |
| 33 | + | |
| 34 | +asis: | |
| 35 | + /* FIXME - copy within UTF-8 chars boundaries */ | |
| 36 | + if(sz >= osz) | |
| 37 | + sz = osz-1; | |
| 38 | + memmove(o0, s, sz); | |
| 39 | + o0[sz] = 0; | |
| 40 | + return sz; | |
| 29 | 41 | } |
Binary file not shown.