A.3.2 The Package Characters.Handling
Static Semantics
1
The library package
Characters.Handling has the following declaration:
2/2
{
AI95-00362-01}
{
AI95-00395-01}
with Ada.Characters.Conversions;
package Ada.Characters.Handling
is
pragma Pure Preelaborate(Handling);
3
--Character classification functions
4/3
{
AI05-0185-1}
function Is_Control (Item :
in Character)
return Boolean;
function Is_Graphic (Item :
in Character)
return Boolean;
function Is_Letter (Item :
in Character)
return Boolean;
function Is_Lower (Item :
in Character)
return Boolean;
function Is_Upper (Item :
in Character)
return Boolean;
function Is_Basic (Item :
in Character)
return Boolean;
function Is_Digit (Item :
in Character)
return Boolean;
function Is_Decimal_Digit (Item :
in Character)
return Boolean
renames Is_Digit;
function Is_Hexadecimal_Digit (Item :
in Character)
return Boolean;
function Is_Alphanumeric (Item :
in Character)
return Boolean;
function Is_Special (Item :
in Character)
return Boolean;
function Is_Line_Terminator (Item : in Character) return Boolean;
function Is_Mark (Item : in Character) return Boolean;
function Is_Other_Format (Item : in Character) return Boolean;
function Is_Punctuation_Connector (Item : in Character) return Boolean;
function Is_Space (Item : in Character) return Boolean;
5
--Conversion functions for Character and String
6
function To_Lower (Item :
in Character)
return Character;
function To_Upper (Item :
in Character)
return Character;
function To_Basic (Item :
in Character)
return Character;
7
function To_Lower (Item :
in String)
return String;
function To_Upper (Item :
in String)
return String;
function To_Basic (Item :
in String)
return String;
8
--Classifications of and conversions between Character and ISO 646
9
subtype ISO_646
is
Character
range Character'Val(0) .. Character'Val(127);
10
function Is_ISO_646 (Item :
in Character)
return Boolean;
function Is_ISO_646 (Item :
in String)
return Boolean;
11
function To_ISO_646 (Item :
in Character;
Substitute :
in ISO_646 := ' ')
return ISO_646;
12
function To_ISO_646 (Item :
in String;
Substitute :
in ISO_646 := ' ')
return String;
13/2
{
AI95-00285-01}
{
AI95-00395-01}
--
The functions Is_Character, Is_String, To_Character, To_String, To_Wide_Character, Classifications of and conversions between Wide_Character and Character.
-- and To_Wide_String are obsolescent; see J.14.
Paragraphs 14 through 18 were deleted.
14/2
{
AI95-00395-01}
function Is_Character (Item : in Wide_Character) return Boolean;
function Is_String (Item : in Wide_String) return Boolean;
15/2
{
AI95-00395-01}
function To_Character (Item : in Wide_Character;
Substitute : in Character := ' ')
return Character;
16/2
{
AI95-00395-01}
function To_String (Item : in Wide_String;
Substitute : in Character := ' ')
return String;
17/2
{
AI95-00395-01}
function To_Wide_Character (Item : in Character) return Wide_Character;
18/2
{
AI95-00395-01}
function To_Wide_String (Item : in String) return Wide_String;
19
end Ada.Characters.Handling;
19.a/2
Discussion: {
AI95-00395-01}
The with_clause
for Ada.Characters.Conversions is needed for the definition of the obsolescent
functions (see J.14). It would be odd to put
this clause into J.14 as it was not present
in Ada 95, and with_clauses
are semantically neutral to clients anyway.
20
In the description below for each function that returns
a Boolean result, the effect is described in terms of the conditions
under which the value True is returned. If these conditions are not met,
then the function returns False.
21
Each of the following classification functions has
a formal Character parameter, Item, and returns a Boolean result.
22
True if Item is a control character. A control character is a
character whose position is in one of the ranges 0..31 or 127..159.
23
True if Item is a graphic character. A graphic character is a
character whose position is in one of the ranges 32..126 or 160..255.
24
True if Item is a letter. A letter is a character that is in one
of the ranges 'A'..'Z' or 'a'..'z', or whose position is in one of the
ranges 192..214, 216..246, or 248..255.
25
True if Item is a lower-case letter. A lower-case letter is a
character that is in the range 'a'..'z', or whose position is in one
of the ranges 223..246 or 248..255.
26
True if Item is an upper-case letter. An upper-case letter is
a character that is in the range 'A'..'Z' or whose position is in one
of the ranges 192..214 or 216.. 222.
27
True if Item is a basic letter. A basic letter is a character
that is in one of the ranges 'A'..'Z' and 'a'..'z', or that is one of
the following: 'Æ', 'æ', 'Ð', 'ð', 'Þ', 'þ',
or 'ß'.
28
True if Item is a decimal digit. A decimal digit is a character
in the range '0'..'9'.
29
Is_Decimal_Digit
A renaming of Is_Digit.
30
True if Item is a hexadecimal digit. A hexadecimal digit is a
character that is either a decimal digit or that is in one of the ranges
'A' .. 'F' or 'a' .. 'f'.
31
True if Item is an alphanumeric character. An alphanumeric character
is a character that is either a letter or a decimal digit.
32
True if Item is a special graphic character. A special graphic character
is a graphic character that is not alphanumeric.
32.1/3
True if Item is a character with position 10 ..
13 (Line_Feed, Line_Tabulation, Form_Feed, Carriage_Return) or 133 (Next_Line).
32.2/3
Never True (no value of type Character has categories
Mark, Non-Spacing or Mark, Spacing Combining).
32.3/3
True if Item is a character with position 173 (Soft_Hyphen).
32.4/3
True if Item is a character with position 95 ('_',
known as Low_Line or Underscore).
32.5/3
True if Item is a character with position 32 ('
') or 160 (No_Break_Space).
33
Each of the names To_Lower, To_Upper, and To_Basic
refers to two functions: one that converts from Character to Character,
and the other that converts from String to String. The result of each
Character-to-Character function is described below, in terms of the conversion
applied to Item, its formal Character parameter. The result of each
String-to-String conversion is obtained by applying to each element of
the function's String parameter the corresponding Character-to-Character
conversion; the result is the null String if the value of the formal
parameter is the null String. The lower bound of the result String is
1.
34
To_Lower
Returns the corresponding lower-case value for Item if Is_Upper(Item),
and returns Item otherwise.
35
To_Upper
Returns the corresponding upper-case value for Item if Is_Lower(Item)
and Item has an upper-case form, and returns Item otherwise. The lower
case letters 'ß' and 'ÿ' do not have upper case forms.
36
To_Basic
Returns the letter corresponding to Item but with no diacritical mark,
if Item is a letter but not a basic letter; returns Item otherwise.
37
The following set of functions test for membership
in the ISO 646 character range, or convert between ISO 646 and Character.
38
Is_ISO_646
The function whose formal parameter, Item, is of type Character returns
True if Item is in the subtype ISO_646.
39
Is_ISO_646
The function whose formal parameter, Item, is of type String returns
True if Is_ISO_646(Item(I)) is True for each I in Item'Range.
40
To_ISO_646
The function whose first formal parameter, Item, is of type Character
returns Item if Is_ISO_646(Item), and returns the Substitute ISO_646
character otherwise.
41
To_ISO_646
The function whose first formal parameter, Item, is of type String returns
the String whose Range is 1..Item'Length and each of whose elements is
given by To_ISO_646 of the corresponding element in Item.
Paragraphs
42 through 48 were deleted.
42/2
{
AI95-00285-01}
{
AI95-00395-01}
The following set of functions test Wide_Character
values for membership in Character, or convert between corresponding
characters of Wide_Character and Character.
43/2
Returns True if Wide_Character'Pos(Item) <=
Character'Pos(Character'Last).
44/2
Returns True if Is_Character(Item(I)) is True for
each I in Item'Range.
45/2
Returns the Character corresponding to Item if
Is_Character(Item), and returns the Substitute Character otherwise.
46/2
Returns the String whose range is 1..Item'Length
and each of whose elements is given by To_Character of the corresponding
element in Item.
47/2
Returns the Wide_Character X such that Character'Pos(Item)
= Wide_Character'Pos(X).
48/2
Returns the Wide_String whose range is 1..Item'Length
and each of whose elements is given by To_Wide_Character of the corresponding
element in Item.
Implementation Advice
49/2
This paragraph was
deleted.{
AI95-00285-01}
If an implementation provides a localized definition
of Character or Wide_Character, then the effects of the subprograms in
Characters.Handling should reflect the localizations. See also 3.5.2.
50
5 A basic letter is a letter without a
diacritical mark.
51
6 Except
for the hexadecimal digits, basic letters, and ISO_646 characters, the
categories identified in the classification functions form a strict hierarchy:
52
— Control characters
53
— Graphic characters
54
— Alphanumeric characters
55
— Letters
56
— Upper-case letters
57
— Lower-case letters
58
— Decimal digits
59
— Special graphic characters
59.a
Ramification: Thus each Character value
is either a control character or a graphic character but not both; each
graphic character is either an alphanumeric or special graphic but not
both; each alphanumeric is either a letter or decimal digit but not both;
each letter is either upper case or lower case but not both.
60/3
7 {
AI05-0114-1}
There are certain characters which are defined
to be lower case letters by ISO 10646 and are therefore allowed in identifiers,
but are not considered lower case letters by Ada.Characters.Handling.
60.a/3
Reason: This is
to maintain runtime compatibility with the Ada 95 definitions of these
functions. We don't list the exact characters involved because they're
likely to change in future character set standards; the list for ISO
10646:2003 can be found in AI05-0114-1.
60.b/3
Ramification: No
version of Characters.Handling is intended to do portable (Ada-version
independent) manipulation of Ada identifiers. Specifically for Ada 2012,
Wide_Characters.Handling has the correct classification of characters,
but that is unlikely to be true in future Ada standards (it will have
to remain tied to the classifications of ISO 10646:2003 forever in order
to avoid breaking programs at runtime, while future Ada standards will
move to newer character set standards.
Extensions to Ada 95
60.c/2
{
AI95-00362-01}
Characters.Handling is now
Pure, so it can be used in pure units.
Incompatibilities With Ada 2005
60.d/3
{
AI05-0185-1}
Added additional classification
routines so that Characters.Handling has all of the routines available
in Wide_Characters.Handling. If Characters.Handling is referenced in
a use_clause,
and an entity E with a defining_identifier
that is the same as one of the new functions is defined in a package
that is also referenced in a use_clause,
the entity E may no longer be use-visible, resulting in errors.
This should be rare and is easily fixed if it does occur.
Wording Changes from Ada 95
60.e/2
60.f/3
{
AI95-00285-01}
{
AI05-0248-1}
We no longer talk about localized character sets;
these are a nonstandard non-standard mode, which is none of our business.
Wording Changes from Ada 2005
60.g/3
{
AI05-0114-1}
Correction: Added a note to clarify that
these functions don't have any relationship to the characters allowed
in identifiers.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe