diff options
| author | Charles Forsyth <charles.forsyth@gmail.com> | 2015-06-14 12:32:13 +0100 |
|---|---|---|
| committer | Charles Forsyth <charles.forsyth@gmail.com> | 2015-06-14 12:32:13 +0100 |
| commit | 89dfe4bea0ef29d57db26cade21924eb38402e02 (patch) | |
| tree | 3c1d63e095ae2070c1e2bc595639d23fc5c4bf6f /emu/Nt/r16.c | |
| parent | 62d7827bc358c000db9ff48fe61bd28ac352a884 (diff) | |
handle 16-bit unicode from Windows in clipboard and fs names
Diffstat (limited to 'emu/Nt/r16.c')
| -rw-r--r-- | emu/Nt/r16.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/emu/Nt/r16.c b/emu/Nt/r16.c index cdbc13ac..92a36521 100644 --- a/emu/Nt/r16.c +++ b/emu/Nt/r16.c @@ -9,6 +9,28 @@ #include "error.h" #include "r16.h" +#define Bit(i) (7-(i)) +/* N 0's preceded by i 1's, T(Bit(2)) is 1100 0000 */ +#define T(i) (((1 << (Bit(i)+1))-1) ^ 0xFF) +/* 0000 0000 0000 0111 1111 1111 */ +#define RuneX(i) ((1 << (Bit(i) + ((i)-1)*Bitx))-1) + +enum +{ + Bitx = Bit(1), + + Tx = T(1), /* 1000 0000 */ + Rune1 = (1<<(Bit(0)+0*Bitx))-1, /* 0000 0000 0000 0000 0111 1111 */ + + Maskx = (1<<Bitx)-1, /* 0011 1111 */ + Testx = Maskx ^ 0xFF, /* 1100 0000 */ + + SurrogateMin = 0xD800, + SurrogateMax = 0xDFFF, + + Bad = Runeerror, +}; + Rune16* runes16dup(Rune16 *r) { @@ -59,6 +81,28 @@ runes16toutf(char *p, Rune16 *r, int nc) return op; } +int +rune16nlen(Rune16 *r, int nrune) +{ + int nb, i; + Rune c; + + nb = 0; + while(nrune--) { + c = *r++; + if(c <= Rune1){ + nb++; + } else { + for(i = 2; i < UTFmax + 1; i++) + if(c <= RuneX(i) || i == UTFmax){ + nb += i; + break; + } + } + } + return nb; +} + Rune16* utftorunes16(Rune16 *r, char *p, int nc) { |
