Author: miguel
Date: 2005-09-27 14:46:53 -0400 (Tue, 27 Sep 2005)
New Revision: 50883

Modified:
   branches/mono-1-1-9/mcs/class/System.XML/System.Xml/XmlTextReader.cs
   
branches/mono-1-1-9/mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs
Log:
Backport

Modified: branches/mono-1-1-9/mcs/class/System.XML/System.Xml/XmlTextReader.cs
===================================================================
--- branches/mono-1-1-9/mcs/class/System.XML/System.Xml/XmlTextReader.cs        
2005-09-27 18:40:17 UTC (rev 50882)
+++ branches/mono-1-1-9/mcs/class/System.XML/System.Xml/XmlTextReader.cs        
2005-09-27 18:46:53 UTC (rev 50883)
@@ -1420,10 +1420,10 @@
 
                private void AppendSurrogatePairNameChar (int ch)
                {
-                       nameBuffer [nameLength++] = (char) (ch / 0x10000 + 
0xD800 - 1);
+                       nameBuffer [nameLength++] = (char) ((ch - 0x10000) / 
0x400 + 0xD800);
                        if (nameLength == nameCapacity)
                                ExpandNameCapacity ();
-                       nameBuffer [nameLength++] = (char) (ch % 0x10000 + 
0xDC00);
+                       nameBuffer [nameLength++] = (char) ((ch - 0x10000) % 
0x400 + 0xDC00);
                }
 
                private void ExpandNameCapacity ()
@@ -1444,8 +1444,8 @@
 
                private void AppendSurrogatePairValueChar (int ch)
                {
-                       valueBuffer.Append ((char) (ch / 0x10000 + 0xD800 - 1));
-                       valueBuffer.Append ((char) (ch % 0x10000 + 0xDC00));
+                       valueBuffer.Append ((char) ((ch - 0x10000) / 0x400 + 
0xD800));
+                       valueBuffer.Append ((char) ((ch - 0x10000) % 0x400 + 
0xDC00));
                }
 
                private string CreateValueString ()
@@ -1467,10 +1467,10 @@
                        if (ch < Char.MaxValue)
                                currentTagBuffer [currentTagLength++] = (char) 
ch;
                        else {
-                               currentTagBuffer [currentTagLength++] = (char) 
(ch / 0x10000 + 0xD800 - 1);
+                               currentTagBuffer [currentTagLength++] = (char) 
((ch - 0x10000) / 0x400 + 0xD800);
                                if (currentTagLength == currentTagCapacity)
                                        ExpandCurrentTagCapacity ();
-                               currentTagBuffer [currentTagLength++] = (char) 
(ch % 0x10000 + 0xDC00);
+                               currentTagBuffer [currentTagLength++] = (char) 
((ch - 0x10000) % 0x400 + 0xDC00);
                        }
                }
 
@@ -2669,8 +2669,8 @@
                                        if (c < Char.MaxValue)
                                                buffer [bufIndex++] = (char) c;
                                        else {
-                                               buffer [bufIndex++] = (char) (c 
/ 0x10000 + 0xD800 - 1);
-                                               buffer [bufIndex++] = (char) (c 
% 0x10000 + 0xDC00);
+                                               buffer [bufIndex++] = (char) 
((c - 0x10000) / 0x400 + 0xD800);
+                                               buffer [bufIndex++] = (char) 
((c - 0x10000) % 0x400 + 0xDC00);
                                        }
                                        break;
                                }

Modified: 
branches/mono-1-1-9/mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs
===================================================================
--- 
branches/mono-1-1-9/mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs  
    2005-09-27 18:40:17 UTC (rev 50882)
+++ 
branches/mono-1-1-9/mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs  
    2005-09-27 18:46:53 UTC (rev 50883)
@@ -1115,5 +1115,20 @@
                                XmlNodeType.Document, null);
                        xtr.Read ();
                }
+
+               [Test] // bug #76247
+               public void SurrogateRoundtrip ()
+               {
+                       byte [] data = new byte [] {0x3c, 0x61, 0x3e, 0xf0,
+                               0xa8, 0xa7, 0x80, 0x3c, 0x2f, 0x61, 0x3e};
+                       XmlTextReader xtr = new XmlTextReader (
+                               new MemoryStream (data));
+                       xtr.Read ();
+                       string line = xtr.ReadString ();
+                       int [] arr = new int [line.Length];
+                       for (int i = 0; i < line.Length; i++)
+                               arr [i] = (int) line [i];
+                       AssertEquals (new int [] {0xd862, 0xddc0}, arr);
+               }
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to