Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / ada / g-byorma.ads
blob6016f755bcc3b53d69825925caf8f9bc1cd5b8b4
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 -- S p e c --
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 ------------------------------------------------------------------------------
34 -- This package provides a procedure for reading and interpreting the BOM
35 -- (byte order mark) used to publish the encoding method for a string (for
36 -- example, a UTF-8 encoded file in windows will start with the appropriate
37 -- BOM sequence to signal UTF-8 encoding.
39 -- There are two cases
41 -- Case 1. UTF encodings for Unicode files
43 -- Here the convention is to have the first character of the file be a
44 -- non-breaking zero width space character (16#0000_FEFF#). For the UTF
45 -- encodings, the representation of this character can be used to uniquely
46 -- determine the encoding. Furthermore, the possibility of any confusion
47 -- with unencoded files is minimal, since for example the UTF-8 encoding
48 -- of this character looks like the sequence:
50 -- LC_I_Diaeresis
51 -- Right_Angle_Quotation
52 -- Fraction_One_Half
54 -- which is so unlikely to occur legitimately in normal use that it can
55 -- safely be ignored in most cases (for example, no legitimate Ada source
56 -- file could start with this sequence of characters).
58 -- Case 2. Specialized XML encodings
60 -- The XML standard defines a number of other possible encodings and also
61 -- defines standardized sequences for marking these encodings. This package
62 -- can also optionally handle these XML defined BOM sequences. These XML
63 -- cases depend on the first character of the XML file being < so that the
64 -- encoding of this character can be recognized.
66 pragma Warnings (Off);
67 pragma Compiler_Unit;
68 pragma Warnings (On);
70 package GNAT.Byte_Order_Mark is
72 type BOM_Kind is
73 (UTF8_All, -- UTF8-encoding
74 UTF16_LE, -- UTF16 little-endian encoding
75 UTF16_BE, -- UTF16 big-endian encoding
76 UTF32_LE, -- UTF32 little-endian encoding
77 UTF32_BE, -- UTF32 big-endian encoding
79 -- The following cases are for XML only
81 UCS4_BE, -- UCS-4, big endian machine (1234 order)
82 UCS4_LE, -- UCS-4, little endian machine (4321 order)
83 UCS4_2143, -- UCS-4, unusual byte order (2143 order)
84 UCS4_3412, -- UCS-4, unusual byte order (3412 order)
86 -- Value returned if no BOM recognized
88 Unknown); -- Unknown, assumed to be ASCII compatible
90 procedure Read_BOM
91 (Str : String;
92 Len : out Natural;
93 BOM : out BOM_Kind;
94 XML_Support : Boolean := False);
95 -- This is the routine to read the BOM from the start of the given string
96 -- Str. On return BOM is set to the appropriate BOM_Kind and Len is set to
97 -- its length. The caller will typically skip the first Len characters in
98 -- the string to ignore the BOM sequence. The special XML possibilities are
99 -- recognized only if flag XML_Support is set to True. Note that for the
100 -- XML cases, Len is always set to zero on return (not to the length of the
101 -- relevant sequence) since in the XML cases, the sequence recognized is
102 -- for the first real character in the file (<) which is not to be skipped.
104 end GNAT.Byte_Order_Mark;