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-2007, 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
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#)
90 -- UTF-8 (endian-independent)
93 and then Str (Str'First) = Character'Val (16#EF#)
94 and then Str (Str'First + 1) = Character'Val (16#BB#)
95 and then Str (Str'First + 2) = Character'Val (16#BF#)
100 -- UCS-4 (big-endian) XML only
103 and then Str'Length >= 4
104 and then Str (Str'First) = Character'Val (16#00#)
105 and then Str (Str'First + 1) = Character'Val (16#00#)
106 and then Str (Str'First + 2) = Character'Val (16#00#)
107 and then Str (Str'First + 3) = Character'Val (16#3C#)
112 -- UCS-4 (little-endian) XML case
115 and then Str'Length >= 4
116 and then Str (Str'First) = Character'Val (16#3C#)
117 and then Str (Str'First + 1) = Character'Val (16#00#)
118 and then Str (Str'First + 2) = Character'Val (16#00#)
119 and then Str (Str'First + 3) = Character'Val (16#00#)
124 -- UCS-4 (unusual byte order 2143) XML case
127 and then Str'Length >= 4
128 and then Str (Str'First) = Character'Val (16#00#)
129 and then Str (Str'First + 1) = Character'Val (16#00#)
130 and then Str (Str'First + 2) = Character'Val (16#3C#)
131 and then Str (Str'First + 3) = Character'Val (16#00#)
136 -- UCS-4 (unusual byte order 3412) XML case
139 and then Str'Length >= 4
140 and then Str (Str'First) = Character'Val (16#00#)
141 and then Str (Str'First + 1) = Character'Val (16#3C#)
142 and then Str (Str'First + 2) = Character'Val (16#00#)
143 and then Str (Str'First + 3) = Character'Val (16#00#)
148 -- UTF-16 (big-endian) XML case
151 and then Str'Length >= 4
152 and then Str (Str'First) = Character'Val (16#00#)
153 and then Str (Str'First + 1) = Character'Val (16#3C#)
154 and then Str (Str'First + 2) = Character'Val (16#00#)
155 and then Str (Str'First + 3) = Character'Val (16#3F#)
160 -- UTF-32 (little-endian) XML case
163 and then Str'Length >= 4
164 and then Str (Str'First) = Character'Val (16#3C#)
165 and then Str (Str'First + 1) = Character'Val (16#00#)
166 and then Str (Str'First + 2) = Character'Val (16#3F#)
167 and then Str (Str'First + 3) = Character'Val (16#00#)
172 -- Unrecognized special encodings XML only
175 and then Str'Length >= 4
176 and then Str (Str'First) = Character'Val (16#3C#)
177 and then Str (Str'First + 1) = Character'Val (16#3F#)
178 and then Str (Str'First + 2) = Character'Val (16#78#)
179 and then Str (Str'First + 3) = Character'Val (16#6D#)
181 -- Utf8, ASCII, some part of ISO8859, Shift-JIS, EUC,...
194 end GNAT.Byte_Order_Mark;