Rationale for Ada 2012

John Barnes
Contents   Index   References   Search   Previous   Next 

7.5 Hashing and comparison

New library functions are added for case insensitive comparisons and hashing. Thus we have
function Ada.Strings.Equal_Case_Insensitive
           (Left, Right: String) return Boolean;
pragma Pure(Ada.Strings.Equal_Case_Insensitive);
This simply compares the strings Left and Right for equality but ignoring case. Thus
Equal_Case_Insensitive("Pig", "PIG")
is true.
The function Ada.Strings.Fixed.Equal_Case_Insensitive is a renaming of the above. There are also similar functions Ada.Strings.Bounded.Equal_Case_Insensitive for bounded and Ada.Strings.Unbounded.Equal_Case_Insensitive for unbounded strings. And, as expected, there are similar functions for wide and wide wide versions.
Note that the comparison for strings can be phrased as convert to lower case and then compare. But this does not always work for wide and wide wide strings. The proper terminology is "apply locale-independent case folding and then compare".
Although it comes to the same thing for Latin-1 characters there are problems with some character sets where there is not a one-one correspondence between lower case and upper case. This used to apply to English with the two forms of lower case S and still applies to the corresponding letters in Greek where the upper case character is Σ and there are two lower case versions namely σ and ς. So
Ada.Strings.Wide_Equal_Case_Insensitive("ΣΟΣ"), "σος")
returns true. Note that if we just convert to lower case first rather than applying case folding then it would not be true.
Furthermore there is also
function Ada.Strings.Less_Case_Insensitive
       (Left, Right: String) return Boolean;
pragma Pure(Ada.Strings.Less_Case_Insensitive);
which does a lexicographic comparison.
As expected there are similar functions for fixed, bounded and unbounded strings and, naturally, for wide and wide wide versions.
Ada 2005 has functions for hashing such as
with Ada.Containers;
function Ada.Strings.Hash(Key: String)
        return Containers.Hash_Type;
Ada 2012 adds case insensitive versions as well such as
with Ada.Containers;
function Ada.Strings.Hash_Case_Insensitive
         (Key: String) return Containers.Hash_Type;
There are also fixed, bounded and unbounded versions and the inevitable wide and wide wide ones as well.

Contents   Index   References   Search   Previous   Next 
© 2011, 2012, 2013 John Barnes Informatics.
Sponsored in part by:
The Ada Resource Association:

    ARA
  AdaCore:


    AdaCore
and   Ada-Europe:

Ada-Europe