-
Notifications
You must be signed in to change notification settings - Fork 0
CryptAda.Lists.Identifier_Item
This package provides functionality for handling Identifiers either as items in lists or as item name in both, text form and as Identifier objects. Manipulation of Identifiers in the enumeration form is provided by the generic package CryptAda.Lists.Enumeration_Item.
Identifiers are character sequence that meet the syntax rules for Ada identifiers:
- First character must be a letter (Ada.Characters.Handling.Is_Letter shall return True for that character).
- Next characters must be either alphanumeric characters or the underscore '_' character.
- No two or more consecutive underscore characters are allowed and the underscore could not be the last character of the identifier.
- Ada reserved words are not allowed as identifiers.
Identifier comparison is case unsensitive, when converting from identifier text to Identifier, any whitespace (' ' | HT .. CR) before first identifier character or after the last identifier character is removed.
Case, when returning back the text from an Identifier object is preserved.
Maximum length for identifier is defined by the constant Identifier_Max_Length defined in CryptAda.Lists.
A null identifier represents an undefined identifier and is the value that an Identifier object acquires when its definition is elaborated.
procedure Copy_Identifier(
From : in Identifier;
To : in out Identifier);
Returns in To
a copy of From
.
- From. Source Identifier of the copy.
- To. Target Identifier of the copy.
-
CryptAda_Identifier_Error if
From
is a null identifier. - CryptAda_Storage_Error if an error is raised when allocating space for the copied items.
procedure Text_2_Identifier(
From : in Identifier_Text;
To : in out Identifier);
Converts an identifier text to its identifier representation.
- From. Identifier text to convert.
-
To. Identifier resulting from
From
conversion.
-
CryptAda_Overflow_Error if
From
identifier characters exceeds the maximum defined length for identifiers. - CryptAda_Storage_Error if an error is raised when allocating space for the identifier.
-
CryptAda_Syntax_Error if
From
does not meet the syntax rules for identifiers.
procedure Identifier_2_Text(
From : in Identifier;
To : out Identifier_Text;
Length : out Positive);
function Identifier_2_Text(
From : in Identifier)
return Identifier_Text;
Returns the text representation of an identifier value.
Two overloaded forms are provided: a procedure form and a function form.
The case of the identifier characters in the identifier text returned by these subprograms is preserved so:
declare
Id_Text_1 : constant Identifier_Text := "Hello";
Id : Identifier;
begin
Text_2_Identifier(Id_Text_1, Id);
declare
Id_Text_2 : constant Identifier_Text := Identifier_2_Text(Id);
B : Boolean := (Id_Text_1 = Id_Text_2);
begin
-- B is always True.
end;
end;
- From. Identifier from which the text form is to be returned.
-
To. Procedure form,
Identifier_Text
object where the text form ofFrom
will be copied. -
Length. Procedure form, number of characters copied to
To
.
Function form, Identifier_Text
value containing the text representation of From
.
-
CryptAda_Identifier_Error if
From
is a null identifier. -
CryptAda_Overflow_Error (procedure form) if
To
length is not enough to hold the text representation ofFrom
.
function Is_Null(
What : in Identifier)
return Boolean;
Checks whether or not an Identifier is null.
- What. Identifier to check.
Boolean value indicating whether the Identifier is null or not.
None.
procedure Make_Null(
What : in out Identifier);
Makes a given identifier null.
- What. Identifier to make null.
None.
function Is_Equal(
Left : in Identifier;
Right : in Identifier)
return Boolean;
Equality test for Identifiers. Two identifiers are equal if:
- They are both null.
- They contain the same sequence of characters ignoring case for letters.
Note:
declare
Id_T_1 : constant Identifier_Text := "Hello";
Id_T_2 : constant Identifier_Text := "HELLO";
Id_1 : Identifier;
Id_2 : Identifier;
begin
Text_2_Identifier(Id_T_1, Id_1);
Text_2_Identifier(Id_T_2, Id_2);
-- (Id_T_1 = Id_T_2) is always False.
-- Is_Equal(Id_1, Id_2) is always True.
end;
- Left. First identifier to compare.
- Right. Second identifier to compare.
Boolean value indicating if the identifiers are equal or not.
None.
function Text_Length(
Of_Id : in Identifier)
return Natural;
Returns the length of the text representation of an Identifier.
- Of_Id. Identifier for which the text length is to be obtained.
Natural value with Of_Id text length.
None.
procedure Get_Value(
From_List : in List;
At_Position : in Position_Count;
Value : in out Identifier);
procedure Get_Value(
From_List : in List;
Item_Name : in Identifier;
Value : in out Identifier);
procedure Get_Value(
From_List : in List;
Item_Name : in Identifier_Text;
Value : in out Identifier);
Returns the value of a specific Identifier item from the current list of a List object.
Three overloaded forms are provided:
- Returns the identifier item value provided its position (unnamed and named lists).
- Returns the identifier item value provided its item name as an Identifier (named lists).
- Returns the identifier item value provided its item name as an Identifier_Text (named lists).
- From_List. List object from whose current list the identifier item value is to be retrieved.
- At_Position. First overloaded form, position of the identifier item in From_List current list.
- Item_Name. Second and third overloaded forms, either an Identifier or an Identifier_Text with the name of the identifier item.
- Value. Value of the identifier item.
-
CryptAda_List_Kind_Error if
From_List
current list is Empty. -
CryptAda_Index_Error if
At_Position
is not a valid position inFrom_List
current list. -
CryptAda_Identifier_Error (second form) if the
Item_Name
is a null identifier. -
CryptAda_Syntax_Error (third form) if the
Identifier_Text
does not conform the syntax for identifiers. -
CryptAda_Named_List_Error (second and third forms) if
From_List
current list is an unnamed list. -
CryptAda_Item_Not_Found_Error (second and third forms) there is no item with
Item_Name
in the current list ofFrom_List
. -
CryptAda_Item_Kind_Error if
At_Position
orItem_Name
identify an item whose kind is notIdentifier_Item_Kind
.
procedure Replace_Value(
In_List : in out List;
At_Position : in Position_Count;
Value : in Identifier);
procedure Replace_Value(
In_List : in out List;
Item_Name : in Identifier;
Value : in Identifier);
procedure Replace_Value(
In_List : in out List;
Item_Name : in Identifier_Text;
Value : in Identifier);
Replaces the value of a specific Identifier item from the current list of a List object with a replacement identifier provided.
Three overloaded forms are provided:
- Replaces the identifier item value provided its position (unnamed and named lists).
- Replaces the identifier item value provided its item name as an Identifier (named lists).
- Replaces the identifier item value provided its item name as an Identifier_Text (named lists).
- In_List. List object from whose current list contains the identifier item whose value is to be replaced.
- At_Position. First overloaded form, position of the identifier item in In_List current list.
- Item_Name. Second and third overloaded forms, either an Identifier or an Identifier_Text with the name of the identifier item.
- Value. New value for the identifier item.
-
CryptAda_List_Kind_Error if
In_List
current list is Empty. -
CryptAda_Index_Error if
At_Position
is not a valid position inIn_List
current list. -
CryptAda_Identifier_Error if the
Item_Name
in the second form is a null identifier or ifValue
is a null identifier. -
CryptAda_Syntax_Error (third form) if the
Identifier_Text
does not conform the syntax for identifiers. -
CryptAda_Named_List_Error (second and third forms) if
In_List
current list is an unnamed list. -
CryptAda_Item_Not_Found_Error (second and third forms) there is no item with
Item_Name
in the current list ofIn_List
. -
CryptAda_Item_Kind_Error if
At_Position
orItem_Name
identify an item whose kind is notIdentifier_Item_Kind
.
procedure Insert_Value(
In_List : in out List;
At_Position : in Insert_Count;
Value : in Identifier);
procedure Insert_Value(
In_List : in out List;
At_Position : in Insert_Count;
Item_Name : in Identifier;
Value : in Identifier);
procedure Insert_Value(
In_List : in out List;
At_Position : in Insert_Count;
Item_Name : in Identifier_Text;
Value : in Identifier);
Inserts an Identifier value at a specific position into the current list of a List object.
Three overloaded forms are provided:
- Inserts an unnamed identifier value.
- Inserts a named identifier value given its name as Identifier.
- Inserts a named identifier value given its name as Identifier_Text.
- In_List. List object in whose current list the identifier item is to be inserted.
-
At_Position. Insert count value that specifies the position where insertion will take place (0 meaning at the beginning and any positive value means after the item which ocuppies
At_Position
position). - Item_Name. Second and third overloaded forms, either an Identifier or an Identifier_Text with the name of the identifier item to insert.
- Value. Value of the identifier item to insert.
-
CryptAda_List_Kind_Error if
In_List
is named and the first form is used or ifIn_List
is unnamed and second and third forms are attempted. -
CryptAda_Index_Error if
At_Position
is not a valid insertion position inIn_List
current list. -
CryptAda_Identifier_Error if the
Item_Name
in the second form is a null identifier or ifValue
is a null identifier. -
CryptAda_Syntax_Error (third form) if the
Identifier_Text
does not conform the syntax for identifiers. -
CryptAda_Overflow_Error if the insertion operation will cause that
In_List
current list will exceed the maximum number of items for a List object.
function Position_By_Value(
In_List : in List;
Value : in Identifier;
Start_Position : in Position_Count := Position_Count'First;
End_Position : in Position_Count := Position_Count'Last)
return Position_Count;
Returns the position that an Identifier item with a specific value occupies into the current list of a List object.
- In_List. List object to query for the item position.
- Value. Item value searched for.
- Start_Position. Position in the current list to start the search from.
- End_Position. Position in the current list beyond which the search will not proceed.
-
CryptAda_List_Kind_Error if
In_List
is empty. -
CryptAda_Index_Error if
Start_Position
is greater than the number of itemsIn_List
or if it is greater thanEnd_Position
. -
CryptAda_Identifier_Error if
Value
is a null identifier. -
CryptAda_Item_Not_Found_Error if no item with value
Value
was foundIn_List
.
function Is_Enumerated(
In_List : in List;
At_Position : in Position_Count)
return Boolean;
function Is_Enumerated(
In_List : in List;
Item_Name : in Identifier)
return Boolean;
function Is_Enumerated(
In_List : in List;
Item_Name : in Identifier_Text)
return Boolean;
Determines if a specified Identifier item in the current list of a list object is an enumerated item.
Three overloaded forms are provided:
- Item is specified by position (named and unnamed lists).
- Item is specified by name provided as an Identifier (named lists).
- Item is specified by name provided as an Identifier_Text (named lists).
- In_List. List object to query.
- At_Position. (First form) position of the item to query.
- Item_Name. Second and third overloaded forms, either an Identifier or an Identifier_Text with the name of the identifier item to query.
Boolean value that indicates if the identifier item specified is an enumerated value.
-
CryptAda_List_Kind_Error if
In_List
is empty. -
CryptAda_Index_Error if
At_Position
is not a valid position inIn_List
current list. -
CryptAda_Identifier_Error (second form) if the
Item_Name
is a null identifier. -
CryptAda_Syntax_Error (third form) if the
Identifier_Text
does not conform the syntax for identifiers. -
CryptAda_Named_List_Error (second and third forms) if
From_List
current list is an unnamed list. -
CryptAda_Item_Not_Found_Error (second and third forms) there is no item with
Item_Name
in the current list ofFrom_List
. -
CryptAda_Item_Kind_Error if
At_Position
orItem_Name
identify an item whose kind is notIdentifier_Item_Kind
.
function Enumeration_Pos(
In_List : in List;
At_Position : in Position_Count)
return Integer;
function Enumeration_Pos(
In_List : in List;
Item_Name : in Identifier)
return Integer;
function Enumeration_Pos(
In_List : in List;
Item_Name : in Identifier_Text)
return Integer;
Returns the value of the attribute 'Pos of an Identifier item that is an enumerated item in the current list of a list object.
Three overloaded forms are provided:
- Item is specified by position (named and unnamed lists).
- Item is specified by name provided as an Identifier (named lists).
- Item is specified by name provided as an Identifier_Text (named lists).
- In_List. List object to query.
- At_Position. (First form) position of the item to query.
- Item_Name. Second and third overloaded forms, either an Identifier or an Identifier_Text with the name of the identifier item to query.
Integer with the value of 'Pos attribute of the enumeration value.
-
CryptAda_List_Kind_Error if
In_List
is empty. -
CryptAda_Index_Error if
At_Position
is not a valid position inIn_List
current list. -
CryptAda_Identifier_Error (second form) if the
Item_Name
is a null identifier. -
CryptAda_Syntax_Error (third form) if the
Identifier_Text
does not conform the syntax for identifiers. -
CryptAda_Named_List_Error (second and third forms) if
From_List
current list is an unnamed list. -
CryptAda_Item_Not_Found_Error (second and third forms) there is no item with
Item_Name
in the current list ofFrom_List
. -
CryptAda_Item_Kind_Error if
At_Position
orItem_Name
identify an item whose kind is notIdentifier_Item_Kind
or if being an Identifier is not an enumeration value.