| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- A D A . W I D E _ W I D E _ C H A R A C T E R T S . U N I C O D E -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2005-2025, 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 3, 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. -- |
| 17 |
-- -- |
| 18 |
-- As a special exception under Section 7 of GPL version 3, you are granted -- |
| 19 |
-- additional permissions described in the GCC Runtime Library Exception, -- |
| 20 |
-- version 3.1, as published by the Free Software Foundation. -- |
| 21 |
-- -- |
| 22 |
-- You should have received a copy of the GNU General Public License and -- |
| 23 |
-- a copy of the GCC Runtime Library Exception along with this program; -- |
| 24 |
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- |
| 25 |
-- <http://www.gnu.org/licenses/>. -- |
| 26 |
-- -- |
| 27 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 28 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 29 |
-- -- |
| 30 |
------------------------------------------------------------------------------ |
| 31 |
|
| 32 |
-- Unicode categorization routines for Wide_Wide_Character |
| 33 |
|
| 34 |
with System.UTF_32; |
| 35 |
|
| 36 |
package Ada.Wide_Wide_Characters.Unicode is |
| 37 |
pragma Pure; |
| 38 |
|
| 39 |
-- The following type defines the categories from the unicode definitions. |
| 40 |
-- The one addition we make is Fe, which represents the characters FFFE |
| 41 |
-- and FFFF in any of the planes. |
| 42 |
|
| 43 |
type Category is new System.UTF_32.Category; |
| 44 |
-- Cc Other, Control |
| 45 |
-- Cf Other, Format |
| 46 |
-- Cn Other, Not Assigned |
| 47 |
-- Co Other, Private Use |
| 48 |
-- Cs Other, Surrogate |
| 49 |
-- Ll Letter, Lowercase |
| 50 |
-- Lm Letter, Modifier |
| 51 |
-- Lo Letter, Other |
| 52 |
-- Lt Letter, Titlecase |
| 53 |
-- Lu Letter, Uppercase |
| 54 |
-- Mc Mark, Spacing Combining |
| 55 |
-- Me Mark, Enclosing |
| 56 |
-- Mn Mark, Nonspacing |
| 57 |
-- Nd Number, Decimal Digit |
| 58 |
-- Nl Number, Letter |
| 59 |
-- No Number, Other |
| 60 |
-- Pc Punctuation, Connector |
| 61 |
-- Pd Punctuation, Dash |
| 62 |
-- Pe Punctuation, Close |
| 63 |
-- Pf Punctuation, Final quote |
| 64 |
-- Pi Punctuation, Initial quote |
| 65 |
-- Po Punctuation, Other |
| 66 |
-- Ps Punctuation, Open |
| 67 |
-- Sc Symbol, Currency |
| 68 |
-- Sk Symbol, Modifier |
| 69 |
-- Sm Symbol, Math |
| 70 |
-- So Symbol, Other |
| 71 |
-- Zl Separator, Line |
| 72 |
-- Zp Separator, Paragraph |
| 73 |
-- Zs Separator, Space |
| 74 |
-- Fe relative position FFFE/FFFF in plane |
| 75 |
|
| 76 |
function Get_Category (U : Wide_Wide_Character) return Category; |
| 77 |
pragma Inline (Get_Category); |
| 78 |
-- Given a Wide_Wide_Character, returns corresponding Category, or Cn if |
| 79 |
-- the code does not have an assigned unicode category. |
| 80 |
|
| 81 |
-- The following functions perform category tests corresponding to lexical |
| 82 |
-- classes defined in the Ada standard. There are two interfaces for each |
| 83 |
-- function. The second takes a Category (e.g. returned by Get_Category). |
| 84 |
-- The first takes a Wide_Wide_Character. The form taking the |
| 85 |
-- Wide_Wide_Character is typically more efficient than calling |
| 86 |
-- Get_Category, but if several different tests are to be performed on the |
| 87 |
-- same code, it is more efficient to use Get_Category to get the category, |
| 88 |
-- then test the resulting category. |
| 89 |
|
| 90 |
function Is_Letter (U : Wide_Wide_Character) return Boolean; |
| 91 |
function Is_Letter (C : Category) return Boolean; |
| 92 |
pragma Inline (Is_Letter); |
| 93 |
-- Returns true iff U is a letter that can be used to start an identifier, |
| 94 |
-- or if C is one of the corresponding categories, which are the following: |
| 95 |
-- Letter, Uppercase (Lu) |
| 96 |
-- Letter, Lowercase (Ll) |
| 97 |
-- Letter, Titlecase (Lt) |
| 98 |
-- Letter, Modifier (Lm) |
| 99 |
-- Letter, Other (Lo) |
| 100 |
-- Number, Letter (Nl) |
| 101 |
|
| 102 |
function Is_Digit (U : Wide_Wide_Character) return Boolean; |
| 103 |
function Is_Digit (C : Category) return Boolean; |
| 104 |
pragma Inline (Is_Digit); |
| 105 |
-- Returns true iff U is a digit that can be used to extend an identifer, |
| 106 |
-- or if C is one of the corresponding categories, which are the following: |
| 107 |
-- Number, Decimal_Digit (Nd) |
| 108 |
|
| 109 |
function Is_Line_Terminator (U : Wide_Wide_Character) return Boolean; |
| 110 |
pragma Inline (Is_Line_Terminator); |
| 111 |
-- Returns true iff U is an allowed line terminator for source programs, |
| 112 |
-- if U is in the category Zp (Separator, Paragaph), or Zs (Separator, |
| 113 |
-- Line), or if U is a conventional line terminator (CR, LF, VT, FF). |
| 114 |
-- There is no category version for this function, since the set of |
| 115 |
-- characters does not correspond to a set of Unicode categories. |
| 116 |
|
| 117 |
function Is_Mark (U : Wide_Wide_Character) return Boolean; |
| 118 |
function Is_Mark (C : Category) return Boolean; |
| 119 |
pragma Inline (Is_Mark); |
| 120 |
-- Returns true iff U is a mark character which can be used to extend an |
| 121 |
-- identifier, or if C is one of the corresponding categories, which are |
| 122 |
-- the following: |
| 123 |
-- Mark, Non-Spacing (Mn) |
| 124 |
-- Mark, Spacing Combining (Mc) |
| 125 |
|
| 126 |
function Is_Other (U : Wide_Wide_Character) return Boolean; |
| 127 |
function Is_Other (C : Category) return Boolean; |
| 128 |
pragma Inline (Is_Other); |
| 129 |
-- Returns true iff U is an other format character, which means that it |
| 130 |
-- can be used to extend an identifier, but is ignored for the purposes of |
| 131 |
-- matching of identiers, or if C is one of the corresponding categories, |
| 132 |
-- which are the following: |
| 133 |
-- Other, Format (Cf) |
| 134 |
|
| 135 |
function Is_Punctuation (U : Wide_Wide_Character) return Boolean; |
| 136 |
function Is_Punctuation (C : Category) return Boolean; |
| 137 |
pragma Inline (Is_Punctuation); |
| 138 |
-- Returns true iff U is a punctuation character that can be used to |
| 139 |
-- separate pices of an identifier, or if C is one of the corresponding |
| 140 |
-- categories, which are the following: |
| 141 |
-- Punctuation, Connector (Pc) |
| 142 |
|
| 143 |
function Is_Space (U : Wide_Wide_Character) return Boolean; |
| 144 |
function Is_Space (C : Category) return Boolean; |
| 145 |
pragma Inline (Is_Space); |
| 146 |
-- Returns true iff U is considered a space to be ignored, or if C is one |
| 147 |
-- of the corresponding categories, which are the following: |
| 148 |
-- Separator, Space (Zs) |
| 149 |
|
| 150 |
function Is_NFKC (U : Wide_Wide_Character) return Boolean; |
| 151 |
pragma Inline (Is_NFKC); |
| 152 |
-- Returns True if the Wide_Wide_Character designated by U could be present |
| 153 |
-- in a string normalized to Normalization Form KC (as defined by Clause |
| 154 |
-- 21 of ISO/IEC 10646:2017), otherwise returns False. |
| 155 |
|
| 156 |
function Is_Non_Graphic (U : Wide_Wide_Character) return Boolean; |
| 157 |
function Is_Non_Graphic (C : Category) return Boolean; |
| 158 |
pragma Inline (Is_Non_Graphic); |
| 159 |
-- Returns true iff U is considered to be a non-graphic character, or if C |
| 160 |
-- is one of the corresponding categories, which are the following: |
| 161 |
-- Other, Control (Cc) |
| 162 |
-- Other, Private Use (Co) |
| 163 |
-- Other, Surrogate (Cs) |
| 164 |
-- Separator, Line (Zl) |
| 165 |
-- Separator, Paragraph (Zp) |
| 166 |
-- FFFE or FFFF positions in any plane (Fe) |
| 167 |
-- |
| 168 |
-- Note that the Ada category format effector is subsumed by the above |
| 169 |
-- list of Unicode categories. |
| 170 |
-- |
| 171 |
-- Note that Other, Unassiged (Cn) is quite deliberately not included |
| 172 |
-- in the list of categories above. This means that should any of these |
| 173 |
-- code positions be defined in future with graphic characters they will |
| 174 |
-- be allowed without a need to change implementations or the standard. |
| 175 |
-- |
| 176 |
-- Note that Other, Format (Cf) is also quite deliberately not included |
| 177 |
-- in the list of categories above. This means that these characters can |
| 178 |
-- be included in character and string literals. |
| 179 |
|
| 180 |
function Is_Basic (U : Wide_Wide_Character) return Boolean; |
| 181 |
pragma Inline (Is_Basic); |
| 182 |
-- Returns True if the Wide_Wide_Character designated by Item has no |
| 183 |
-- Decomposition Mapping in the code charts of ISO/IEC 10646:2017, |
| 184 |
-- otherwise returns False. |
| 185 |
|
| 186 |
function To_Basic (U : Wide_Wide_Character) return Wide_Wide_Character; |
| 187 |
pragma Inline (To_Basic); |
| 188 |
-- Returns the Wide_Wide_Character whose code point is given by the first |
| 189 |
-- value of its Decomposition Mapping in the code charts of |
| 190 |
-- ISO/IEC 10646:2017 if any, returns Item otherwise. |
| 191 |
|
| 192 |
-- The following function is used to fold to upper case, as required by |
| 193 |
-- the Ada 2005 standard rules for identifier case folding. Two |
| 194 |
-- identifiers are equivalent if they are identical after folding all |
| 195 |
-- letters to upper case using this routine. A fold to lower routine is |
| 196 |
-- also provided. |
| 197 |
|
| 198 |
function To_Lower_Case |
| 199 |
(U : Wide_Wide_Character) return Wide_Wide_Character; |
| 200 |
pragma Inline (To_Lower_Case); |
| 201 |
-- If U represents an upper case letter, returns the corresponding lower |
| 202 |
-- case letter, otherwise U is returned unchanged. The folding is locale |
| 203 |
-- independent as defined by documents referenced in the note in section |
| 204 |
-- 1 of ISO/IEC 10646:2003 |
| 205 |
|
| 206 |
function To_Upper_Case |
| 207 |
(U : Wide_Wide_Character) return Wide_Wide_Character; |
| 208 |
pragma Inline (To_Upper_Case); |
| 209 |
-- If U represents a lower case letter, returns the corresponding upper |
| 210 |
-- case letter, otherwise U is returned unchanged. The folding is locale |
| 211 |
-- independent as defined by documents referenced in the note in section |
| 212 |
-- 1 of ISO/IEC 10646:2003 |
| 213 |
|
| 214 |
end Ada.Wide_Wide_Characters.Unicode; |