You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by yt...@apache.org on 2005/03/17 00:24:47 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler Text.java

ytalwar     2005/03/16 15:24:47

  Modified:    java/src/org/apache/xalan/xsltc/compiler Text.java
  Log:
  This is a fix for XALANJ-2081.
  In class org.apache.xalan.xsltc.compiler.Text, a check was being done to find out if a given text string is all whitespaces.
  In case, a given text string is all whitespace, a call to serializer is not made.
  The code was using trim() method from java.lang.String.  trim() method trimmed characters as whitespaces 
  that are not considered as whitespace in XML.
  
  The code logic is changed to check if a given string is all whitespace accoding to XML specifications.
  
  I would like to thank Michael Glavassevich and Brian Minchau for their input to resolve this issue.
  
  Revision  Changes    Path
  1.18      +28 -4     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Text.java
  
  Index: Text.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Text.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Text.java	16 Feb 2004 22:25:10 -0000	1.17
  +++ Text.java	16 Mar 2005 23:24:47 -0000	1.18
  @@ -103,10 +103,29 @@
   	    LiteralElement element = (LiteralElement)getParent();
   	    String space = element.getAttribute("xml:space");
   	    if ((space == null) || (!space.equals("preserve")))
  -		if (_text.trim().length() == 0) _ignore = true;
  +        {
  +            int i;
  +            final int textLength = _text.length();
  +            for (i = 0; i < textLength; i++) {
  +                char c = _text.charAt(i);
  +                if (!isWhitespace(c))
  +                    break;
  +            }
  +            if (i == textLength)
  +                _ignore = true;
  +        }
   	}
   	else {
  -	    if (_text.trim().length() == 0) _ignore = true;
  +        int i;
  +        final int textLength = _text.length();
  +        for (i = 0; i < textLength; i++) 
  +        {
  +            char c = _text.charAt(i);
  +            if (!isWhitespace(c))
  +                break;
  +        }
  +        if (i == textLength)
  +            _ignore = true;
   	}
       }
   
  @@ -125,7 +144,12 @@
       protected boolean contextDependent() {
   	return false;
       }
  -
  + 
  +    private static boolean isWhitespace(char c)
  +    {
  +    	return (c == 0x20 || c == 0x09 || c == 0x0A || c == 0x0D);
  +    }
  + 
       public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
   	final ConstantPoolGen cpg = classGen.getConstantPool();
   	final InstructionList il = methodGen.getInstructionList();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org