From patchwork Thu Oct 7 09:26:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 67017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 9DAA6B6F01 for ; Thu, 7 Oct 2010 20:26:44 +1100 (EST) Received: (qmail 2507 invoked by alias); 7 Oct 2010 09:26:42 -0000 Received: (qmail 2498 invoked by uid 22791); 7 Oct 2010 09:26:41 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Oct 2010 09:26:37 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id D0259CB022E; Thu, 7 Oct 2010 11:26:34 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id al6v6fPusDvY; Thu, 7 Oct 2010 11:26:34 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id BDA23CB01D4; Thu, 7 Oct 2010 11:26:34 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id A1254D9BB5; Thu, 7 Oct 2010 11:26:34 +0200 (CEST) Date: Thu, 7 Oct 2010 11:26:34 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Robert Dewar Subject: [Ada] Add To_Lower_Case function to Unicode packages Message-ID: <20101007092634.GA31274@adacore.com> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch adds a To_Lower_Case function to the Unicode packages for Wide_Character and Wide_Wide_Character, and improves and corrects the To_Upper_Case function as previously described for the corresponding case conversion routines in System.UTF_32, on which these new routines depend. The following two programs compile without error using -gnata -gnat05: with Ada.Wide_Characters.Unicode; use Ada.Wide_Characters.Unicode; with Text_IO; use Text_IO; procedure WUnicode is subtype WC is Wide_Character; C : WC; procedure T (Test : String; Val : Boolean) is begin if not Val then Put_Line ("Test " & test & " failed"); end if; end T; begin T ("01", To_Upper_Case (WC'Val (16#B5#)) = WC'Val (16#B5#)); T ("02", To_Upper_Case ('a') = 'A'); T ("03", To_Upper_Case (WC'Val (16#253#)) = WC'Val(16#253# - 210)); T ("04", To_Lower_Case (WC'Val(16#B5#)) = WC'Val(16#B5#)); T ("05", To_Lower_Case (WC'Val(16#253# - 210)) = WC'Val(16#253#)); T ("06", To_Lower_Case ('A') = 'a'); for J in Wide_Character loop C := To_Lower_Case (J); T ("07", C = J or else To_Upper_Case (C) = J); C := To_Upper_Case (J); T ("08", C = J or else To_Lower_Case (C) = J); end loop; end WUnicode; with Ada.Wide_Wide_Characters.Unicode; use Ada.Wide_Wide_Characters.Unicode; with Text_IO; use Text_IO; procedure WWUnicode is subtype WC is Wide_Wide_Character; C : WC; procedure T (Test : String; Val : Boolean) is begin if not Val then Put_Line ("Test " & test & " failed"); end if; end T; begin T ("01", To_Upper_Case (WC'Val (16#B5#)) = WC'Val (16#B5#)); T ("02", To_Upper_Case ('a') = 'A'); T ("03", To_Upper_Case (WC'Val (16#253#)) = WC'Val(16#253# - 210)); T ("04", To_Lower_Case (WC'Val(16#B5#)) = WC'Val(16#B5#)); T ("05", To_Lower_Case (WC'Val(16#253# - 210)) = WC'Val(16#253#)); T ("06", To_Lower_Case ('A') = 'a'); for J in WC'Val (0) .. WC'Val(16#10_FFFF#) loop C := To_Lower_Case (J); T ("07", C = J or else To_Upper_Case (C) = J); C := To_Upper_Case (J); T ("08", C = J or else To_Lower_Case (C) = J); end loop; end WWUnicode; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-07 Robert Dewar * a-wichun.ads, a-wichun.adb (To_Lower_Case): New function (To_Upper_Case): Fix to be inverse of To_Lower_Case * a-zchuni.ads, a-zchuni.adb (To_Lower_Case): New function (To_Upper_Case): Fix to be inverse of To_Lower_Case Index: a-zchuni.adb =================================================================== --- a-zchuni.adb (revision 165080) +++ a-zchuni.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2005-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2005-2010, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -150,6 +150,19 @@ package body Ada.Wide_Wide_Characters.Un end Is_Space; ------------------- + -- To_Lower_Case -- + ------------------- + + function To_Lower_Case + (U : Wide_Wide_Character) return Wide_Wide_Character + is + begin + return + Wide_Wide_Character'Val + (G.UTF_32_To_Lower_Case (Wide_Wide_Character'Pos (U))); + end To_Lower_Case; + + ------------------- -- To_Upper_Case -- ------------------- Index: a-zchuni.ads =================================================================== --- a-zchuni.ads (revision 165080) +++ a-zchuni.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 2005-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2005-2010, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -173,7 +173,16 @@ package Ada.Wide_Wide_Characters.Unicode -- The following function is used to fold to upper case, as required by -- the Ada 2005 standard rules for identifier case folding. Two -- identifiers are equivalent if they are identical after folding all - -- letters to upper case using this routine. + -- letters to upper case using this routine. A fold to lower routine is + -- also provided. + + function To_Lower_Case + (U : Wide_Wide_Character) return Wide_Wide_Character; + pragma Inline (To_Lower_Case); + -- If U represents an upper case letter, returns the corresponding lower + -- case letter, otherwise U is returned unchanged. The folding is locale + -- independent as defined by documents referenced in the note in section + -- 1 of ISO/IEC 10646:2003 function To_Upper_Case (U : Wide_Wide_Character) return Wide_Wide_Character; Index: a-wichun.adb =================================================================== --- a-wichun.adb (revision 165080) +++ a-wichun.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2005-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2005-2010, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -150,6 +150,19 @@ package body Ada.Wide_Characters.Unicode end Is_Space; ------------------- + -- To_Lower_Case -- + ------------------- + + function To_Lower_Case + (U : Wide_Character) return Wide_Character + is + begin + return + Wide_Character'Val + (G.UTF_32_To_Lower_Case (Wide_Character'Pos (U))); + end To_Lower_Case; + + ------------------- -- To_Upper_Case -- ------------------- Index: a-wichun.ads =================================================================== --- a-wichun.ads (revision 165080) +++ a-wichun.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 2005-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2005-2010, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -176,7 +176,15 @@ package Ada.Wide_Characters.Unicode is -- The following function is used to fold to upper case, as required by -- the Ada 2005 standard rules for identifier case folding. Two -- identifiers are equivalent if they are identical after folding all - -- letters to upper case using this routine. + -- letters to upper case using this routine. A corresponding function to + -- fold to lower case is also provided. + + function To_Lower_Case (U : Wide_Character) return Wide_Character; + pragma Inline (To_Lower_Case); + -- If U represents an upper case letter, returns the corresponding lower + -- case letter, otherwise U is returned unchanged. The folding is locale + -- independent as defined by documents referenced in the note in section + -- 1 of ISO/IEC 10646:2003 function To_Upper_Case (U : Wide_Character) return Wide_Character; pragma Inline (To_Upper_Case);