1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- G N A T . U T F _ 3 2 --
9 -- Copyright (C) 2005 Free Software Foundation, Inc. --
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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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 not available directly for use in application programs,
42 -- but it serves as the basis for GNAT.Wide_Case_Utilities and
43 -- GNAT.Wide_Wide_Case_Utilities, which can 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#
53 Cn, -- Other, Not Assigned
54 Co, -- Other, Private Use
55 Cs, -- Other, Surrogate
56 Ll, -- Letter, Lowercase
57 Lm, -- Letter, Modifier
59 Lt, -- Letter, Titlecase
60 Lu, -- Letter, Uppercase
61 Mc, -- Mark, Spacing Combining
62 Me, -- Mark, Enclosing
63 Mn, -- Mark, Nonspacing
64 Nd, -- Number, Decimal Digit
67 Pc, -- Punctuation, Connector
68 Pd, -- Punctuation, Dash
69 Pe, -- Punctuation, Close
70 Pf, -- Punctuation, Final quote
71 Pi, -- Punctuation, Initial quote
72 Po, -- Punctuation, Other
73 Ps, -- Punctuation, Open
74 Sc, -- Symbol, Currency
75 Sk, -- Symbol, Modifier
78 Zl, -- Separator, Line
79 Zp, -- Separator, Paragraph
80 Zs); -- Separator, Space
82 function Get_Category (U : UTF_32) return Category;
83 -- Given a UTF32 code, returns corresponding Category, or Cn if
84 -- the code does not have an assigned unicode category.
86 -- The following functions perform category tests corresponding to lexical
87 -- classes defined in the Ada standard. There are two interfaces for each
88 -- function. The first takes a Category (e.g. returned by Get_Category).
89 -- The second takes a UTF_32 code. The form taking the UTF_32 code is
90 -- typically more efficient than calling Get_Category, but if several
91 -- different tests are to be performed on the same code, it is more
92 -- efficient to use Get_Category to get the category, then test the
93 -- resulting category.
95 function Is_UTF_32_Letter (U : UTF_32) return Boolean;
96 function Is_UTF_32_Letter (C : Category) return Boolean;
97 pragma Inline (Is_UTF_32_Letter);
98 -- Returns true iff U is a letter that can be used to start an identifier,
99 -- or if C is one of the corresponding categories, which are the following:
100 -- Letter, Uppercase (Lu)
101 -- Letter, Lowercase (Ll)
102 -- Letter, Titlecase (Lt)
103 -- Letter, Modifier (Lm)
104 -- Letter, Other (Lo)
105 -- Number, Letter (Nl)
107 function Is_UTF_32_Digit (U : UTF_32) return Boolean;
108 function Is_UTF_32_Digit (C : Category) return Boolean;
109 pragma Inline (Is_UTF_32_Digit);
110 -- Returns true iff U is a digit that can be used to extend an identifer,
111 -- or if C is one of the corresponding categories, which are the following:
112 -- Number, Decimal_Digit (Nd)
114 function Is_UTF_32_Line_Terminator (U : UTF_32) return Boolean;
115 pragma Inline (Is_UTF_32_Line_Terminator);
116 -- Returns true iff U is an allowed line terminator for source programs,
117 -- if U is in the category Zp (Separator, Paragaph), or Zs (Separator,
118 -- Line), or if U is a conventional line terminator (CR, LF, VT, FF).
119 -- There is no category version for this function, since the set of
120 -- characters does not correspond to a set of Unicode categories.
122 function Is_UTF_32_Mark (U : UTF_32) return Boolean;
123 function Is_UTF_32_Mark (C : Category) return Boolean;
124 pragma Inline (Is_UTF_32_Mark);
125 -- Returns true iff U is a mark character which can be used to extend an
126 -- identifier, or if C is one of the corresponding categories, which are
128 -- Mark, Non-Spacing (Mn)
129 -- Mark, Spacing Combining (Mc)
131 function Is_UTF_32_Other (U : UTF_32) return Boolean;
132 function Is_UTF_32_Other (C : Category) return Boolean;
133 pragma Inline (Is_UTF_32_Other);
134 -- Returns true iff U is an other format character, which means that it
135 -- can be used to extend an identifier, but is ignored for the purposes of
136 -- matching of identiers, or if C is one of the corresponding categories,
137 -- which are the following:
138 -- Other, Format (Cf)
140 function Is_UTF_32_Punctuation (U : UTF_32) return Boolean;
141 function Is_UTF_32_Punctuation (C : Category) return Boolean;
142 pragma Inline (Is_UTF_32_Punctuation);
143 -- Returns true iff U is a punctuation character that can be used to
144 -- separate pices of an identifier, or if C is one of the corresponding
145 -- categories, which are the following:
146 -- Punctuation, Connector (Pc)
148 function Is_UTF_32_Space (U : UTF_32) return Boolean;
149 function Is_UTF_32_Space (C : Category) return Boolean;
150 pragma Inline (Is_UTF_32_Space);
151 -- Returns true iff U is considered a space to be ignored, or if C is one
152 -- of the corresponding categories, which are the following:
153 -- Separator, Space (Zs)
155 function Is_UTF_32_Non_Graphic (U : UTF_32) return Boolean;
156 function Is_UTF_32_Non_Graphic (C : Category) return Boolean;
157 pragma Inline (Is_UTF_32_Non_Graphic);
158 -- Returns true iff U is considered to be a non-graphic character, or if C
159 -- is one of the corresponding categories, which are the following:
160 -- Other, Control (Cc)
161 -- Other, Private Use (Co)
162 -- Other, Surrogate (Cs)
163 -- Other, Format (Cf)
164 -- Separator, Line (Zl)
165 -- Separator, Paragraph (Zp)
167 -- Note that the Ada category format effector is subsumed by the above
168 -- list of Unicode categories.
170 -- Note that Other, Unassiged (Cn) is quite deliberately not included
171 -- in the list of categories above. This means that should any of these
172 -- code positions be defined in future with graphic characters they will
173 -- be allowed without a need to change implementations or the standard.
175 -- The following function is used to fold to upper case, as required by
176 -- the Ada 2005 standard rules for identifier case folding. Two
177 -- identifiers are equivalent if they are identical after folding all
178 -- letters to upper case using this routine.
180 function UTF_32_To_Upper_Case (U : UTF_32) return UTF_32;
181 pragma Inline (UTF_32_To_Upper_Case);
182 -- If U represents a lower case letter, returns the corresponding upper
183 -- case letter, otherwise U is returned unchanged. The folding is locale
184 -- independent as defined by documents referenced in the note in section
185 -- 1 of ISO/IEC 10646:2003