You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mi...@apache.org on 2003/08/13 07:53:41 UTC
cvs commit: xml-xalan/java/src/org/apache/xml/serializer ToHTMLStream.java ToStream.java ToTextStream.java
minchau 2003/08/12 22:53:41
Modified: java/src/org/apache/xml/serializer ToHTMLStream.java
ToStream.java ToTextStream.java
Log:
PR: bugzilla 18907
Submitted by: Brian MinchauPatch has just been applied to main branch of CVS.
Now ToStream.writeUTF16Surrogate(char c, char ch[], int i, int end)
return nothing rather than the "i+1" that it had always returned,
which was a bit confusing.
This routine always processed 2 input characters and always returned "i+1" so why bother?
There was no error in returning "i+1" because the situation in which this routine was called were always in a loop:
for (int i=start; i < end; i++) { ... }
so "i" was always incremented before going on to the next iteration. Any i++; after calling writeUTF16Surrogate() now means that 2 input characters have been processed, so there is no bug here (never was). The code is just clearer now.
A bug has been fixed in ToStream.accumDefaultEscape() which used to mis-count how many input characters that it processed.
Revision Changes Path
1.23 +4 -2 xml-xalan/java/src/org/apache/xml/serializer/ToHTMLStream.java
Index: ToHTMLStream.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToHTMLStream.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- ToHTMLStream.java 1 Aug 2003 01:03:06 -0000 1.22
+++ ToHTMLStream.java 13 Aug 2003 05:53:41 -0000 1.23
@@ -1336,8 +1336,10 @@
if (isUTF16Surrogate(ch))
{
- i = writeUTF16Surrogate(ch, chars, i, end);
-
+ writeUTF16Surrogate(ch, chars, i, end);
+ i++; // two input characters processed
+ // this increments by one and the for()
+ // loop itself increments by another one.
}
// The next is kind of a hack to keep from escaping in the case
1.21 +12 -15 xml-xalan/java/src/org/apache/xml/serializer/ToStream.java
Index: ToStream.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToStream.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- ToStream.java 12 Aug 2003 19:59:42 -0000 1.20
+++ ToStream.java 13 Aug 2003 05:53:41 -0000 1.21
@@ -979,26 +979,23 @@
}
/**
- * Once a surrogate has been detected, write the pair as a single
- * character reference.
+ * Once a surrogate has been detected, write out the pair of
+ * characters as a single character reference.
*
* @param c the first part of the surrogate.
* @param ch Character array.
* @param i position Where the surrogate was detected.
* @param end The end index of the significant characters.
- * @return i+1.
* @throws IOException
* @throws org.xml.sax.SAXException if invalid UTF-16 surrogate detected.
*/
- protected int writeUTF16Surrogate(char c, char ch[], int i, int end)
+ protected void writeUTF16Surrogate(char c, char ch[], int i, int end)
throws IOException
{
// UTF-16 surrogate
int surrogateValue = getURF16SurrogateValue(c, ch, i, end);
- i++;
-
final java.io.Writer writer = m_writer;
writer.write('&');
writer.write('#');
@@ -1006,8 +1003,6 @@
// writer.write('x');
writer.write(Integer.toString(surrogateValue));
writer.write(';');
-
- return i;
}
/**
@@ -1018,7 +1013,7 @@
* @param ch Character array.
* @param i position Where the surrogate was detected.
* @param end The end index of the significant characters.
- * @return i+1.
+ * @return the integer value of the UTF-16 surrogate.
* @throws org.xml.sax.SAXException if invalid UTF-16 surrogate detected.
*/
int getURF16SurrogateValue(char c, char ch[], int i, int end)
@@ -1149,7 +1144,8 @@
// This needs to go into a function...
if (isUTF16Surrogate(c))
{
- i = writeUTF16Surrogate(c, ch, i, end);
+ writeUTF16Surrogate(c, ch, i, end);
+ i++ ; // process two input characters
}
else
{
@@ -1196,7 +1192,8 @@
{
if (m_cdataTagOpen)
closeCDATA();
- i = writeUTF16Surrogate(c, ch, i, end);
+ writeUTF16Surrogate(c, ch, i, end);
+ i++; // process two input characters
}
else
{
@@ -1621,7 +1618,8 @@
* @param len length of chars.
* @param escLF true if the linefeed should be escaped.
*
- * @return i+1 if the character was written, else i.
+ * @return i+1 if a character was written, i+2 if two characters
+ * were written out, else return i.
*
* @throws org.xml.sax.SAXException
*/
@@ -1639,8 +1637,6 @@
if (i == pos)
{
- pos++;
-
if (0xd800 <= ch && ch < 0xdc00)
{
@@ -1679,7 +1675,7 @@
writer.write("&#");
writer.write(Integer.toString(next));
writer.write(';');
-
+ pos += 2; // count the two characters that went into writing out this entity
/*} else if (null != ctbc && !ctbc.canConvert(ch)) {
sb.append("&#x");
sb.append(Integer.toString((int)ch, 16));
@@ -1697,6 +1693,7 @@
{
writer.write(ch);
}
+ pos++; // count the single character that was processed
}
}
1.11 +9 -3 xml-xalan/java/src/org/apache/xml/serializer/ToTextStream.java
Index: ToTextStream.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToTextStream.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ToTextStream.java 7 Jul 2003 06:23:51 -0000 1.10
+++ ToTextStream.java 13 Aug 2003 05:53:41 -0000 1.11
@@ -300,6 +300,9 @@
if (isCData)
{
+ // This for() loop always increments i by one at the end
+ // of the loop. Additional increments of i adjust for when
+ // two input characters are processed.
for (int i = start; i < end; i++)
{
final char c = ch[i];
@@ -316,7 +319,8 @@
// This needs to go into a function...
if (isUTF16Surrogate(c))
{
- i = writeUTF16Surrogate(c, ch, i, end);
+ writeUTF16Surrogate(c, ch, i, end);
+ i++; // two input characters processed
}
else
{
@@ -347,7 +351,8 @@
else if (isUTF16Surrogate(c))
{
- i = writeUTF16Surrogate(c, ch, i, end);
+ writeUTF16Surrogate(c, ch, i, end);
+ i++; // two input characters processed
}
else
{
@@ -373,7 +378,8 @@
}
else if (isUTF16Surrogate(c))
{
- i = writeUTF16Surrogate(c, ch, i, end);
+ writeUTF16Surrogate(c, ch, i, end);
+ i++; // two input characters processed
}
else
{
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org