Skip to content

Commit

Permalink
Implement (and test) UK encoding page
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Jul 26, 2010
1 parent c5855ff commit 0c741e0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,46 @@ static VTermEncoding encoding_usascii = {
.decode = &decode_usascii,
};

struct StaticTableEncoding {
const VTermEncoding enc;
const uint32_t chars[128];
};

static int decode_table(VTermEncoding *enc, uint32_t cp[], int *cpi, int cplen,
const char bytes[], size_t *pos, size_t bytelen)
{
struct StaticTableEncoding *table = (struct StaticTableEncoding *)enc;

for(; *pos < bytelen; (*pos)++) {
unsigned char c = (bytes[*pos]) & 0x7f;

if(c < 0x20)
return 0;

if(table->chars[c])
cp[(*cpi)++] = table->chars[c];
else
cp[(*cpi)++] = c;
}

return 1;
}

static const struct StaticTableEncoding encoding_uk = {
{ .decode = &decode_table },
{
['$'] = 0x00a3,
}
};

static struct {
VTermEncodingType type;
char designation;
VTermEncoding *enc;
}
encodings[] = {
{ ENC_UTF8, 'u', &encoding_utf8 },
{ ENC_SINGLE_94, 'A', (VTermEncoding*)&encoding_uk },
{ ENC_SINGLE_94, 'B', &encoding_usascii },
{ 0, 0 },
};
Expand Down
14 changes: 14 additions & 0 deletions t/14state_encoding.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INIT
UTF8 1
WANTSTATE g

!Default
RESET
PUSH '$'
putglyph 0x23 1 0,0

!Designate G0=UK
RESET
PUSH "\e(A"
PUSH '$'
putglyph 0x00a3 1 0,0

0 comments on commit 0c741e0

Please sign in to comment.