Commit 14063a12 by Robert Dewar Committed by Arnaud Charlet

g-byorma.adb (Read_BOM): Reorder tests so that UTF_32 is recognized

2008-03-26  Robert Dewar  <dewar@adacore.com>

	* g-byorma.adb (Read_BOM): Reorder tests so that UTF_32 is recognized

From-SVN: r133584
parent 2a6b365a
......@@ -44,27 +44,13 @@ package body GNAT.Byte_Order_Mark is
XML_Support : Boolean := False)
is
begin
-- UTF-16 (big-endian)
if Str'Length >= 2
and then Str (Str'First) = Character'Val (16#FE#)
and then Str (Str'First + 1) = Character'Val (16#FF#)
then
Len := 2;
BOM := UTF16_BE;
-- UTF-16 (little-endian)
elsif Str'Length >= 2
and then Str (Str'First) = Character'Val (16#FF#)
and then Str (Str'First + 1) = Character'Val (16#FE#)
then
Len := 2;
BOM := UTF16_LE;
-- Note: the order of these tests is important, because in some cases
-- one sequence is a prefix of a longer sequence, and we must test for
-- the longer sequence first
-- UTF-32 (big-endian)
elsif Str'Length >= 4
if Str'Length >= 4
and then Str (Str'First) = Character'Val (16#00#)
and then Str (Str'First + 1) = Character'Val (16#00#)
and then Str (Str'First + 2) = Character'Val (16#FE#)
......@@ -84,6 +70,23 @@ package body GNAT.Byte_Order_Mark is
Len := 4;
BOM := UTF32_LE;
-- UTF-16 (big-endian)
elsif Str'Length >= 2
and then Str (Str'First) = Character'Val (16#FE#)
and then Str (Str'First + 1) = Character'Val (16#FF#)
then
Len := 2;
BOM := UTF16_BE;
-- UTF-16 (little-endian)
elsif Str'Length >= 2
and then Str (Str'First) = Character'Val (16#FF#)
and then Str (Str'First + 1) = Character'Val (16#FE#)
then
Len := 2;
BOM := UTF16_LE;
-- UTF-8 (endian-independent)
elsif Str'Length >= 3
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment