File : g-byorma.ads


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT COMPILER COMPONENTS                         --
   4 --                                                                          --
   5 --                 G N A T . B Y T E _ O R D E R _ M A R K                  --
   6 --                                                                          --
   7 --                                 S p e c                                  --
   8 --                                                                          --
   9 --                     Copyright (C) 2006-2013, AdaCore                     --
  10 --                                                                          --
  11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  12 -- terms of the  GNU General Public License as published  by the Free Soft- --
  13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
  14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  16 -- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
  17 --                                                                          --
  18 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  21 --                                                                          --
  22 -- You should have received a copy of the GNU General Public License and    --
  23 -- a copy of the GCC Runtime Library Exception along with this program;     --
  24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
  25 -- <http://www.gnu.org/licenses/>.                                          --
  26 --                                                                          --
  27 -- GNAT was originally developed  by the GNAT team at  New York University. --
  28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
  29 --                                                                          --
  30 ------------------------------------------------------------------------------
  31 
  32 --  This package provides a procedure for reading and interpreting the BOM
  33 --  (byte order mark) used to publish the encoding method for a string (for
  34 --  example, a UTF-8 encoded file in windows will start with the appropriate
  35 --  BOM sequence to signal UTF-8 encoding.
  36 
  37 --  There are two cases
  38 
  39 --    Case 1. UTF encodings for Unicode files
  40 
  41 --      Here the convention is to have the first character of the file be a
  42 --      non-breaking zero width space character (16#0000_FEFF#). For the UTF
  43 --      encodings, the representation of this character can be used to uniquely
  44 --      determine the encoding. Furthermore, the possibility of any confusion
  45 --      with unencoded files is minimal, since for example the UTF-8 encoding
  46 --      of this character looks like the sequence:
  47 
  48 --        LC_I_Diaeresis
  49 --        Right_Angle_Quotation
  50 --        Fraction_One_Half
  51 
  52 --      which is so unlikely to occur legitimately in normal use that it can
  53 --      safely be ignored in most cases (for example, no legitimate Ada source
  54 --      file could start with this sequence of characters).
  55 
  56 --   Case 2. Specialized XML encodings
  57 
  58 --     The XML standard defines a number of other possible encodings and also
  59 --     defines standardized sequences for marking these encodings. This package
  60 --     can also optionally handle these XML defined BOM sequences. These XML
  61 --     cases depend on the first character of the XML file being < so that the
  62 --     encoding of this character can be recognized.
  63 
  64 pragma Compiler_Unit_Warning;
  65 
  66 package GNAT.Byte_Order_Mark is
  67 
  68    type BOM_Kind is
  69      (UTF8_All,  --  UTF8-encoding
  70       UTF16_LE,  --  UTF16 little-endian encoding
  71       UTF16_BE,  --  UTF16 big-endian encoding
  72       UTF32_LE,  --  UTF32 little-endian encoding
  73       UTF32_BE,  --  UTF32 big-endian encoding
  74 
  75       --  The following cases are for XML only
  76 
  77       UCS4_BE,   --  UCS-4, big endian machine (1234 order)
  78       UCS4_LE,   --  UCS-4, little endian machine (4321 order)
  79       UCS4_2143, --  UCS-4, unusual byte order (2143 order)
  80       UCS4_3412, --  UCS-4, unusual byte order (3412 order)
  81 
  82       --  Value returned if no BOM recognized
  83 
  84       Unknown);  --  Unknown, assumed to be ASCII compatible
  85 
  86    procedure Read_BOM
  87      (Str         : String;
  88       Len         : out Natural;
  89       BOM         : out BOM_Kind;
  90       XML_Support : Boolean := False);
  91    --  This is the routine to read the BOM from the start of the given string
  92    --  Str. On return BOM is set to the appropriate BOM_Kind and Len is set to
  93    --  its length. The caller will typically skip the first Len characters in
  94    --  the string to ignore the BOM sequence. The special XML possibilities are
  95    --  recognized only if flag XML_Support is set to True. Note that for the
  96    --  XML cases, Len is always set to zero on return (not to the length of the
  97    --  relevant sequence) since in the XML cases, the sequence recognized is
  98    --  for the first real character in the file (<) which is not to be skipped.
  99 
 100 end GNAT.Byte_Order_Mark;