------------------------------------------------------------------------------
-- --
--- GNAT RUNTIME COMPONENTS --
+-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . W C H _ J I S --
-- --
-- B o d y --
-- --
--- $Revision: 1.5 $ --
--- --
--- Copyright (C) 1992,1993,1994 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- --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
--- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
--- MA 02111-1307, USA. --
+-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
+-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
--- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
+-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
+with System.Pure_Exceptions; use System.Pure_Exceptions;
+
package body System.WCh_JIS is
type Byte is mod 256;
----------------
procedure JIS_To_EUC
- (J : in Wide_Character;
+ (J : Wide_Character;
EUC1 : out Character;
EUC2 : out Character)
is
JIS2 : constant Natural := Wide_Character'Pos (J) rem 256;
begin
+ -- Special case of small Katakana
+
if JIS1 = 0 then
+
+ -- The value must be in the range 16#80# to 16#FF# so that the upper
+ -- bit is set in both bytes.
+
+ if JIS2 < 16#80# then
+ Raise_Exception (CE, "invalid small Katakana character");
+ end if;
+
EUC1 := Character'Val (EUC_Hankaku_Kana);
EUC2 := Character'Val (JIS2);
+ -- The upper bit of both characters must be clear, or this is not
+ -- a valid character for representation in EUC form.
+
+ elsif JIS1 > 16#7F# or else JIS2 > 16#7F# then
+ Raise_Exception (CE, "wide character value out of EUC range");
+
+ -- Result is just the two characters with upper bits set
+
else
EUC1 := Character'Val (JIS1 + 16#80#);
EUC2 := Character'Val (JIS2 + 16#80#);
----------------------
procedure JIS_To_Shift_JIS
- (J : in Wide_Character;
+ (J : Wide_Character;
SJ1 : out Character;
SJ2 : out Character)
is