summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/omega/otp/char2uni/inutf8.otp
blob: 2bbab400c42b2276408e45583c767ace1f4bca7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
% File inutf8.otp
% Conversion to UTF-16 from UTF-8 
% Copyright (c) 1999 John Plaice and Yannis Haralambous
% Copyright (C) 2005, 2006 Roozbeh Pournader
% This file is part of the Omega project.
%
% The information was originally provided by Martin Dürst.
% Updated to incorporate exact definition of UTF-8 from Unicode 4.0.
%

input:  1;
output: 2;

expressions:

% One-byte sequences get mapped to proper ASCII
@"00-@"7F
  => \1;

% Two-byte sequences:
% U+0080..U+07FF
(@"C2-@"DF)(@"80-@"BF)
  => #(((\1-@"C0)*@"40) + (\2-@"80));

% Three-byte sequences:
% U+0800..U+0FFF
@"E0(@"A0-@"BF)(@"80-@"BF)
  => #(((\2-@"80)*@"40) + (\3-@"80));
% U+1000..U+CFFF, U+E000..U+FFFF
(@"E1-@"EC|@"EE-@"EF)(@"80-@"BF)(@"80-@"BF)
  => #(((\1-@"E0)*@"1000) + ((\2-@"80)*@"40) + (\3-@"80));
% U+D000..U+D7FF
@"ED(@"80-@"9F)(@"80-@"BF)
  => #(@"D000 + ((\2-@"80)*@"40) + (\3-@"80));

% Four-byte sequences:
% The arithmatics is a little complex here, since the characters
% are converted to UTF-16 directly.
% U+10000..U+3FFFF
@"F0(@"90-@"BF)(@"80-@"BF)(@"80-@"BF)
  => #(@"D7C0 + ((\2-@"80)*4) + ((\3-@"80) div: @"10))
     #(@"DC00 + ((\3 mod: 10)*@"40) + (\4 - @"80));
% U+40000..U+FFFFF
(@"F1-@"F3)(@"80-@"BF)(@"80-@"BF)(@"80-@"BF)
  => #(@"D7C0 + ((\1-@"F0)*@"100) + ((\2-@"80)*4) + ((\3-@"80) div: @"10))
     #(@"DC00 + ((\3 mod: 10)*@"40) + (\4 - @"80));
% U+100000..U+10FFFF
@"F4(@"80-@"8F)(@"80-@"BF)(@"80-@"BF)
  => #(@"DBC0 + ((\2-@"80)*4) + ((\3-@"80) div: @"10))
     #(@"DC00 + ((\3 mod: 10)*@"40) + (\4 - @"80));

% Anything else gets mapped to U+FFFD. This should probably
% get replaced by an error message, instead.
. => @"FFFD;