=================
Character Types
=================

----------------------------------
Language-Defined Character Types
----------------------------------

* :ada:`Character`

   - 8-bit Latin-1 (ASCII subset of Unicode)
   - Base component of :ada:`String`
   - Uses attributes :ada:`'Image` / :ada:`'Value`
   - Part of original Ada language

* :ada:`Wide_Character`

   - 16-bit Unicode (*BMP* - Basic Multilingual Plane)
   - Base component of :ada:`Wide_Strings`
   - Uses attributes :ada:`'Wide_Image` / :ada:`'Wide_Value`
   - Added in Ada 95

* :ada:`Wide_Wide_Character`

   - 32-bit Unicode (full Unicode support)
   - Base component of :ada:`Wide_Wide_Strings`
   - Uses attributes :ada:`'Wide_Wide_Image` / :ada:`'Wide_Wide_Value`
   - Added in Ada 2005

-----------------------------
Character Oriented Packages
-----------------------------

* Language-defined
* :ada:`Ada.Characters.Handling`

   - Classification
   - Conversion

* :ada:`Ada.Characters.Latin_1`

   - Characters as constants

* See RM Annex A for details

---------------------------------------
Ada.Characters.Latin_1 Sample Content
---------------------------------------

.. code:: Ada

   package Ada.Characters.Latin_1 is
     NUL : constant Character := Character'Val (0);
     ...
     LF  : constant Character := Character'Val (10);
     VT  : constant Character := Character'Val (11);
     FF  : constant Character := Character'Val (12);
     CR  : constant Character := Character'Val (13);
     ...
     Commercial_At  : constant Character := '@';  -- Character'Val (64)
     ...
     LC_A : constant Character := 'a';  -- Character'Val (97)
     LC_B : constant Character := 'b';  -- Character'Val (98)
     ...
     Inverted_Exclamation : constant Character := Character'Val (161);
     Cent_Sign            : constant Character := Character'Val (162);
   ...
     LC_Y_Diaeresis       : constant Character := Character'Val (255);
   end Ada.Characters.Latin_1;

----------------------------------------
Ada.Characters.Handling Sample Content
----------------------------------------

.. code:: Ada

   package Ada.Characters.Handling is
     function Is_Control           (Item : Character) return Boolean;
     function Is_Graphic           (Item : Character) return Boolean;
     function Is_Letter            (Item : Character) return Boolean;
     function Is_Lower             (Item : Character) return Boolean;
     function Is_Upper             (Item : Character) return Boolean;
     function Is_Basic             (Item : Character) return Boolean;
     function Is_Digit             (Item : Character) return Boolean;
     function Is_Decimal_Digit     (Item : Character) return Boolean renames Is_Digit;
     function Is_Hexadecimal_Digit (Item : Character) return Boolean;
     function Is_Alphanumeric      (Item : Character) return Boolean;
     function Is_Special           (Item : Character) return Boolean;
     function To_Lower (Item : Character) return Character;
     function To_Upper (Item : Character) return Character;
     function To_Basic (Item : Character) return Character;
     function To_Lower (Item : String) return String;
     function To_Upper (Item : String) return String;
     function To_Basic (Item : String) return String;
   ...
   end Ada.Characters.Handling;

------
Quiz
------

.. code:: Ada

    type Char_T is (NUL, A, B, 'C');
    for Char_T use (NUL => 0, A => 1, B => 2, 'C' => 3);
    type Str_T is array (Positive range <>) of Char_T;
    Example : Str_T := "CC" & A & NUL;

Which of the following proposition(s) is (are) true

A. The code fails at run-time
B. ``Example'Length = 3``
C. :answermono:`Example (1) = 'C'`
D. :answermono:`Example (3) = A`

.. container:: animate

   Explanations

   A. Unconstrained string is initialized correctly
   B. Null character in Ada is still a character, so length is 4
   C. First element in :ada:`Example` is the character 'C'
   D. Third element in :ada:`Example` is the enumeral :ada:`A`

------
Quiz
------

.. code:: Ada

    with Ada.Characters.Latin_1;
    use Ada.Characters.Latin_1;
    with Ada.Characters.Handling;
    use Ada.Characters.Handling;

Which of the following proposition(s) are true?

A. ``NUL = 0``
B. ``NUL = '\0'``
C. :answermono:`Character'Pos (NUL) = 0`
D. :answermono:`Is_Control (NUL)`

.. container:: animate

   Explanations

   A. :ada:`NUL` is an enumeral - it has no value
   B. :ada:`NUL` cannot be treated as a C-style value
   C. :ada:`NUL` is in the first position (0) of the character type
   D. :ada:`Handling` considers :ada:`NUL` as a control character
