2005-12-29 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / ada / g-utf_32.ads
blobc2f3bf92b65494c567652ca0af8cbc825719e3ac
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- G N A T . U T F _ 3 2 --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2005 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 -- This package is available directly for use in application programs,
42 -- and also serves as the basis for Ada.Wide_Wide_Characters.Unicode and
43 -- Ada.Wide_Characters.Unicode, which can also be used directly.
45 package GNAT.UTF_32 is
47 type UTF_32 is range 0 .. 16#7FFF_FFFF#;
48 -- So far, the only defined character codes are in 0 .. 16#01_FFFF#
50 -- The following type defines the categories from the unicode definitions.
51 -- The one addition we make is Fe, which represents the characters FFFE
52 -- and FFFF in any of the planes.
54 type Category is (
55 Cc, -- Other, Control
56 Cf, -- Other, Format
57 Cn, -- Other, Not Assigned
58 Co, -- Other, Private Use
59 Cs, -- Other, Surrogate
60 Ll, -- Letter, Lowercase
61 Lm, -- Letter, Modifier
62 Lo, -- Letter, Other
63 Lt, -- Letter, Titlecase
64 Lu, -- Letter, Uppercase
65 Mc, -- Mark, Spacing Combining
66 Me, -- Mark, Enclosing
67 Mn, -- Mark, Nonspacing
68 Nd, -- Number, Decimal Digit
69 Nl, -- Number, Letter
70 No, -- Number, Other
71 Pc, -- Punctuation, Connector
72 Pd, -- Punctuation, Dash
73 Pe, -- Punctuation, Close
74 Pf, -- Punctuation, Final quote
75 Pi, -- Punctuation, Initial quote
76 Po, -- Punctuation, Other
77 Ps, -- Punctuation, Open
78 Sc, -- Symbol, Currency
79 Sk, -- Symbol, Modifier
80 Sm, -- Symbol, Math
81 So, -- Symbol, Other
82 Zl, -- Separator, Line
83 Zp, -- Separator, Paragraph
84 Zs, -- Separator, Space
85 Fe); -- relative position FFFE/FFFF in any plane
87 function Get_Category (U : UTF_32) return Category;
88 -- Given a UTF32 code, returns corresponding Category, or Cn if
89 -- the code does not have an assigned unicode category.
91 -- The following functions perform category tests corresponding to lexical
92 -- classes defined in the Ada standard. There are two interfaces for each
93 -- function. The second takes a Category (e.g. returned by Get_Category).
94 -- The first takes a UTF_32 code. The form taking the UTF_32 code is
95 -- typically more efficient than calling Get_Category, but if several
96 -- different tests are to be performed on the same code, it is more
97 -- efficient to use Get_Category to get the category, then test the
98 -- resulting category.
100 function Is_UTF_32_Letter (U : UTF_32) return Boolean;
101 function Is_UTF_32_Letter (C : Category) return Boolean;
102 pragma Inline (Is_UTF_32_Letter);
103 -- Returns true iff U is a letter that can be used to start an identifier,
104 -- or if C is one of the corresponding categories, which are the following:
105 -- Letter, Uppercase (Lu)
106 -- Letter, Lowercase (Ll)
107 -- Letter, Titlecase (Lt)
108 -- Letter, Modifier (Lm)
109 -- Letter, Other (Lo)
110 -- Number, Letter (Nl)
112 function Is_UTF_32_Digit (U : UTF_32) return Boolean;
113 function Is_UTF_32_Digit (C : Category) return Boolean;
114 pragma Inline (Is_UTF_32_Digit);
115 -- Returns true iff U is a digit that can be used to extend an identifer,
116 -- or if C is one of the corresponding categories, which are the following:
117 -- Number, Decimal_Digit (Nd)
119 function Is_UTF_32_Line_Terminator (U : UTF_32) return Boolean;
120 pragma Inline (Is_UTF_32_Line_Terminator);
121 -- Returns true iff U is an allowed line terminator for source programs,
122 -- if U is in the category Zp (Separator, Paragaph), or Zs (Separator,
123 -- Line), or if U is a conventional line terminator (CR, LF, VT, FF).
124 -- There is no category version for this function, since the set of
125 -- characters does not correspond to a set of Unicode categories.
127 function Is_UTF_32_Mark (U : UTF_32) return Boolean;
128 function Is_UTF_32_Mark (C : Category) return Boolean;
129 pragma Inline (Is_UTF_32_Mark);
130 -- Returns true iff U is a mark character which can be used to extend an
131 -- identifier, or if C is one of the corresponding categories, which are
132 -- the following:
133 -- Mark, Non-Spacing (Mn)
134 -- Mark, Spacing Combining (Mc)
136 function Is_UTF_32_Other (U : UTF_32) return Boolean;
137 function Is_UTF_32_Other (C : Category) return Boolean;
138 pragma Inline (Is_UTF_32_Other);
139 -- Returns true iff U is an other format character, which means that it
140 -- can be used to extend an identifier, but is ignored for the purposes of
141 -- matching of identiers, or if C is one of the corresponding categories,
142 -- which are the following:
143 -- Other, Format (Cf)
145 function Is_UTF_32_Punctuation (U : UTF_32) return Boolean;
146 function Is_UTF_32_Punctuation (C : Category) return Boolean;
147 pragma Inline (Is_UTF_32_Punctuation);
148 -- Returns true iff U is a punctuation character that can be used to
149 -- separate pices of an identifier, or if C is one of the corresponding
150 -- categories, which are the following:
151 -- Punctuation, Connector (Pc)
153 function Is_UTF_32_Space (U : UTF_32) return Boolean;
154 function Is_UTF_32_Space (C : Category) return Boolean;
155 pragma Inline (Is_UTF_32_Space);
156 -- Returns true iff U is considered a space to be ignored, or if C is one
157 -- of the corresponding categories, which are the following:
158 -- Separator, Space (Zs)
160 function Is_UTF_32_Non_Graphic (U : UTF_32) return Boolean;
161 function Is_UTF_32_Non_Graphic (C : Category) return Boolean;
162 pragma Inline (Is_UTF_32_Non_Graphic);
163 -- Returns true iff U is considered to be a non-graphic character, or if C
164 -- is one of the corresponding categories, which are the following:
165 -- Other, Control (Cc)
166 -- Other, Private Use (Co)
167 -- Other, Surrogate (Cs)
168 -- Separator, Line (Zl)
169 -- Separator, Paragraph (Zp)
170 -- FFFE or FFFF positions in any plane (Fe)
172 -- Note that the Ada category format effector is subsumed by the above
173 -- list of Unicode categories.
175 -- Note that Other, Unassiged (Cn) is quite deliberately not included
176 -- in the list of categories above. This means that should any of these
177 -- code positions be defined in future with graphic characters they will
178 -- be allowed without a need to change implementations or the standard.
180 -- Note that Other, Format (Cf) is also quite deliberately not included
181 -- in the list of categories above. This means that these characters can
182 -- be included in character and string literals.
184 -- The following function is used to fold to upper case, as required by
185 -- the Ada 2005 standard rules for identifier case folding. Two
186 -- identifiers are equivalent if they are identical after folding all
187 -- letters to upper case using this routine.
189 function UTF_32_To_Upper_Case (U : UTF_32) return UTF_32;
190 pragma Inline (UTF_32_To_Upper_Case);
191 -- If U represents a lower case letter, returns the corresponding upper
192 -- case letter, otherwise U is returned unchanged. The folding is locale
193 -- independent as defined by documents referenced in the note in section
194 -- 1 of ISO/IEC 10646:2003
196 end GNAT.UTF_32;