1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . B Y T E _ O R D E R _ M A R K --
9 -- Copyright (C) 2006-2017, AdaCore --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 pragma Compiler_Unit_Warning
;
34 package body GNAT
.Byte_Order_Mark
is
44 XML_Support
: Boolean := False)
47 -- Note: the order of these tests is important, because in some cases
48 -- one sequence is a prefix of a longer sequence, and we must test for
49 -- the longer sequence first
51 -- UTF-32 (big-endian)
54 and then Str
(Str
'First) = Character'Val (16#
00#
)
55 and then Str
(Str
'First + 1) = Character'Val (16#
00#
)
56 and then Str
(Str
'First + 2) = Character'Val (16#FE#
)
57 and then Str
(Str
'First + 3) = Character'Val (16#FF#
)
62 -- UTF-32 (little-endian)
65 and then Str
(Str
'First) = Character'Val (16#FF#
)
66 and then Str
(Str
'First + 1) = Character'Val (16#FE#
)
67 and then Str
(Str
'First + 2) = Character'Val (16#
00#
)
68 and then Str
(Str
'First + 3) = Character'Val (16#
00#
)
73 -- UTF-16 (big-endian)
76 and then Str
(Str
'First) = Character'Val (16#FE#
)
77 and then Str
(Str
'First + 1) = Character'Val (16#FF#
)
82 -- UTF-16 (little-endian)
85 and then Str
(Str
'First) = Character'Val (16#FF#
)
86 and then Str
(Str
'First + 1) = Character'Val (16#FE#
)
91 -- UTF-8 (endian-independent)
94 and then Str
(Str
'First) = Character'Val (16#EF#
)
95 and then Str
(Str
'First + 1) = Character'Val (16#BB#
)
96 and then Str
(Str
'First + 2) = Character'Val (16#BF#
)
101 -- UCS-4 (big-endian) XML only
104 and then Str
'Length >= 4
105 and then Str
(Str
'First) = Character'Val (16#
00#
)
106 and then Str
(Str
'First + 1) = Character'Val (16#
00#
)
107 and then Str
(Str
'First + 2) = Character'Val (16#
00#
)
108 and then Str
(Str
'First + 3) = Character'Val (16#
3C#
)
113 -- UCS-4 (little-endian) XML case
116 and then Str
'Length >= 4
117 and then Str
(Str
'First) = Character'Val (16#
3C#
)
118 and then Str
(Str
'First + 1) = Character'Val (16#
00#
)
119 and then Str
(Str
'First + 2) = Character'Val (16#
00#
)
120 and then Str
(Str
'First + 3) = Character'Val (16#
00#
)
125 -- UCS-4 (unusual byte order 2143) XML case
128 and then Str
'Length >= 4
129 and then Str
(Str
'First) = Character'Val (16#
00#
)
130 and then Str
(Str
'First + 1) = Character'Val (16#
00#
)
131 and then Str
(Str
'First + 2) = Character'Val (16#
3C#
)
132 and then Str
(Str
'First + 3) = Character'Val (16#
00#
)
137 -- UCS-4 (unusual byte order 3412) XML case
140 and then Str
'Length >= 4
141 and then Str
(Str
'First) = Character'Val (16#
00#
)
142 and then Str
(Str
'First + 1) = Character'Val (16#
3C#
)
143 and then Str
(Str
'First + 2) = Character'Val (16#
00#
)
144 and then Str
(Str
'First + 3) = Character'Val (16#
00#
)
149 -- UTF-16 (big-endian) XML case
152 and then Str
'Length >= 4
153 and then Str
(Str
'First) = Character'Val (16#
00#
)
154 and then Str
(Str
'First + 1) = Character'Val (16#
3C#
)
155 and then Str
(Str
'First + 2) = Character'Val (16#
00#
)
156 and then Str
(Str
'First + 3) = Character'Val (16#
3F#
)
161 -- UTF-32 (little-endian) XML case
164 and then Str
'Length >= 4
165 and then Str
(Str
'First) = Character'Val (16#
3C#
)
166 and then Str
(Str
'First + 1) = Character'Val (16#
00#
)
167 and then Str
(Str
'First + 2) = Character'Val (16#
3F#
)
168 and then Str
(Str
'First + 3) = Character'Val (16#
00#
)
173 -- Unrecognized special encodings XML only
176 and then Str
'Length >= 4
177 and then Str
(Str
'First) = Character'Val (16#
3C#
)
178 and then Str
(Str
'First + 1) = Character'Val (16#
3F#
)
179 and then Str
(Str
'First + 2) = Character'Val (16#
78#
)
180 and then Str
(Str
'First + 3) = Character'Val (16#
6D#
)
182 -- UTF-8, ASCII, some part of ISO8859, Shift-JIS, EUC,...
195 end GNAT
.Byte_Order_Mark
;