| | 1 | #include <tads.h> |
| | 2 | #include <charset.h> |
| | 3 | |
| | 4 | main(args) |
| | 5 | { |
| | 6 | local cs; |
| | 7 | local mappable; |
| | 8 | local s; |
| | 9 | local b; |
| | 10 | |
| | 11 | /* test some simple US-ASCII mappings */ |
| | 12 | cs = new CharacterSet('us-ascii'); |
| | 13 | "us-ascii:\n"; |
| | 14 | "\texists? <<cs.isMappingKnown() ? 'yes' : 'no'>>\n"; |
| | 15 | "\tcan map 0x77? <<cs.isMappable(0x77) ? 'yes' : 'no'>>\n"; |
| | 16 | "\tcan map 'abc'? <<cs.isMappable('abc') ? 'yes' : 'no'>>\n"; |
| | 17 | "\tcan map 0x10CD? <<cs.isMappable(0x10CD) ? 'yes' : 'no'>>\n"; |
| | 18 | "\tcan map 'abc\u1011\u1012def'? << |
| | 19 | cs.isMappable('abc\u1011\u1012def') ? 'yes' : 'no'>>\n"; |
| | 20 | "\b"; |
| | 21 | |
| | 22 | /* test local character set operations */ |
| | 23 | "Local display character set = |
| | 24 | <<getLocalCharSet(CharsetDisplay)>>\n"; |
| | 25 | "Local file system character set = |
| | 26 | <<getLocalCharSet(CharsetFileName)>>\n"; |
| | 27 | "\b"; |
| | 28 | |
| | 29 | /* test for the local presence of the Cyrillic alphabet */ |
| | 30 | cs = new CharacterSet(getLocalCharSet(CharsetDisplay)); |
| | 31 | "Can the local display character set show the Cyrillic alphabet? "; |
| | 32 | for (mappable = 'yes', local ch = 0x0410 ; ch <= 0x044F ; ++ch) |
| | 33 | { |
| | 34 | if (!cs.isMappable(ch)) |
| | 35 | { |
| | 36 | mappable = 'no'; |
| | 37 | break; |
| | 38 | } |
| | 39 | } |
| | 40 | "<<mappable>>\b"; |
| | 41 | |
| | 42 | /* iso-8859-1 - unicode to local */ |
| | 43 | cs = new CharacterSet('iso-8859-1'); |
| | 44 | "Some ISO 8859-1 mappings: unicode to local:\n"; |
| | 45 | s = 'test \x91\x92\u1024 done'; |
| | 46 | b = s.mapToByteArray(cs); |
| | 47 | "'<<s>>' -> "; |
| | 48 | for (local i = 1 ; i <= b.length() ; ++i) |
| | 49 | "[<<i>>]=<<b[i]>>\t"; |
| | 50 | "\b"; |
| | 51 | |
| | 52 | /* iso8859-1 - local to unicode */ |
| | 53 | "ISO 8859-1: local to unicode\n"; |
| | 54 | for (local i = 1 ; i <= b.length() ; ++i) |
| | 55 | b[i] = 64 + i; |
| | 56 | "'<<b.mapToString(cs)>>'\b"; |
| | 57 | } |
| | 58 | |