Update concepts branch to revision 131834
[official-gcc.git] / gcc / ada / s-utf_32.ads
blobc189be4aaf7e13e8dc3b8cdf34b72a2f5c47272f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . U T F _ 3 2 --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2005-2008, 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 is an internal package that provides basic character
35 -- classification capabilities needed by the compiler for handling full
36 -- 32-bit wide wide characters. We avoid the use of the actual type
37 -- Wide_Wide_Character, since we want to use these routines in the compiler
38 -- itself, and we want to be able to compile the compiler with old versions
39 -- of GNAT that did not implement Wide_Wide_Character.
41 -- System.UTF_32 should not be directly used from an application program, but
42 -- an equivalent package GNAT.UTF_32 can be used directly and provides exactly
43 -- the same services. The reason this package is in System is so that it can
44 -- with'ed by other packages in the Ada and System hierarchies.
46 pragma Warnings (Off);
47 pragma Compiler_Unit;
48 pragma Warnings (On);
50 package System.UTF_32 is
52 type UTF_32 is range 0 .. 16#7FFF_FFFF#;
53 -- So far, the only defined character codes are in 0 .. 16#01_FFFF#
55 -- The following type defines the categories from the unicode definitions.
56 -- The one addition we make is Fe, which represents the characters FFFE
57 -- and FFFF in any of the planes.
59 type Category is (
60 Cc, -- Other, Control
61 Cf, -- Other, Format
62 Cn, -- Other, Not Assigned
63 Co, -- Other, Private Use
64 Cs, -- Other, Surrogate
65 Ll, -- Letter, Lowercase
66 Lm, -- Letter, Modifier
67 Lo, -- Letter, Other
68 Lt, -- Letter, Titlecase
69 Lu, -- Letter, Uppercase
70 Mc, -- Mark, Spacing Combining
71 Me, -- Mark, Enclosing
72 Mn, -- Mark, Nonspacing
73 Nd, -- Number, Decimal Digit
74 Nl, -- Number, Letter
75 No, -- Number, Other
76 Pc, -- Punctuation, Connector
77 Pd, -- Punctuation, Dash
78 Pe, -- Punctuation, Close
79 Pf, -- Punctuation, Final quote
80 Pi, -- Punctuation, Initial quote
81 Po, -- Punctuation, Other
82 Ps, -- Punctuation, Open
83 Sc, -- Symbol, Currency
84 Sk, -- Symbol, Modifier
85 Sm, -- Symbol, Math
86 So, -- Symbol, Other
87 Zl, -- Separator, Line
88 Zp, -- Separator, Paragraph
89 Zs, -- Separator, Space
90 Fe); -- relative position FFFE/FFFF in any plane
92 function Get_Category (U : UTF_32) return Category;
93 -- Given a UTF32 code, returns corresponding Category, or Cn if
94 -- the code does not have an assigned unicode category.
96 -- The following functions perform category tests corresponding to lexical
97 -- classes defined in the Ada standard. There are two interfaces for each
98 -- function. The second takes a Category (e.g. returned by Get_Category).
99 -- The first takes a UTF_32 code. The form taking the UTF_32 code is
100 -- typically more efficient than calling Get_Category, but if several
101 -- different tests are to be performed on the same code, it is more
102 -- efficient to use Get_Category to get the category, then test the
103 -- resulting category.
105 function Is_UTF_32_Letter (U : UTF_32) return Boolean;
106 function Is_UTF_32_Letter (C : Category) return Boolean;
107 pragma Inline (Is_UTF_32_Letter);
108 -- Returns true iff U is a letter that can be used to start an identifier,
109 -- or if C is one of the corresponding categories, which are the following:
110 -- Letter, Uppercase (Lu)
111 -- Letter, Lowercase (Ll)
112 -- Letter, Titlecase (Lt)
113 -- Letter, Modifier (Lm)
114 -- Letter, Other (Lo)
115 -- Number, Letter (Nl)
117 function Is_UTF_32_Digit (U : UTF_32) return Boolean;
118 function Is_UTF_32_Digit (C : Category) return Boolean;
119 pragma Inline (Is_UTF_32_Digit);
120 -- Returns true iff U is a digit that can be used to extend an identifier,
121 -- or if C is one of the corresponding categories, which are the following:
122 -- Number, Decimal_Digit (Nd)
124 function Is_UTF_32_Line_Terminator (U : UTF_32) return Boolean;
125 pragma Inline (Is_UTF_32_Line_Terminator);
126 -- Returns true iff U is an allowed line terminator for source programs,
127 -- if U is in the category Zp (Separator, Paragraph), or Zs (Separator,
128 -- Line), or if U is a conventional line terminator (CR, LF, VT, FF).
129 -- There is no category version for this function, since the set of
130 -- characters does not correspond to a set of Unicode categories.
132 function Is_UTF_32_Mark (U : UTF_32) return Boolean;
133 function Is_UTF_32_Mark (C : Category) return Boolean;
134 pragma Inline (Is_UTF_32_Mark);
135 -- Returns true iff U is a mark character which can be used to extend an
136 -- identifier, or if C is one of the corresponding categories, which are
137 -- the following:
138 -- Mark, Non-Spacing (Mn)
139 -- Mark, Spacing Combining (Mc)
141 function Is_UTF_32_Other (U : UTF_32) return Boolean;
142 function Is_UTF_32_Other (C : Category) return Boolean;
143 pragma Inline (Is_UTF_32_Other);
144 -- Returns true iff U is an other format character, which means that it
145 -- can be used to extend an identifier, but is ignored for the purposes of
146 -- matching of identifiers, or if C is one of the corresponding categories,
147 -- which are the following:
148 -- Other, Format (Cf)
150 function Is_UTF_32_Punctuation (U : UTF_32) return Boolean;
151 function Is_UTF_32_Punctuation (C : Category) return Boolean;
152 pragma Inline (Is_UTF_32_Punctuation);
153 -- Returns true iff U is a punctuation character that can be used to
154 -- separate pieces of an identifier, or if C is one of the corresponding
155 -- categories, which are the following:
156 -- Punctuation, Connector (Pc)
158 function Is_UTF_32_Space (U : UTF_32) return Boolean;
159 function Is_UTF_32_Space (C : Category) return Boolean;
160 pragma Inline (Is_UTF_32_Space);
161 -- Returns true iff U is considered a space to be ignored, or if C is one
162 -- of the corresponding categories, which are the following:
163 -- Separator, Space (Zs)
165 function Is_UTF_32_Non_Graphic (U : UTF_32) return Boolean;
166 function Is_UTF_32_Non_Graphic (C : Category) return Boolean;
167 pragma Inline (Is_UTF_32_Non_Graphic);
168 -- Returns true iff U is considered to be a non-graphic character, or if C
169 -- is one of the corresponding categories, which are the following:
170 -- Other, Control (Cc)
171 -- Other, Private Use (Co)
172 -- Other, Surrogate (Cs)
173 -- Separator, Line (Zl)
174 -- Separator, Paragraph (Zp)
175 -- FFFE or FFFF positions in any plane (Fe)
177 -- Note that the Ada category format effector is subsumed by the above
178 -- list of Unicode categories.
180 -- Note that Other, Unassigned (Cn) is quite deliberately not included
181 -- in the list of categories above. This means that should any of these
182 -- code positions be defined in future with graphic characters they will
183 -- be allowed without a need to change implementations or the standard.
185 -- Note that Other, Format (Cf) is also quite deliberately not included
186 -- in the list of categories above. This means that these characters can
187 -- be included in character and string literals.
189 -- The following function is used to fold to upper case, as required by
190 -- the Ada 2005 standard rules for identifier case folding. Two
191 -- identifiers are equivalent if they are identical after folding all
192 -- letters to upper case using this routine.
194 function UTF_32_To_Upper_Case (U : UTF_32) return UTF_32;
195 pragma Inline (UTF_32_To_Upper_Case);
196 -- If U represents a lower case letter, returns the corresponding upper
197 -- case letter, otherwise U is returned unchanged. The folding is locale
198 -- independent as defined by documents referenced in the note in section
199 -- 1 of ISO/IEC 10646:2003
201 end System.UTF_32;