Merged with mainline at revision 128810.
[official-gcc.git] / gcc / ada / s-wchcon.ads
blob8607c19e9511fe2ad72359b05fffbce21338b5d2
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . W C H _ C O N --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
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 defines the codes used to identify the encoding method for
35 -- wide characters in string and character constants. This is needed both
36 -- at compile time and at runtime (for the wide character runtime routines)
38 -- This unit may be used directly from an application program by providing
39 -- an appropriate WITH, and the interface can be expected to remain stable.
41 pragma Warnings (Off);
42 pragma Compiler_Unit;
43 pragma Warnings (On);
45 package System.WCh_Con is
46 pragma Pure;
48 -------------------------------------
49 -- Wide_Character Encoding Methods --
50 -------------------------------------
52 -- A wide character encoding method is a method for uniquely representing
53 -- a Wide_Character or Wide_Wide_Character value using a one or more
54 -- Character values. Three types of encoding method are supported by GNAT:
56 -- An escape encoding method uses ESC as the first character of the
57 -- sequence, and subsequent characters determine the wide character
58 -- value that is represented. Any character other than ESC stands
59 -- for itself as a single byte (i.e. any character in Latin-1, other
60 -- than ESC itself, is represented as a single character: itself).
62 -- An upper half encoding method uses a character in the upper half
63 -- range (i.e. in the range 16#80# .. 16#FF#) as the first byte of
64 -- a wide character encoding sequence. Subsequent characters are
65 -- used to determine the wide character value that is represented.
66 -- Any character in the lower half (16#00# .. 16#7F#) represents
67 -- itself as a single character.
69 -- The brackets notation, where a wide character is represented by the
70 -- sequence ["xx"] or ["xxxx"] or ["xxxxxx"] where xx are hexadecimal
71 -- characters. Note that currently this is the only encoding that
72 -- supports the full UTF-32 range.
74 -- Note that GNAT does not currently support escape-in, escape-out
75 -- encoding methods, where an escape sequence is used to set a mode
76 -- used to recognize subsequent characters. All encoding methods use
77 -- individual character-by-character encodings, so that a sequence of
78 -- wide characters is represented by a sequence of encodings.
80 -- To add new encoding methods, the following steps are required:
82 -- 1. Define a code for a new value of type WC_Encoding_Method
83 -- 2. Adjust the definition of WC_Encoding_Method accordingly
84 -- 3. Provide appropriate conversion routines in System.Wch_Cnv
85 -- 4. Adjust definition of WC_Longest_Sequence if necessary
86 -- 5. Add an entry in WC_Encoding_Letters for the new method
87 -- 6. Add proper code to s-wchstw.adb, s-wchwts.adb, s-widwch.adb
88 -- 7. Update documentation (remember section on form strings)
90 -- Note that the WC_Encoding_Method values must be kept ordered so that
91 -- the definitions of the subtypes WC_Upper_Half_Encoding_Method and
92 -- WC_ESC_Encoding_Method are still correct.
94 ---------------------------------
95 -- Encoding Method Definitions --
96 ---------------------------------
98 type WC_Encoding_Method is range 1 .. 6;
99 -- Type covering the range of values used to represent wide character
100 -- encoding methods. An enumeration type might be a little neater, but
101 -- more trouble than it's worth, given the need to pass these values
102 -- from the compiler to the backend, and to record them in the ALI file.
104 WCEM_Hex : constant WC_Encoding_Method := 1;
105 -- The wide character with code 16#abcd# is represented by the escape
106 -- sequence ESC a b c d (five characters, where abcd are ASCII hex
107 -- characters, using upper case for letters). This method is easy
108 -- to deal with in external environments that do not support wide
109 -- characters, and covers the whole BMP. This is the default encoding
110 -- method.
112 WCEM_Upper : constant WC_Encoding_Method := 2;
113 -- The wide character with encoding 16#abcd#, where the upper bit is on
114 -- (i.e. a is in the range 8-F) is represented as two bytes 16#ab# and
115 -- 16#cd#. The second byte may never be a format control character, but
116 -- is not required to be in the upper half. This method can be also used
117 -- for shift-JIS or EUC where the internal coding matches the external
118 -- coding.
120 WCEM_Shift_JIS : constant WC_Encoding_Method := 3;
121 -- A wide character is represented by a two character sequence 16#ab#
122 -- and 16#cd#, with the restrictions described for upper half encoding
123 -- as described above. The internal character code is the corresponding
124 -- JIS character according to the standard algorithm for Shift-JIS
125 -- conversion. See the body of package System.JIS_Conversions for
126 -- further details.
128 WCEM_EUC : constant WC_Encoding_Method := 4;
129 -- A wide character is represented by a two character sequence 16#ab# and
130 -- 16#cd#, with both characters being in the upper half set. The internal
131 -- character code is the corresponding JIS character according to the EUC
132 -- encoding algorithm. See the body of package System.JIS_Conversions for
133 -- further details.
135 WCEM_UTF8 : constant WC_Encoding_Method := 5;
136 -- An ISO 10646-1 BMP/Unicode wide character is represented in
137 -- UCS Transformation Format 8 (UTF-8) as defined in Annex R of ISO
138 -- 10646-1/Am.2. Depending on the character value, a Unicode character
139 -- is represented as the one to six byte sequence.
141 -- 16#0000_0000#-16#0000_007f#: 2#0xxxxxxx#
142 -- 16#0000_0080#-16#0000_07ff#: 2#110xxxxx# 2#10xxxxxx#
143 -- 16#0000_0800#-16#0000_ffff#: 2#1110xxxx# 2#10xxxxxx# 2#10xxxxxx#
144 -- 16#0001_0000#-16#001F_FFFF#: 2#11110xxx# 2#10xxxxxx# 2#10xxxxxx#
145 -- 2#10xxxxxx#
146 -- 16#0020_0000#-16#03FF_FFFF#: 2#111110xx# 2#10xxxxxx# 2#10xxxxxx#
147 -- 2#10xxxxxx# 2#10xxxxxx#
148 -- 16#0400_0000#-16#7FFF_FFFF#: 2#1111110x# 2#10xxxxxx# 2#10xxxxxx#
149 -- 2#10xxxxxx# 2#10xxxxxx# 2#10xxxxxx#
151 -- where the xxx bits correspond to the left-padded bits of the
152 -- 16-bit character value. Note that all lower half ASCII characters
153 -- are represented as ASCII bytes and all upper half characters and
154 -- other wide characters are represented as sequences of upper-half.
156 WCEM_Brackets : constant WC_Encoding_Method := 6;
157 -- A wide character is represented using one of the following sequences:
159 -- ["xx"]
160 -- ["xxxx"]
161 -- ["xxxxxx"]
162 -- ["xxxxxxxx"]
164 -- where xx are hexadecimal digits representing the character code.
166 WC_Encoding_Letters : constant array (WC_Encoding_Method) of Character :=
167 (WCEM_Hex => 'h',
168 WCEM_Upper => 'u',
169 WCEM_Shift_JIS => 's',
170 WCEM_EUC => 'e',
171 WCEM_UTF8 => '8',
172 WCEM_Brackets => 'b');
173 -- Letters used for selection of wide character encoding method in the
174 -- compiler options (-gnatW? switch) and for Wide_Text_IO (WCEM parameter
175 -- in the form string).
177 subtype WC_ESC_Encoding_Method is
178 WC_Encoding_Method range WCEM_Hex .. WCEM_Hex;
179 -- Encoding methods using an ESC character at the start of the sequence
181 subtype WC_Upper_Half_Encoding_Method is
182 WC_Encoding_Method range WCEM_Upper .. WCEM_UTF8;
183 -- Encoding methods using an upper half character (16#80#..16#FF) at
184 -- the start of the sequence.
186 WC_Longest_Sequence : constant := 10;
187 -- The longest number of characters that can be used for a wide character
188 -- or wide wide character sequence for any of the active encoding methods.
190 function Get_WC_Encoding_Method (C : Character) return WC_Encoding_Method;
191 -- Given a character C, returns corresponding encoding method (see array
192 -- WC_Encoding_Letters above). Raises Constraint_Error if not in list.
194 function Get_WC_Encoding_Method (S : String) return WC_Encoding_Method;
195 -- Given a lower case string that is one of hex, upper, shift_jis, euc,
196 -- utf8, brackets, return the corresponding encoding method. Raises
197 -- Constraint_Error if not in list.
199 end System.WCh_Con;