Debian Codegraph @

texmf-dist/omega/otp/char2uni/inutf8.otp

raw
1 % File inutf8.otp
2 % Conversion to UTF-16 from UTF-8
3 % Copyright (c) 1999 John Plaice and Yannis Haralambous
4 % Copyright (C) 2005, 2006 Roozbeh Pournader
5 % This file is part of the Omega project.
6 %
7 % The information was originally provided by Martin Dürst.
8 % Updated to incorporate exact definition of UTF-8 from Unicode 4.0.
9 %
10
11 input: 1;
12 output: 2;
13
14 expressions:
15
16 % One-byte sequences get mapped to proper ASCII
17 @"00-@"7F
18 => \1;
19
20 % Two-byte sequences:
21 % U+0080..U+07FF
22 (@"C2-@"DF)(@"80-@"BF)
23 => #(((\1-@"C0)*@"40) + (\2-@"80));
24
25 % Three-byte sequences:
26 % U+0800..U+0FFF
27 @"E0(@"A0-@"BF)(@"80-@"BF)
28 => #(((\2-@"80)*@"40) + (\3-@"80));
29 % U+1000..U+CFFF, U+E000..U+FFFF
30 (@"E1-@"EC|@"EE-@"EF)(@"80-@"BF)(@"80-@"BF)
31 => #(((\1-@"E0)*@"1000) + ((\2-@"80)*@"40) + (\3-@"80));
32 % U+D000..U+D7FF
33 @"ED(@"80-@"9F)(@"80-@"BF)
34 => #(@"D000 + ((\2-@"80)*@"40) + (\3-@"80));
35
36 % Four-byte sequences:
37 % The arithmatics is a little complex here, since the characters
38 % are converted to UTF-16 directly.
39 % U+10000..U+3FFFF
40 @"F0(@"90-@"BF)(@"80-@"BF)(@"80-@"BF)
41 => #(@"D7C0 + ((\2-@"80)*4) + ((\3-@"80) div: @"10))
42 #(@"DC00 + ((\3 mod: 10)*@"40) + (\4 - @"80));
43 % U+40000..U+FFFFF
44 (@"F1-@"F3)(@"80-@"BF)(@"80-@"BF)(@"80-@"BF)
45 => #(@"D7C0 + ((\1-@"F0)*@"100) + ((\2-@"80)*4) + ((\3-@"80) div: @"10))
46 #(@"DC00 + ((\3 mod: 10)*@"40) + (\4 - @"80));
47 % U+100000..U+10FFFF
48 @"F4(@"80-@"8F)(@"80-@"BF)(@"80-@"BF)
49 => #(@"DBC0 + ((\2-@"80)*4) + ((\3-@"80) div: @"10))
50 #(@"DC00 + ((\3 mod: 10)*@"40) + (\4 - @"80));
51
52 % Anything else gets mapped to U+FFFD. This should probably
53 % get replaced by an error message, instead.
54 . => @"FFFD;