diff options
Diffstat (limited to 'gcc/ada/s-widwch.adb')
-rw-r--r-- | gcc/ada/s-widwch.adb | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/gcc/ada/s-widwch.adb b/gcc/ada/s-widwch.adb index a5eaa0451b3..3797bf52c99 100644 --- a/gcc/ada/s-widwch.adb +++ b/gcc/ada/s-widwch.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-1998 Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2005 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- -- @@ -41,15 +41,13 @@ package body System.Wid_WChar is function Width_Wide_Character (Lo, Hi : Wide_Character; - EM : WC_Encoding_Method) - return Natural + EM : WC_Encoding_Method) return Natural is W : Natural; P : Natural; begin W := 0; - for C in Lo .. Hi loop P := Wide_Character'Pos (C); @@ -97,4 +95,64 @@ package body System.Wid_WChar is return W; end Width_Wide_Character; + ------------------------------- + -- Width_Wide_Wide_Character -- + ------------------------------- + + function Width_Wide_Wide_Character + (Lo, Hi : Wide_Wide_Character; + EM : WC_Encoding_Method) return Natural + is + W : Natural; + P : Natural; + + begin + W := 0; + for C in Lo .. Hi loop + P := Wide_Wide_Character'Pos (C); + + -- Here if we find a character in wide wide character range + + if P > 16#FF# then + case EM is + when WCEM_Hex => + return Natural'Max (W, 5); + + when WCEM_Upper => + return Natural'Max (W, 2); + + when WCEM_Shift_JIS => + return Natural'Max (W, 2); + + when WCEM_EUC => + return Natural'Max (W, 2); + + when WCEM_UTF8 => + if Hi > Wide_Wide_Character'Val (16#FFFF#) then + return Natural'Max (W, 4); + elsif Hi > Wide_Wide_Character'Val (16#07FF#) then + return Natural'Max (W, 3); + else + return Natural'Max (W, 2); + end if; + + when WCEM_Brackets => + return Natural'Max (W, 10); + + end case; + + -- If we are in character range then use length of character image + + else + declare + S : constant String := Character'Image (Character'Val (P)); + begin + W := Natural'Max (W, S'Length); + end; + end if; + end loop; + + return W; + end Width_Wide_Wide_Character; + end System.Wid_WChar; |