OSDN Git Service

* decl.c (maybe_pad_type): Use value_factor_p.
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-byorma.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                 G N A T . B Y T E _ O R D E R _ M A R K                  --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                     Copyright (C) 2006-2007, AdaCore                     --
10 --                                                                          --
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.                                              --
21 --                                                                          --
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.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 package body GNAT.Byte_Order_Mark is
35
36    --------------
37    -- Read_BOM --
38    --------------
39
40    procedure Read_BOM
41      (Str         : String;
42       Len         : out Natural;
43       BOM         : out BOM_Kind;
44       XML_Support : Boolean := False)
45    is
46    begin
47       --  UTF-16 (big-endian)
48
49       if Str'Length >= 2
50         and then Str (Str'First) = Character'Val (16#FE#)
51         and then Str (Str'First + 1) = Character'Val (16#FF#)
52       then
53          Len := 2;
54          BOM := UTF16_BE;
55
56       --  UTF-16 (little-endian)
57
58       elsif Str'Length >= 2
59         and then Str (Str'First) = Character'Val (16#FF#)
60         and then Str (Str'First + 1) = Character'Val (16#FE#)
61       then
62          Len := 2;
63          BOM := UTF16_LE;
64
65       --  UTF-32 (big-endian)
66
67       elsif Str'Length >= 4
68         and then Str (Str'First)     = Character'Val (16#00#)
69         and then Str (Str'First + 1) = Character'Val (16#00#)
70         and then Str (Str'First + 2) = Character'Val (16#FE#)
71         and then Str (Str'First + 3) = Character'Val (16#FF#)
72       then
73          Len := 4;
74          BOM := UTF32_BE;
75
76       --  UTF-32 (little-endian)
77
78       elsif Str'Length >= 4
79         and then Str (Str'First)     = Character'Val (16#FF#)
80         and then Str (Str'First + 1) = Character'Val (16#FE#)
81         and then Str (Str'First + 2) = Character'Val (16#00#)
82         and then Str (Str'First + 3) = Character'Val (16#00#)
83       then
84          Len := 4;
85          BOM := UTF32_LE;
86
87       --  UTF-8 (endian-independent)
88
89       elsif Str'Length >= 3
90         and then Str (Str'First)     = Character'Val (16#EF#)
91         and then Str (Str'First + 1) = Character'Val (16#BB#)
92         and then Str (Str'First + 2) = Character'Val (16#BF#)
93       then
94          Len := 3;
95          BOM := UTF8_All;
96
97       --  UCS-4 (big-endian) XML only
98
99       elsif XML_Support
100         and then Str'Length >= 4
101         and then Str (Str'First)     = Character'Val (16#00#)
102         and then Str (Str'First + 1) = Character'Val (16#00#)
103         and then Str (Str'First + 2) = Character'Val (16#00#)
104         and then Str (Str'First + 3) = Character'Val (16#3C#)
105       then
106          Len := 0;
107          BOM := UCS4_BE;
108
109       --  UCS-4 (little-endian) XML case
110
111       elsif XML_Support
112         and then Str'Length >= 4
113         and then Str (Str'First)     = Character'Val (16#3C#)
114         and then Str (Str'First + 1) = Character'Val (16#00#)
115         and then Str (Str'First + 2) = Character'Val (16#00#)
116         and then Str (Str'First + 3) = Character'Val (16#00#)
117       then
118          Len := 0;
119          BOM := UCS4_LE;
120
121       --  UCS-4 (unusual byte order 2143) XML case
122
123       elsif XML_Support
124         and then Str'Length >= 4
125         and then Str (Str'First)     = Character'Val (16#00#)
126         and then Str (Str'First + 1) = Character'Val (16#00#)
127         and then Str (Str'First + 2) = Character'Val (16#3C#)
128         and then Str (Str'First + 3) = Character'Val (16#00#)
129       then
130          Len := 0;
131          BOM := UCS4_2143;
132
133       --  UCS-4 (unusual byte order 3412) XML case
134
135       elsif XML_Support
136         and then Str'Length >= 4
137         and then Str (Str'First)     = Character'Val (16#00#)
138         and then Str (Str'First + 1) = Character'Val (16#3C#)
139         and then Str (Str'First + 2) = Character'Val (16#00#)
140         and then Str (Str'First + 3) = Character'Val (16#00#)
141       then
142          Len := 0;
143          BOM := UCS4_3412;
144
145       --  UTF-16 (big-endian) XML case
146
147       elsif XML_Support
148         and then Str'Length >= 4
149         and then Str (Str'First)     = Character'Val (16#00#)
150         and then Str (Str'First + 1) = Character'Val (16#3C#)
151         and then Str (Str'First + 2) = Character'Val (16#00#)
152         and then Str (Str'First + 3) = Character'Val (16#3F#)
153       then
154          Len := 0;
155          BOM := UTF16_BE;
156
157       --  UTF-32 (little-endian) XML case
158
159       elsif XML_Support
160         and then Str'Length >= 4
161         and then Str (Str'First)     = Character'Val (16#3C#)
162         and then Str (Str'First + 1) = Character'Val (16#00#)
163         and then Str (Str'First + 2) = Character'Val (16#3F#)
164         and then Str (Str'First + 3) = Character'Val (16#00#)
165       then
166          Len := 0;
167          BOM := UTF16_LE;
168
169       --  Unrecognized special encodings XML only
170
171       elsif XML_Support
172         and then Str'Length >= 4
173         and then Str (Str'First)     = Character'Val (16#3C#)
174         and then Str (Str'First + 1) = Character'Val (16#3F#)
175         and then Str (Str'First + 2) = Character'Val (16#78#)
176         and then Str (Str'First + 3) = Character'Val (16#6D#)
177       then
178          --  Utf8, ASCII, some part of ISO8859, Shift-JIS, EUC,...
179
180          Len := 0;
181          BOM := Unknown;
182
183       --  No BOM recognized
184
185       else
186          Len := 0;
187          BOM := Unknown;
188       end if;
189    end Read_BOM;
190
191 end GNAT.Byte_Order_Mark;