------------------------------------------------------------------------------
--                     XML/Ada - An XML suite for Ada95                     --
--                                                                          --
--                     Copyright (C) 2001-2017, AdaCore                     --
--                                                                          --
-- This library is free software;  you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software  Foundation;  either version 3,  or (at your  option) any later --
-- version. This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
------------------------------------------------------------------------------

with Unicode.Names.Latin_Extended_A; use Unicode.Names.Latin_Extended_A;
with Unicode.Names.Latin_1_Supplement; use Unicode.Names.Latin_1_Supplement;
with Unicode.Names.Spacing_Modifier_Letters;
use Unicode.Names.Spacing_Modifier_Letters;
with Ada.Exceptions;                 use Ada.Exceptions;

package body Unicode.CCS.Iso_8859_4 is

   type Conversion_Arr is array (Unicode_Char range 16#00A1# .. 16#00FF#)
     of Unicode_Char;

   To_Unicode_Arr : constant Conversion_Arr :=
     (16#00A1# => Latin_Capital_Letter_A_With_Ogonek,
      16#00A2# => Latin_Small_Letter_Kra,
      16#00A3# => Latin_Capital_Letter_R_With_Cedilla,
      16#00A4# => Currency_Sign,
      16#00A5# => Latin_Capital_Letter_I_With_Tilde,
      16#00A6# => Latin_Capital_Letter_L_With_Cedilla,
      16#00A7# => Section_Sign,
      16#00A8# => Diaeresis,
      16#00A9# => Latin_Capital_Letter_S_With_Caron,
      16#00AA# => Latin_Capital_Letter_E_With_Macron,
      16#00AB# => Latin_Capital_Letter_G_With_Cedilla,
      16#00AC# => Latin_Capital_Letter_T_With_Stroke,
      16#00AD# => Soft_Hyphen,
      16#00AE# => Latin_Capital_Letter_Z_With_Caron,
      16#00AF# => Macron,
      16#00B0# => Degree_Sign,
      16#00B1# => Latin_Small_Letter_A_With_Ogonek,
      16#00B2# => Ogonek,
      16#00B3# => Latin_Small_Letter_R_With_Cedilla,
      16#00B4# => Acute_Accent,
      16#00B5# => Latin_Small_Letter_I_With_Tilde,
      16#00B6# => Latin_Small_Letter_L_With_Cedilla,
      16#00B7# => Caron,
      16#00B8# => Cedilla,
      16#00B9# => Latin_Small_Letter_S_With_Caron,
      16#00BA# => Latin_Small_Letter_E_With_Macron,
      16#00BB# => Latin_Small_Letter_G_With_Cedilla,
      16#00BC# => Latin_Small_Letter_T_With_Stroke,
      16#00BD# => Latin_Capital_Letter_Eng,
      16#00BE# => Latin_Small_Letter_Z_With_Caron,
      16#00BF# => Latin_Small_Letter_Eng,
      16#00C0# => Latin_Capital_Letter_A_With_Macron,
      16#00C1# => Latin_Capital_Letter_A_With_Acute,
      16#00C2# => Latin_Capital_Letter_A_With_Circumflex,
      16#00C3# => Latin_Capital_Letter_A_With_Tilde,
      16#00C4# => Latin_Capital_Letter_A_With_Diaeresis,
      16#00C5# => Latin_Capital_Letter_A_With_Ring_Above,
      16#00C6# => Latin_Capital_Letter_Ae,
      16#00C7# => Latin_Capital_Letter_I_With_Ogonek,
      16#00C8# => Latin_Capital_Letter_C_With_Caron,
      16#00C9# => Latin_Capital_Letter_E_With_Acute,
      16#00CA# => Latin_Capital_Letter_E_With_Ogonek,
      16#00CB# => Latin_Capital_Letter_E_With_Diaeresis,
      16#00CC# => Latin_Capital_Letter_E_With_Dot_Above,
      16#00CD# => Latin_Capital_Letter_I_With_Acute,
      16#00CE# => Latin_Capital_Letter_I_With_Circumflex,
      16#00CF# => Latin_Capital_Letter_I_With_Macron,
      16#00D0# => Latin_Capital_Letter_D_With_Stroke,
      16#00D1# => Latin_Capital_Letter_N_With_Cedilla,
      16#00D2# => Latin_Capital_Letter_O_With_Macron,
      16#00D3# => Latin_Capital_Letter_K_With_Cedilla,
      16#00D4# => Latin_Capital_Letter_O_With_Circumflex,
      16#00D5# => Latin_Capital_Letter_O_With_Tilde,
      16#00D6# => Latin_Capital_Letter_O_With_Diaeresis,
      16#00D7# => Multiplication_Sign,
      16#00D8# => Latin_Capital_Letter_O_With_Stroke,
      16#00D9# => Latin_Capital_Letter_U_With_Ogonek,
      16#00DA# => Latin_Capital_Letter_U_With_Acute,
      16#00DB# => Latin_Capital_Letter_U_With_Circumflex,
      16#00DC# => Latin_Capital_Letter_U_With_Diaeresis,
      16#00DD# => Latin_Capital_Letter_Y_With_Acute,
      16#00DE# => Latin_Capital_Letter_U_With_Macron,
      16#00DF# => Latin_Small_Letter_Sharp_S,
      16#00E0# => Latin_Small_Letter_A_With_Macron,
      16#00E1# => Latin_Small_Letter_A_With_Acute,
      16#00E2# => Latin_Small_Letter_A_With_Circumflex,
      16#00E3# => Latin_Small_Letter_A_With_Tilde,
      16#00E4# => Latin_Small_Letter_A_With_Diaeresis,
      16#00E5# => Latin_Small_Letter_A_With_Ring_Above,
      16#00E6# => Latin_Small_Letter_Ae,
      16#00E7# => Latin_Small_Letter_I_With_Ogonek,
      16#00E8# => Latin_Small_Letter_C_With_Caron,
      16#00E9# => Latin_Small_Letter_E_With_Acute,
      16#00EA# => Latin_Small_Letter_E_With_Ogonek,
      16#00EB# => Latin_Small_Letter_E_With_Diaeresis,
      16#00EC# => Latin_Small_Letter_E_With_Dot_Above,
      16#00ED# => Latin_Small_Letter_I_With_Acute,
      16#00EE# => Latin_Small_Letter_I_With_Circumflex,
      16#00EF# => Latin_Small_Letter_I_With_Macron,
      16#00F0# => Latin_Small_Letter_D_With_Stroke,
      16#00F1# => Latin_Small_Letter_N_With_Cedilla,
      16#00F2# => Latin_Small_Letter_O_With_Macron,
      16#00F3# => Latin_Small_Letter_K_With_Cedilla,
      16#00F4# => Latin_Small_Letter_O_With_Circumflex,
      16#00F5# => Latin_Small_Letter_O_With_Tilde,
      16#00F6# => Latin_Small_Letter_O_With_Diaeresis,
      16#00F7# => Division_Sign,
      16#00F8# => Latin_Small_Letter_O_With_Stroke,
      16#00F9# => Latin_Small_Letter_U_With_Ogonek,
      16#00FA# => Latin_Small_Letter_U_With_Acute,
      16#00FB# => Latin_Small_Letter_U_With_Circumflex,
      16#00FC# => Latin_Small_Letter_U_With_Diaeresis,
      16#00FD# => Latin_Small_Letter_U_With_Tilde,
      16#00FE# => Latin_Small_Letter_U_With_Macron,
      16#00FF# => Dot_Above);

   ----------------
   -- To_Unicode --
   ----------------

   function To_Unicode (Char : Unicode_Char) return Unicode_Char is
   begin
      if Char > To_Unicode_Arr'Last then
         Raise_Exception
           (Invalid_Code'Identity,
            "code " & Unicode_Char'Image (Char)
            & " is not available in Iso/8859-4");

      elsif Char < To_Unicode_Arr'First then
         return Char;

      else
         return To_Unicode_Arr (Char);
      end if;
   end To_Unicode;

   -------------------
   -- To_Iso_8859_4 --
   -------------------

   function To_Iso_8859_4 (Char : Unicode_Char) return Unicode_Char is
   begin
      case Char is
         when Latin_Capital_Letter_A_With_Ogonek     => return 16#00A1#;
         when Latin_Small_Letter_Kra                 => return 16#00A2#;
         when Latin_Capital_Letter_R_With_Cedilla    => return 16#00A3#;
         when Currency_Sign                          => return 16#00A4#;
         when Latin_Capital_Letter_I_With_Tilde      => return 16#00A5#;
         when Latin_Capital_Letter_L_With_Cedilla    => return 16#00A6#;
         when Latin_Capital_Letter_S_With_Caron      => return 16#00A9#;
         when Latin_Capital_Letter_E_With_Macron     => return 16#00AA#;
         when Latin_Capital_Letter_G_With_Cedilla    => return 16#00AB#;
         when Latin_Capital_Letter_T_With_Stroke     => return 16#00AC#;
         when Latin_Capital_Letter_Z_With_Caron      => return 16#00AE#;
         when Latin_Small_Letter_A_With_Ogonek       => return 16#00B1#;
         when Ogonek                                 => return 16#00B2#;
         when Latin_Small_Letter_R_With_Cedilla      => return 16#00B3#;
         when Latin_Small_Letter_I_With_Tilde        => return 16#00B5#;
         when Latin_Small_Letter_L_With_Cedilla      => return 16#00B6#;
         when Caron                                  => return 16#00B7#;
         when Latin_Small_Letter_S_With_Caron        => return 16#00B9#;
         when Latin_Small_Letter_E_With_Macron       => return 16#00BA#;
         when Latin_Small_Letter_G_With_Cedilla      => return 16#00BB#;
         when Latin_Small_Letter_T_With_Stroke       => return 16#00BC#;
         when Latin_Capital_Letter_Eng               => return 16#00BD#;
         when Latin_Small_Letter_Z_With_Caron        => return 16#00BE#;
         when Latin_Small_Letter_Eng                 => return 16#00BF#;
         when Latin_Capital_Letter_A_With_Macron     => return 16#00C0#;
         when Latin_Capital_Letter_I_With_Ogonek     => return 16#00C7#;
         when Latin_Capital_Letter_C_With_Caron      => return 16#00C8#;
         when Latin_Capital_Letter_E_With_Ogonek     => return 16#00CA#;
         when Latin_Capital_Letter_E_With_Dot_Above  => return 16#00CC#;
         when Latin_Capital_Letter_I_With_Macron     => return 16#00CF#;
         when Latin_Capital_Letter_D_With_Stroke     => return 16#00D0#;
         when Latin_Capital_Letter_N_With_Cedilla    => return 16#00D1#;
         when Latin_Capital_Letter_O_With_Macron     => return 16#00D2#;
         when Latin_Capital_Letter_K_With_Cedilla    => return 16#00D3#;
         when Latin_Capital_Letter_U_With_Ogonek     => return 16#00D9#;
         when Latin_Capital_Letter_Y_With_Acute      => return 16#00DD#;
         when Latin_Capital_Letter_U_With_Macron     => return 16#00DE#;
         when Latin_Small_Letter_A_With_Macron       => return 16#00E0#;
         when Latin_Small_Letter_I_With_Ogonek       => return 16#00E7#;
         when Latin_Small_Letter_C_With_Caron        => return 16#00E8#;
         when Latin_Small_Letter_E_With_Ogonek       => return 16#00EA#;
         when Latin_Small_Letter_E_With_Dot_Above    => return 16#00EC#;
         when Latin_Small_Letter_I_With_Macron       => return 16#00EF#;
         when Latin_Small_Letter_D_With_Stroke       => return 16#00F0#;
         when Latin_Small_Letter_N_With_Cedilla      => return 16#00F1#;
         when Latin_Small_Letter_O_With_Macron       => return 16#00F2#;
         when Latin_Small_Letter_K_With_Cedilla      => return 16#00F3#;
         when Latin_Small_Letter_U_With_Ogonek       => return 16#00F9#;
         when Latin_Small_Letter_U_With_Tilde        => return 16#00FD#;
         when Latin_Small_Letter_U_With_Macron       => return 16#00FE#;
         when Dot_Above                              => return 16#00FF#;

         when others =>
            if Char > 16#00FF# then
               Raise_Exception
                 (Invalid_Code'Identity,
                  "code " & Unicode_Char'Image (Char)
                  & " is not available in Iso/8859-4");
            else
               return Char;
            end if;
      end case;
   end To_Iso_8859_4;
end Unicode.CCS.Iso_8859_4;
