diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-10-31 17:56:24 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-10-31 17:56:24 +0000 |
commit | 3969ea67cd0834862659426cf5e2c8087522b4b5 (patch) | |
tree | 05efa139ac2fbcb141b5b06f6b620f9dbfb2156e /gcc/ada/s-valwch.adb | |
parent | 4a07180b5fbf70f15bd7db3b0067c4155ebbeffa (diff) | |
download | gcc-3969ea67cd0834862659426cf5e2c8087522b4b5.tar.gz |
2006-10-31 Robert Dewar <dewar@adacore.com>
* exp_imgv.adb (Expand_Image_Attribute): For Wide_[Wide_]Character
cases, pass the encoding method, since it is now required by the run
time.
* s-valwch.ads, s-valwch.adb (Value_Wide_Wide_Character): Avoid
assumption that Str'First = 1.
(Value_Wide_Character): Takes EM (encoding method) parameter and passes
it on to the Value_Wide_Wide_Character call.
(Value_Wide_Wide_Character): Takes EM (encoding method) parameter and
properly handles a string of the form quote-encoded_wide_char-quote.
* s-wchcnv.adb: Minor reformatting
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118266 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/s-valwch.adb')
-rw-r--r-- | gcc/ada/s-valwch.adb | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/gcc/ada/s-valwch.adb b/gcc/ada/s-valwch.adb index 63e02eee759..40a2181d821 100644 --- a/gcc/ada/s-valwch.adb +++ b/gcc/ada/s-valwch.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2005, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2006, 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- -- @@ -33,6 +33,8 @@ with Interfaces; use Interfaces; with System.Val_Util; use System.Val_Util; +with System.WCh_Cnv; use System.WCh_Cnv; +with System.WCh_Con; use System.WCh_Con; package body System.Val_WChar is @@ -41,16 +43,17 @@ package body System.Val_WChar is -------------------------- function Value_Wide_Character - (Str : String) return Wide_Character + (Str : String; + EM : System.WCh_Con.WC_Encoding_Method) return Wide_Character is - WWC : constant Wide_Wide_Character := Value_Wide_Wide_Character (Str); - WWV : constant Unsigned_32 := Wide_Wide_Character'Pos (WWC); + WC : constant Wide_Wide_Character := Value_Wide_Wide_Character (Str, EM); + WV : constant Unsigned_32 := Wide_Wide_Character'Pos (WC); begin - if WWV > 16#FFFF# then + if WV > 16#FFFF# then raise Constraint_Error with "out of range character for Value attribute"; else - return Wide_Character'Val (WWV); + return Wide_Character'Val (WV); end if; end Value_Wide_Character; @@ -59,7 +62,8 @@ package body System.Val_WChar is ------------------------------- function Value_Wide_Wide_Character - (Str : String) return Wide_Wide_Character + (Str : String; + EM : System.WCh_Con.WC_Encoding_Method) return Wide_Wide_Character is F : Natural; L : Natural; @@ -72,25 +76,74 @@ package body System.Val_WChar is if S (F) = ''' and then S (L) = ''' then + -- Must be at least three characters + + if L - F < 2 then + raise Constraint_Error; + -- If just three characters, simple character case - if L - F = 2 then + elsif L - F = 2 then return Wide_Wide_Character'Val (Character'Pos (S (F + 1))); - -- Otherwise something is very wrong + -- Only other possibility for quoted string is wide char sequence else - raise Constraint_Error with "invalid string for Value attribute"; + declare + P : Natural; + W : Wide_Wide_Character; + + function In_Char return Character; + -- Function for instantiations of Char_Sequence_To_UTF_32 + + ------------- + -- In_Char -- + ------------- + + function In_Char return Character is + begin + P := P + 1; + + if P = Str'Last then + raise Constraint_Error; + end if; + + return Str (P); + end In_Char; + + function UTF_32 is + new Char_Sequence_To_UTF_32 (In_Char); + + begin + P := F + 1; + + -- Brackets encoding + + if S (F + 1) = '[' then + W := Wide_Wide_Character'Val (UTF_32 ('[', WCEM_Brackets)); + + else + W := Wide_Wide_Character'Val (UTF_32 (S (F + 1), EM)); + end if; + + if P /= L - 1 then + raise Constraint_Error; + end if; + + return W; + end; end if; -- Deal with Hex_hhhhhhhh cases for wide_[wide_]character cases - elsif Str'Length = 12 and then Str (1 .. 4) = "Hex_" then + elsif Str'Length = 12 + and then Str (Str'First .. Str'First + 3) = "Hex_" + then declare W : Unsigned_32 := 0; begin - for J in 5 .. 12 loop + for J in Str'First + 4 .. Str'First + 11 loop W := W * 16 + Character'Pos (Str (J)); if Str (J) in '0' .. '9' then @@ -100,14 +153,12 @@ package body System.Val_WChar is elsif Str (J) in 'a' .. 'f' then W := W - Character'Pos ('a') + 10; else - raise Constraint_Error - with "illegal hex character for Value attribute"; + raise Constraint_Error; end if; end loop; if W > 16#7FFF_FFFF# then - raise Constraint_Error - with "out of range value for Value attribute"; + raise Constraint_Error; else return Wide_Wide_Character'Val (W); end if; @@ -119,6 +170,10 @@ package body System.Val_WChar is return Wide_Wide_Character'Val (Character'Pos (Character'Value (Str))); end if; + + exception + when Constraint_Error => + raise Constraint_Error with "invalid string for value attribute"; end Value_Wide_Wide_Character; end System.Val_WChar; |