home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / s-wchcon.ads < prev    next >
Text File  |  2000-07-19  |  10KB  |  177 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                       S Y S T E M . W C H _ C O N                        --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.10 $                             --
  10. --                                                                          --
  11. --          Copyright (C) 1992-1998 Free Software Foundation, Inc.          --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. --  This package defines the codes used to identify the encoding method for
  37. --  wide characters in string and character constants. This is needed both
  38. --  at compile time and at runtime (for the wide character runtime routines)
  39.  
  40. package System.WCh_Con is
  41. pragma Pure (WCh_Con);
  42.  
  43.    -------------------------------------
  44.    -- Wide_Character Encoding Methods --
  45.    -------------------------------------
  46.  
  47.    --  A wide character encoding method is a method for uniquely representing
  48.    --  a Wide_Character value using a one or more Character values. Three
  49.    --  types of encoding method are supported by GNAT:
  50.  
  51.    --    An escape encoding method uses ESC as the first character of the
  52.    --    sequence, and subsequent characters determine the wide character
  53.    --    value that is represented. Any character other than ESC stands
  54.    --    for itself as a single byte (i.e. any character in Latin-1, other
  55.    --    than ESC itself, is represented as a single character: itself).
  56.  
  57.    --    An upper half encoding method uses a character in the upper half
  58.    --    range (i.e. in the range 16#80# .. 16#FF#) as the first byte of
  59.    --    a wide character encoding sequence. Subsequent characters are
  60.    --    used to determine the wide character value that is represented.
  61.    --    Any character in the lower half (16#00# .. 16#7F#) represents
  62.    --    itself as a single character.
  63.  
  64.    --    The brackets notation, where a wide character is represented
  65.    --    by the sequence ["xx"] or ["xxxx"] where xx are hexadecimal
  66.    --    characters.
  67.  
  68.    --  Note that GNAT does not currently support escape-in, escape-out
  69.    --  encoding methods, where an escape sequence is used to set a mode
  70.    --  used to recognize subsequent characters. All encoding methods use
  71.    --  individual character-by-character encodings, so that a sequence of
  72.    --  wide characters is represented by a sequence of encodings.
  73.  
  74.    --  To add new encoding methods, the following steps are required:
  75.  
  76.    --     1.  Define a code for a new value of type WC_Encoding_Method
  77.    --     2.  Adjust the definition of WC_Encoding_Method accordingly
  78.    --     3.  Provide appropriate conversion routines in System.Wch_Cnv
  79.    --     4.  Adjust definition of WC_Longest_Sequence if necessary
  80.    --     5.  Add an entry in WC_Encoding_Letters for the new method
  81.    --     6.  Add proper code to s-wchstw.adb, s-wchwts.adb, s-widwch.adb
  82.  
  83.    --  Note that the WC_Encoding_Method values must be kept ordered so that
  84.    --  the definitions of the subtypes WC_Upper_Half_Encoding_Method and
  85.    --  WC_ESC_Encoding_Method are still correct.
  86.  
  87.    ---------------------------------
  88.    -- Encoding Method Definitions --
  89.    ---------------------------------
  90.  
  91.    type WC_Encoding_Method is range 1 .. 6;
  92.    --  Type covering the range of values used to represent wide character
  93.    --  encoding methods. An enumeration type might be a little neater, but
  94.    --  more trouble than it's worth, given the need to pass these values
  95.    --  from the compiler to the backend, and to record them in the ALI file.
  96.  
  97.    WCEM_Hex : constant WC_Encoding_Method := 1;
  98.    --  The wide character with code 16#abcd# is represented by the escape
  99.    --  sequence ESC a b c d (five characters, where abcd are ASCII hex
  100.    --  characters, using upper case for letters). This method is easy
  101.    --  to deal with in external environments that do not support wide
  102.    --  characters, and covers the whole BMP. This is the default encoding
  103.    --  method.
  104.  
  105.    WCEM_Upper : constant WC_Encoding_Method := 2;
  106.    --  The wide character with encoding 16#abcd#, where the upper bit is on
  107.    --  (i.e. a is in the range 8-F) is represented as two bytes 16#ab# and
  108.    --  16#cd#. The second byte may never be a format control character, but
  109.    --  is not required to be in the upper half. This method can be also used
  110.    --  for shift-JIS or EUC where the internal coding matches the external
  111.    --  coding.
  112.  
  113.    WCEM_Shift_JIS : constant WC_Encoding_Method := 3;
  114.    --  A wide character is represented by a two character sequence 16#ab#
  115.    --  and 16#cd#, with the restrictions described for upper half encoding
  116.    --  as described above. The internal character code is the corresponding
  117.    --  JIS character according to the standard algorithm for Shift-JIS
  118.    --  conversion. See the body of package System.JIS_Conversions for
  119.    --  further details.
  120.  
  121.    WCEM_EUC : constant WC_Encoding_Method := 4;
  122.    --  A wide character is represented by a two character sequence 16#ab# and
  123.    --  16#cd#, with both characters being in the upper half set. The internal
  124.    --  character code is the corresponding JIS character according to the EUC
  125.    --  encoding algorithm. See the body of package System.JIS_Conversions for
  126.    --  further details.
  127.  
  128.    WCEM_UTF8 : constant WC_Encoding_Method := 5;
  129.    --  An ISO 10646-1 BMP/Unicode wide character is represented in
  130.    --  UCS Transformation Format 8 (UTF-8) as defined in Annex R of ISO
  131.    --  10646-1/Am.2.  Depending on the character value, a Unicode character
  132.    --  is represented as the one, two, or three byte sequence
  133.    --
  134.    --    16#0000#-16#007f#: 2#0xxxxxxx#
  135.    --    16#0080#-16#07ff#: 2#110xxxxx# 2#10xxxxxx#
  136.    --    16#0800#-16#ffff#: 2#1110xxxx# 2#10xxxxxx# 2#10xxxxxx#
  137.    --
  138.    --  where the xxx bits correspond to the left-padded bits of the the
  139.    --  16-bit character value. Note that all lower half ASCII characters
  140.    --  are represented as ASCII bytes and all upper half characters and
  141.    --  other wide characters are represented as sequences of upper-half
  142.    --  (The full UTF-8 scheme allows for encoding 31-bit characters as
  143.    --  6-byte sequences, but in this implementation, all UTF-8 sequences
  144.    --  of four or more bytes length will raise a Constraint_Error, as
  145.    --  will all illegal UTF-8 sequences.)
  146.  
  147.    WCEM_Brackets : constant WC_Encoding_Method := 6;
  148.    --  A wide character is represented as the sequence ["abcd"] where abcd
  149.    --  are four hexadecimal characters. In this mode, the sequence ["ab"]
  150.    --  is also recognized for the case of character codes in the range 0-255.
  151.  
  152.    WC_Encoding_Letters : constant array (WC_Encoding_Method) of Character :=
  153.      (WCEM_Hex       => 'h',
  154.       WCEM_Upper     => 'u',
  155.       WCEM_Shift_JIS => 's',
  156.       WCEM_EUC       => 'e',
  157.       WCEM_UTF8      => '8',
  158.       WCEM_Brackets  => 'b');
  159.    --  Letters used for selection of wide character encoding method in the
  160.    --  compiler options (-gnatW? switch) and for Wide_Text_IO (WCEM parameter
  161.    --  in the form string).
  162.  
  163.    subtype WC_ESC_Encoding_Method is
  164.      WC_Encoding_Method range WCEM_Hex .. WCEM_Hex;
  165.    --  Encoding methods using an ESC character at the start of the sequence.
  166.  
  167.    subtype WC_Upper_Half_Encoding_Method is
  168.      WC_Encoding_Method range WCEM_Upper .. WCEM_UTF8;
  169.    --  Encoding methods using an upper half character (16#80#..16#FF) at
  170.    --  the start of the sequence.
  171.  
  172.    WC_Longest_Sequence : constant := 8;
  173.    --  The longest number of characters that can be used for a wide
  174.    --  character sequence for any of the active encoding methods.
  175.  
  176. end System.WCh_Con;
  177.