poblem with encoding detection for UTF-16 reported by Ashwin and found by

* encoding.c: poblem with encoding detection for UTF-16 reported by
  Ashwin and found by Bill
* test/valid/dtds/utf16b.ent test/valid/dtds/utf16l.ent
  test/valid/UTF16Entity.xml result/valid/UTF16Entity.xml*: added
  the example to the regression tests
Daniel

svn path=/trunk/; revision=3700
diff --git a/ChangeLog b/ChangeLog
index dfede89..fd7ddbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Mar  6 15:23:10 CET 2008 Daniel Veillard <daniel@veillard.com>
+
+	* encoding.c: poblem with encoding detection for UTF-16 reported by
+	  Ashwin and found by Bill
+	* test/valid/dtds/utf16b.ent test/valid/dtds/utf16l.ent
+	  test/valid/UTF16Entity.xml result/valid/UTF16Entity.xml*: added
+	  the example to the regression tests
+
 Tue Mar  4 14:16:38 CET 2008 Daniel Veillard <daniel@veillard.com>
 
 	* xmlwriter.c: patch from Alex Khesin fixing CDATA output after
diff --git a/encoding.c b/encoding.c
index ee5ac39..6d7a4ce 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1768,9 +1768,10 @@
      * echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
      * 45 chars should be sufficient to reach the end of the encoding
      * declaration without going too far inside the document content.
+     * on UTF-16 this means 90bytes, on UCS4 this means 180
      */
-    if (toconv > 45)
-	toconv  = 45;
+    if (toconv > 180)
+	toconv  = 180;
     if (toconv * 2 >= written) {
         xmlBufferGrow(out, toconv);
 	written = out->size - out->use - 1;
diff --git a/result/valid/UTF16Entity.xml b/result/valid/UTF16Entity.xml
new file mode 100644
index 0000000..63cbba2
--- /dev/null
+++ b/result/valid/UTF16Entity.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<!DOCTYPE foo [
+<!ELEMENT foo (root)*>
+<!ELEMENT root EMPTY>
+<!ENTITY utf16b SYSTEM "dtds/utf16b.ent">
+<!ENTITY utf16l SYSTEM "dtds/utf16l.ent">
+]>
+<foo> &utf16b; &utf16l; </foo>
diff --git a/result/valid/UTF16Entity.xml.err b/result/valid/UTF16Entity.xml.err
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/result/valid/UTF16Entity.xml.err
diff --git a/test/valid/UTF16Entity.xml b/test/valid/UTF16Entity.xml
new file mode 100644
index 0000000..8bb29ac
--- /dev/null
+++ b/test/valid/UTF16Entity.xml
@@ -0,0 +1,8 @@
+<!DOCTYPE foo [
+<!ELEMENT foo (root*)>
+<!ELEMENT root EMPTY>
+<!ENTITY utf16b SYSTEM "dtds/utf16b.ent">
+<!ENTITY utf16l SYSTEM "dtds/utf16l.ent">
+]>
+
+<foo> &utf16b; &utf16l; </foo>
diff --git a/test/valid/dtds/utf16b.ent b/test/valid/dtds/utf16b.ent
new file mode 100644
index 0000000..52c7e2d
--- /dev/null
+++ b/test/valid/dtds/utf16b.ent
Binary files differ
diff --git a/test/valid/dtds/utf16l.ent b/test/valid/dtds/utf16l.ent
new file mode 100644
index 0000000..2cad40a
--- /dev/null
+++ b/test/valid/dtds/utf16l.ent
Binary files differ