Index: widechar.adb =================================================================== --- widechar.adb (revision 118179) +++ widechar.adb (working copy) @@ -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- -- @@ -52,20 +52,35 @@ package body Widechar is is begin case Wide_Character_Encoding_Method is + + -- For Hex mode, just test for an ESC character. The ESC character + -- cannot appear in any other context in a legal Ada program. + when WCEM_Hex => return S (P) = ASCII.ESC; - when WCEM_Upper | - WCEM_Shift_JIS | - WCEM_EUC | - WCEM_UTF8 => - return S (P) >= Character'Val (16#80#); + -- For brackets, just test ["x where x is a hex character. This is + -- sufficient test, since this sequence cannot otherwise appear in a + -- legal Ada program. when WCEM_Brackets => return P <= S'Last - 2 and then S (P) = '[' and then S (P + 1) = '"' - and then S (P + 2) /= '"'; + and then (S (P + 2) in '0' .. '9' + or else + S (P + 2) in 'a' .. 'f' + or else + S (P + 2) in 'A' .. 'F'); + + -- All other encoding methods use the upper bit set in the first + -- character to uniquely represent a wide character. + + when WCEM_Upper | + WCEM_Shift_JIS | + WCEM_EUC | + WCEM_UTF8 => + return S (P) >= Character'Val (16#80#); end case; end Is_Start_Of_Wide_Char; @@ -89,6 +104,7 @@ package body Widechar is Err : out Boolean) is P_Init : constant Source_Ptr := P; + Chr : Character; function In_Char return Character; -- Function to obtain characters of wide character escape sequence @@ -108,7 +124,18 @@ package body Widechar is -- Start of processingf for Scan_Wide begin - C := Char_Code (WC_In (In_Char, Wide_Character_Encoding_Method)); + Chr := In_Char; + + -- Scan out the wide character. if the first character is a bracket, + -- we allow brackets encoding regardless of the standard encoding + -- method being used, but otherwise we use this standard method. + + if Chr = '[' then + C := Char_Code (WC_In (Chr, WCEM_Brackets)); + else + C := Char_Code (WC_In (Chr, Wide_Character_Encoding_Method)); + end if; + Err := False; Wide_Char_Byte_Count := Wide_Char_Byte_Count + Nat (P - P_Init - 1);