You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@apache.org on 2001/05/19 09:06:01 UTC

cvs commit: xml-xalan/java/src/org/apache/xpath/objects XNodeSet.java XObject.java XRTreeFrag.java XString.java XStringForChars.java XStringForFSB.java

sboag       01/05/19 00:06:01

  Modified:    java/src/org/apache/xalan/templates Tag: DTM_EXP
                        AVTPartXPath.java ElemValueOf.java
               java/src/org/apache/xalan/xslt Tag: DTM_EXP Process.java
               java/src/org/apache/xml/dtm Tag: DTM_EXP
                        DTMManagerDefault.java
               java/src/org/apache/xml/utils Tag: DTM_EXP XMLString.java
               java/src/org/apache/xpath Tag: DTM_EXP XPath.java
               java/src/org/apache/xpath/axes Tag: DTM_EXP AxesWalker.java
                        FollowingWalker.java
               java/src/org/apache/xpath/functions Tag: DTM_EXP
                        FuncStartsWith.java FuncSum.java
                        FunctionDef1Arg.java
               java/src/org/apache/xpath/objects Tag: DTM_EXP XNodeSet.java
                        XObject.java XRTreeFrag.java XString.java
                        XStringForChars.java XStringForFSB.java
  Log:
  Various tweaks for XMLStrings.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.12.2.2  +1 -1      xml-xalan/java/src/org/apache/xalan/templates/AVTPartXPath.java
  
  Index: AVTPartXPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/AVTPartXPath.java,v
  retrieving revision 1.12.2.1
  retrieving revision 1.12.2.2
  diff -u -r1.12.2.1 -r1.12.2.2
  --- AVTPartXPath.java	2001/04/10 18:44:45	1.12.2.1
  +++ AVTPartXPath.java	2001/05/19 07:05:43	1.12.2.2
  @@ -159,7 +159,7 @@
   
       if (null != xobj)
       {
  -      buf.append(xobj.str());
  +      xobj.appendToFsb(buf);
       }
     }
   }
  
  
  
  1.13.2.3  +9 -6      xml-xalan/java/src/org/apache/xalan/templates/ElemValueOf.java
  
  Index: ElemValueOf.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemValueOf.java,v
  retrieving revision 1.13.2.2
  retrieving revision 1.13.2.3
  diff -u -r1.13.2.2 -r1.13.2.3
  --- ElemValueOf.java	2001/05/16 05:32:55	1.13.2.2
  +++ ElemValueOf.java	2001/05/19 07:05:43	1.13.2.3
  @@ -67,11 +67,13 @@
   import org.apache.xpath.objects.XObject;
   import org.apache.xpath.objects.XNodeSet;
   import org.apache.xalan.trace.SelectionEvent;
  -import org.apache.xml.utils.QName;
   import org.apache.xalan.res.XSLTErrorResources;
   import org.apache.xalan.transformer.TransformerImpl;
   import org.apache.xalan.transformer.ResultTreeHandler;
   
  +import org.apache.xml.utils.QName;
  +import org.apache.xml.utils.XMLString;
  +
   import javax.xml.transform.TransformerException;
   
   /**
  @@ -266,7 +268,7 @@
                                                             "select", m_selectExpression, value);
         }
            
  -      String s;                                                                                             
  +      XMLString s;                                                                                             
         if(DTM.NULL != child)
         {
           DTM dtm = xctxt.getDTM(child);
  @@ -282,8 +284,9 @@
           return;
         }
         else
  -        s = value.str();
  -
  +      {
  +        s = value.xstr();
  +      }
         
         int len = (null != s) ? s.length() : 0;
         if(len > 0)
  @@ -293,11 +296,11 @@
           if (m_disableOutputEscaping)
           {
             rth.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
  -          rth.characters(s.toCharArray(), 0, len);
  +          s.dispatchCharactersEvents(rth);
             rth.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
           }
           else
  -          rth.characters(s.toCharArray(), 0, len);
  +          s.dispatchCharactersEvents(rth);
         }
       }
       catch(SAXException se)
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.32.2.2  +6 -0      xml-xalan/java/src/org/apache/xalan/xslt/Process.java
  
  Index: Process.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xslt/Process.java,v
  retrieving revision 1.32.2.1
  retrieving revision 1.32.2.2
  diff -u -r1.32.2.1 -r1.32.2.2
  --- Process.java	2001/05/16 15:14:15	1.32.2.1
  +++ Process.java	2001/05/19 07:05:45	1.32.2.2
  @@ -567,7 +567,9 @@
             }
             else
             {
  +            System.out.println("Calling newTemplates: "+xslFileName);
               stylesheet = tfactory.newTemplates(new StreamSource(xslFileName));
  +            System.out.println("Done calling newTemplates: "+xslFileName);
             }
           }
   
  @@ -826,8 +828,12 @@
                   transformer.transform(new StreamSource(inFileName), result);
                 }
                 else
  +              {
  +                System.out.println("Starting transform");
                   transformer.transform(new StreamSource(inFileName),
                                         strResult);
  +                System.out.println("Done with transform");
  +              }
               }
             }
             else
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.18  +7 -6      xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManagerDefault.java
  
  Index: DTMManagerDefault.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManagerDefault.java,v
  retrieving revision 1.1.2.17
  retrieving revision 1.1.2.18
  diff -u -r1.1.2.17 -r1.1.2.18
  --- DTMManagerDefault.java	2001/05/18 21:01:21	1.1.2.17
  +++ DTMManagerDefault.java	2001/05/19 07:05:47	1.1.2.18
  @@ -108,6 +108,9 @@
   
     /** Set this to true if you want a dump of the DTM after creation. */
     private static final boolean DUMPTREE = false;
  +  
  +  /** Set this to true if you want a basic diagnostics. */
  +  private static final boolean DEBUG = false;
   
     /**
      * Get an instance of a DTM, loaded with the content from the
  @@ -131,7 +134,8 @@
     public DTM getDTM(Source source, boolean unique,
                       DTMWSFilter whiteSpaceFilter, boolean incremental)
     {
  -
  +    if(DEBUG && null != source)
  +      System.out.println("Starting source: "+source.getSystemId());
       XMLStringFactory xstringFactory = m_xsf;
       int documentID = m_dtms.size() << 20;
   
  @@ -144,7 +148,6 @@
   
         if (DUMPTREE)
         {
  -        System.out.println("Dumping DOM2DTM");
           dtm.dumpDTM();
         }
   
  @@ -200,8 +203,8 @@
           m_dtms.add(dtm);
   
           boolean haveXercesParser =
  -          null != reader
  -          && reader instanceof org.apache.xerces.parsers.SAXParser;
  +          (null != reader)
  +          && (reader instanceof org.apache.xerces.parsers.SAXParser);
   
           if (haveXercesParser)
             incremental = true;  // No matter what.  %REVIEW%
  @@ -220,7 +223,6 @@
   
             if (haveXercesParser)
             {
  -
               // CoroutineSAXParser_Xerces to avoid threading.
               // System.out.println("Using CoroutineSAXParser_Xerces to avoid threading");
               coParser = new CoroutineSAXParser_Xerces(
  @@ -229,7 +231,6 @@
             }
             else
             {
  -
               // Create a CoroutineSAXParser that will run on the secondary thread.
               if (null == reader)
                 coParser = new CoroutineSAXParser(coroutineManager,
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +54 -0     xml-xalan/java/src/org/apache/xml/utils/Attic/XMLString.java
  
  Index: XMLString.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/Attic/XMLString.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- XMLString.java	2001/05/18 07:16:55	1.1.2.1
  +++ XMLString.java	2001/05/19 07:05:48	1.1.2.2
  @@ -262,6 +262,27 @@
     public abstract boolean startsWith(String prefix, int toffset);
   
     /**
  +   * Tests if this string starts with the specified prefix beginning
  +   * a specified index.
  +   *
  +   * @param   prefix    the prefix.
  +   * @param   toffset   where to begin looking in the string.
  +   * @return  <code>true</code> if the character sequence represented by the
  +   *          argument is a prefix of the substring of this object starting
  +   *          at index <code>toffset</code>; <code>false</code> otherwise.
  +   *          The result is <code>false</code> if <code>toffset</code> is
  +   *          negative or greater than the length of this
  +   *          <code>String</code> object; otherwise the result is the same
  +   *          as the result of the expression
  +   *          <pre>
  +   *          this.subString(toffset).startsWith(prefix)
  +   *          </pre>
  +   * @exception java.lang.NullPointerException if <code>prefix</code> is
  +   *          <code>null</code>.
  +   */
  +  public abstract boolean startsWith(XMLString prefix, int toffset);
  +
  +  /**
      * Tests if this string starts with the specified prefix.
      *
      * @param   prefix   the prefix.
  @@ -279,6 +300,23 @@
     public abstract boolean startsWith(String prefix);
   
     /**
  +   * Tests if this string starts with the specified prefix.
  +   *
  +   * @param   prefix   the prefix.
  +   * @return  <code>true</code> if the character sequence represented by the
  +   *          argument is a prefix of the character sequence represented by
  +   *          this string; <code>false</code> otherwise.
  +   *          Note also that <code>true</code> will be returned if the
  +   *          argument is an empty string or is equal to this
  +   *          <code>String</code> object as determined by the
  +   *          {@link #equals(Object)} method.
  +   * @exception java.lang.NullPointerException if <code>prefix</code> is
  +   *          <code>null</code>.
  +   * @since   JDK1. 0
  +   */
  +  public abstract boolean startsWith(XMLString prefix);
  +
  +  /**
      * Tests if this string ends with the specified suffix.
      *
      * @param   suffix   the suffix.
  @@ -654,4 +692,20 @@
      * @return  the string itself.
      */
     public abstract String toString();
  +  
  +  /**
  +   * Tell if this object contains a java String object.
  +   * 
  +   * @return true if this XMLString can return a string without creating one.
  +   */
  +  public abstract boolean hasString();
  +  
  +  /**
  +   * Convert a string to a double -- Allowed input is in fixed
  +   * notation ddd.fff.
  +   *
  +   * @return A double value representation of the string, or return Double.NaN 
  +   * if the string can not be converted.
  +   */
  +  public double toDouble();
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.18.2.3  +1 -1      xml-xalan/java/src/org/apache/xpath/XPath.java
  
  Index: XPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPath.java,v
  retrieving revision 1.18.2.2
  retrieving revision 1.18.2.3
  diff -u -r1.18.2.2 -r1.18.2.3
  --- XPath.java	2001/05/17 05:38:47	1.18.2.2
  +++ XPath.java	2001/05/19 07:05:49	1.18.2.3
  @@ -313,7 +313,7 @@
         {
           e = ((org.apache.xml.utils.WrappedRuntimeException) e).getException();
         }
  -
  +      e.printStackTrace();
   
         String msg = e.getMessage();
         msg = (msg == null || msg.length()== 0)? "Unknown error in XPath" : msg;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.18.2.5  +1 -1      xml-xalan/java/src/org/apache/xpath/axes/AxesWalker.java
  
  Index: AxesWalker.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/AxesWalker.java,v
  retrieving revision 1.18.2.4
  retrieving revision 1.18.2.5
  diff -u -r1.18.2.4 -r1.18.2.5
  --- AxesWalker.java	2001/05/18 07:17:04	1.18.2.4
  +++ AxesWalker.java	2001/05/19 07:05:51	1.18.2.5
  @@ -1212,7 +1212,7 @@
       // different document. 
       while (
         (DTM.NULL != nextNode) && (DTM.NULL != m_prevReturned)
  -      && getDTM(nextNode).getOwnerDocument(nextNode) == getDTM(m_prevReturned).getOwnerDocument(m_prevReturned)
  +      && getDTM(nextNode).getDocument() == getDTM(m_prevReturned).getDocument()
         && getDTM(nextNode).isNodeAfter(nextNode, m_prevReturned));
   
       m_prevReturned = nextNode;
  
  
  
  1.6.2.3   +1 -1      xml-xalan/java/src/org/apache/xpath/axes/FollowingWalker.java
  
  Index: FollowingWalker.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/FollowingWalker.java,v
  retrieving revision 1.6.2.2
  retrieving revision 1.6.2.3
  diff -u -r1.6.2.2 -r1.6.2.3
  --- FollowingWalker.java	2001/05/06 02:09:50	1.6.2.2
  +++ FollowingWalker.java	2001/05/19 07:05:51	1.6.2.3
  @@ -111,7 +111,7 @@
         */
         int e = dtm.getParent(root);
         m_currentNode = e;
  -      m_currentAncestor = dtm.getOwnerDocument(root); // Not totally sure why
  +      m_currentAncestor = dtm.getDocument(); // Not totally sure why
       } 
       else
         m_currentAncestor = root;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.3.2.2   +1 -1      xml-xalan/java/src/org/apache/xpath/functions/FuncStartsWith.java
  
  Index: FuncStartsWith.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncStartsWith.java,v
  retrieving revision 1.3.2.1
  retrieving revision 1.3.2.2
  diff -u -r1.3.2.1 -r1.3.2.2
  --- FuncStartsWith.java	2001/04/10 18:45:32	1.3.2.1
  +++ FuncStartsWith.java	2001/05/19 07:05:53	1.3.2.2
  @@ -82,7 +82,7 @@
      */
     public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
     {
  -    return m_arg0.execute(xctxt).str().startsWith(m_arg1.execute(xctxt).str())
  +    return m_arg0.execute(xctxt).xstr().startsWith(m_arg1.execute(xctxt).xstr())
              ? XBoolean.S_TRUE : XBoolean.S_FALSE;
     }
   }
  
  
  
  1.4.2.3   +1 -1      xml-xalan/java/src/org/apache/xpath/functions/FuncSum.java
  
  Index: FuncSum.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncSum.java,v
  retrieving revision 1.4.2.2
  retrieving revision 1.4.2.3
  diff -u -r1.4.2.2 -r1.4.2.3
  --- FuncSum.java	2001/05/18 07:17:09	1.4.2.2
  +++ FuncSum.java	2001/05/19 07:05:54	1.4.2.3
  @@ -98,7 +98,7 @@
         XMLString s = dtm.getStringValue(pos);
   
         if (null != s)
  -        sum += XString.castToNum(s);
  +        sum += s.toDouble();
       }
       // nodes.detach();
   
  
  
  
  1.5.2.4   +1 -1      xml-xalan/java/src/org/apache/xpath/functions/FunctionDef1Arg.java
  
  Index: FunctionDef1Arg.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FunctionDef1Arg.java,v
  retrieving revision 1.5.2.3
  retrieving revision 1.5.2.4
  diff -u -r1.5.2.3 -r1.5.2.4
  --- FunctionDef1Arg.java	2001/05/18 07:17:09	1.5.2.3
  +++ FunctionDef1Arg.java	2001/05/19 07:05:54	1.5.2.4
  @@ -154,7 +154,7 @@
         {
           DTM dtm = xctxt.getDTM(currentNode);
           XMLString str = dtm.getStringValue(currentNode);
  -        return XString.castToNum(str);
  +        return str.toDouble();
         }
         
       }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.5  +20 -35    xml-xalan/java/src/org/apache/xpath/objects/XNodeSet.java
  
  Index: XNodeSet.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XNodeSet.java,v
  retrieving revision 1.10.2.4
  retrieving revision 1.10.2.5
  diff -u -r1.10.2.4 -r1.10.2.5
  --- XNodeSet.java	2001/05/18 07:17:19	1.10.2.4
  +++ XNodeSet.java	2001/05/19 07:05:57	1.10.2.5
  @@ -154,7 +154,7 @@
      */
     public double getNumberFromNode(int n)
     {
  -    return XString.castToNum(getStringFromNode(n));
  +    return m_dtmMgr.getDTM(n).getStringValue(n).toDouble();
     }
   
     /**
  @@ -215,6 +215,17 @@
   
       return (node != DTM.NULL) ? getStringFromNode(node) : XString.EMPTYSTRING;
     }
  +  
  +  /**
  +   * Cast result object to a string.
  +   *
  +   * @return The string this wraps or the empty string if null
  +   */
  +  public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb)
  +  {
  +    XString xstring = (XString)xstr();
  +    xstring.appendToFsb(fsb);
  +  }
   
   
     /**
  @@ -446,45 +457,19 @@
       }
       else if (XObject.CLASS_RTREEFRAG == type)
       {
  -
  -      // hmmm... 
  -      // Try first to treat it as a number, so that numeric 
  -      // comparisons can be done with it.  I suspect this is bogus...
  -      double num2 = obj2.num();
  -
  -      if (!Double.isNaN(num2))
  -      {
  -        DTMIterator list1 = nodeset();
  -        int node;
  -
  -        while (DTM.NULL != (node = list1.nextNode()))
  -        {
  -          double num1 = getNumberFromNode(node);
  -
  -          if (comparator.compareNumbers(num1, num2))
  -          {
  -            result = true;
  +      XMLString s2 = obj2.xstr();
  +      DTMIterator list1 = nodeset();
  +      int node;
   
  -            break;
  -          }
  -        }
  -      }
  -      else
  +      while (DTM.NULL != (node = list1.nextNode()))
         {
  -        XMLString s2 = obj2.xstr();
  -        DTMIterator list1 = nodeset();
  -        int node;
  +        XMLString s1 = getStringFromNode(node);
   
  -        while (DTM.NULL != (node = list1.nextNode()))
  +        if (comparator.compareStrings(s1, s2))
           {
  -          XMLString s1 = getStringFromNode(node);
  -
  -          if (comparator.compareStrings(s1, s2))
  -          {
  -            result = true;
  +          result = true;
   
  -            break;
  -          }
  +          break;
           }
         }
       }
  
  
  
  1.8.2.5   +11 -0     xml-xalan/java/src/org/apache/xpath/objects/XObject.java
  
  Index: XObject.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XObject.java,v
  retrieving revision 1.8.2.4
  retrieving revision 1.8.2.5
  diff -u -r1.8.2.4 -r1.8.2.5
  --- XObject.java	2001/05/18 07:17:20	1.8.2.4
  +++ XObject.java	2001/05/19 07:05:57	1.8.2.5
  @@ -578,4 +578,15 @@
         throw new XPathException(fmsg);
       }
     }
  +  
  +  /**
  +   * Cast result object to a string.
  +   *
  +   * @return The string this wraps or the empty string if null
  +   */
  +  public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb)
  +  {
  +    fsb.append(str());
  +  }
  +
   }
  
  
  
  1.13.2.4  +22 -30    xml-xalan/java/src/org/apache/xpath/objects/XRTreeFrag.java
  
  Index: XRTreeFrag.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XRTreeFrag.java,v
  retrieving revision 1.13.2.3
  retrieving revision 1.13.2.4
  diff -u -r1.13.2.3 -r1.13.2.4
  --- XRTreeFrag.java	2001/05/18 07:17:21	1.13.2.3
  +++ XRTreeFrag.java	2001/05/19 07:05:57	1.13.2.4
  @@ -136,36 +136,11 @@
     public double num()
     {
   
  -//    java.text.NumberFormat m_formatter =
  -//      java.text.NumberFormat.getNumberInstance();
       double result;
       
       XMLString s = m_dtm.getStringValue(m_dtmRoot);
   
  -    if (null != s)
  -    {
  -//      try
  -//      {
  -
  -        // result = Double.valueOf(s).doubleValue();
  -//        Number n = m_formatter.parse(s.trim());
  -//
  -//        result = n.doubleValue();
  -          result = XString.castToNum(s.trim());
  -//      }
  -//
  -//      // catch(NumberFormatException nfe)
  -//      catch (java.text.ParseException nfe)
  -//      {
  -//        result = Double.NaN;
  -//      }
  -    }
  -    else
  -    {
  -      result = Double.NaN;
  -    }
  -
  -    return result;
  +    return s.toDouble();
     }
   
     /**
  @@ -179,16 +154,33 @@
       return true;
     }
     
  +  private XMLString m_xmlStr = null;
  +  
     /**
      * Cast result object to an XMLString.
      *
      * @return The document fragment node data or the empty string. 
      */
     public XMLString xstr()
  +  {
  +    if(null == m_xmlStr)
  +      m_xmlStr = m_dtm.getStringValue(m_dtmRoot);
  +    
  +    return m_xmlStr;
  +  }
  +  
  +  /**
  +   * Cast result object to a string.
  +   *
  +   * @return The string this wraps or the empty string if null
  +   */
  +  public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb)
     {
  -    return m_dtm.getStringValue(m_dtmRoot);
  +    XString xstring = (XString)xstr();
  +    xstring.appendToFsb(fsb);
     }
   
  +
     /**
      * Cast result object to a string.
      *
  @@ -268,17 +260,17 @@
         }
         else if (XObject.CLASS_NODESET == obj2.getType())
         {
  -        return str().equals(obj2.str());
  +        return xstr().equals(obj2.xstr());
         }
         else if (XObject.CLASS_STRING == obj2.getType())
         {
  -        return str().equals(obj2.str());
  +        return xstr().equals(obj2.xstr());
         }
         else if (XObject.CLASS_RTREEFRAG == obj2.getType())
         {
     
           // Probably not so good.  Think about this.
  -        return str().equals(obj2.str());
  +        return xstr().equals(obj2.xstr());
         }
         else
         {
  
  
  
  1.6.2.4   +226 -87   xml-xalan/java/src/org/apache/xpath/objects/XString.java
  
  Index: XString.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XString.java,v
  retrieving revision 1.6.2.3
  retrieving revision 1.6.2.4
  diff -u -r1.6.2.3 -r1.6.2.4
  --- XString.java	2001/05/18 07:17:22	1.6.2.3
  +++ XString.java	2001/05/19 07:05:58	1.6.2.4
  @@ -78,7 +78,7 @@
   
     /** Empty string XString object */
     public static XString EMPTYSTRING = new XString("");
  -  
  +
     /**
      * Construct a XString object.  This constructor exists for derived classes.
      *
  @@ -121,87 +121,124 @@
     }
   
     /**
  -   * Cast a string to a number.
  +   * Tell if this object contains a java String object.
      *
  -   * @param s The string to convert
  +   * @return true if this XMLString can return a string without creating one.
  +   */
  +  public boolean hasString()
  +  {
  +    return true;
  +  }
  +
  +  /**
  +   * Cast result object to a number.
      *
  -   * @return 0.0 if the string is null, numeric value of the string
  +   * @return 0.0 if this string is null, numeric value of this string
      * or NaN
      */
  -  public static double castToNum(XMLString s)
  +  public double num()
     {
  -    // %OPT% For now...
  -    return castToNum(s.toString());
  +    return toDouble();
     }
  -  
  +
     /**
  -   * Cast a string to a number.
  +   * Convert a string to a double -- Allowed input is in fixed
  +   * notation ddd.fff.
      *
  -   * @param s The string to convert
  -   *
  -   * @return 0.0 if the string is null, numeric value of the string
  -   * or NaN
  +   * @return A double value representation of the string, or return Double.NaN
  +   * if the string can not be converted.
      */
  -  public static double castToNum(String s)
  +  public double toDouble()
     {
  +    int end = length();
  +    
  +    if(0 == end)
  +      return Double.NaN;
   
  -    double result;
  +    double result = 0.0;
  +    int start = 0;
  +    int punctPos = end-1;
   
  -    if (null == s)
  -      result = 0.0;
  -    else
  +    // Scan to first whitespace character.
  +    for (int i = start; i < end; i++)
       {
  -      try
  +      char c = charAt(i);
  +
  +      if (!Character.isSpaceChar(c))
         {
  +        break;
  +      }
  +      else
  +        start++;
  +    }
  +
  +    double sign = 1.0;
   
  -        /**
  -         * TODO: Adjust this for locale. Need to take into
  -         * account the lang parameter on the xsl:sort
  -         */
  -
  -        // It seems we can not use this as it just parses the 
  -        // start of the string until it finds a non-number char, 
  -        // which is not what we want according to the XSLT spec.  
  -        // Also, I *think* this is a local-specific
  -        // parse, which is also not what we want according to the 
  -        // XSLT spec (see below).
  -        // NumberFormat formatter = NumberFormat.getNumberInstance();
  -        // result = formatter.parse(s.trim()).doubleValue();
  -        // The dumb XSLT spec says: "The number function should 
  -        // not be used for conversion of numeric data occurring 
  -        // in an element in an XML document unless the element 
  -        // is of a type that represents numeric data in a 
  -        // language-neutral format (which would typically be 
  -        // transformed into a language-specific format for 
  -        // presentation to a user). In addition, the number 
  -        // function cannot be used unless the language-neutral 
  -        // format used by the element is consistent with the 
  -        // XPath syntax for a Number."
  -        // So I guess we need to check, if the default local 
  -        // is french, does Double.valueOf use the local specific 
  -        // parse?  Or does it use the ieee parse?
  -        result = Double.valueOf(s.trim()).doubleValue();
  +    if (start < end && charAt(start) == '-')
  +    {
  +      sign = -1.0;
  +
  +      start++;
  +    }
  +
  +    int digitsFound = 0;
  +
  +    for (int i = start; i < end; i++)  // parse the string from left to right converting the integer part
  +    {
  +      char c = charAt(i);
  +
  +      if (c != '.')
  +      {
  +        if (Character.isSpaceChar(c))
  +          break;
  +        else if (Character.isDigit(c))
  +        {
  +          result = result * 10.0 + (c - 0x30);
  +
  +          digitsFound++;
  +        }
  +        else
  +        {
  +          return Double.NaN;
  +        }
         }
  +      else
  +      {
  +        punctPos = i;
   
  -      // catch (ParseException e) 
  -      catch (NumberFormatException nfe)
  +        break;
  +      }
  +    }
  +
  +    if (charAt(punctPos) == '.')  // parse the string from the end to the '.' converting the fractional part
  +    {
  +      double fractPart = 0.0;
  +
  +      for (int i = end - 1; i > punctPos; i--)
         {
  -        result = Double.NaN;
  +        char c = charAt(i);
  +
  +        if (Character.isSpaceChar(c))
  +          break;
  +        else if (Character.isDigit(c))
  +        {
  +          fractPart = fractPart / 10.0 + (c - 0x30);
  +
  +          digitsFound++;
  +        }
  +        else
  +        {
  +          return Double.NaN;
  +        }
         }
  +
  +      result += fractPart / 10.0;
       }
   
  -    return result;
  -  }
  +    if (0 == digitsFound)
  +      return Double.NaN;
   
  -  /**
  -   * Cast result object to a number.
  -   *
  -   * @return 0.0 if this string is null, numeric value of this string
  -   * or NaN
  -   */
  -  public double num()
  -  {
  -    return castToNum(str());
  +    return result * sign;
     }
   
     /**
  @@ -214,7 +251,7 @@
     {
       return str().length() > 0;
     }
  -  
  +
     /**
      * Cast result object to a string.
      *
  @@ -251,7 +288,7 @@
   
       return frag.getDocument();
     }
  -  
  +
     /**
      * Directly call the
      * characters method on the passed ContentHandler for the
  @@ -264,12 +301,14 @@
      * @throws org.xml.sax.SAXException
      */
     public void dispatchCharactersEvents(org.xml.sax.ContentHandler ch)
  -      throws org.xml.sax.SAXException
  +          throws org.xml.sax.SAXException
     {
  +
       String str = str();
  +
       ch.characters(str.toCharArray(), 0, str.length());
     }
  -      
  +
     /**
      * Directly call the
      * comment method on the passed LexicalHandler for the
  @@ -280,12 +319,14 @@
      * @throws org.xml.sax.SAXException
      */
     public void dispatchAsComment(org.xml.sax.ext.LexicalHandler lh)
  -      throws org.xml.sax.SAXException
  +          throws org.xml.sax.SAXException
     {
  +
       String str = str();
  +
       lh.comment(str.toCharArray(), 0, str.length());
     }
  -  
  +
     /**
      * Returns the length of this string.
      *
  @@ -340,7 +381,7 @@
     {
       str().getChars(srcBegin, srcEnd, dst, dstBegin);
     }
  -  
  +
     /**
      * Tell if two objects are functionally equal.
      *
  @@ -361,7 +402,7 @@
   
       return str().equals(obj2.str());
     }
  -  
  +
     /**
      * Compares this string to the specified object.
      * The result is <code>true</code> if and only if the argument is not
  @@ -370,6 +411,8 @@
      *
      * @param   anObject   the object to compare this <code>String</code>
      *                     against.
  +   *
  +   * NEEDSDOC @param obj2
      * @return  <code>true</code> if the <code>String </code>are equal;
      *          <code>false</code> otherwise.
      * @see     java.lang.String#compareTo(java.lang.String)
  @@ -377,7 +420,11 @@
      */
     public boolean equals(XMLString obj2)
     {
  -    return str().equals(obj2.toString());
  +
  +    if (!obj2.hasString())
  +      return obj2.equals(this);
  +    else
  +      return str().equals(obj2.toString());
     }
   
     /**
  @@ -388,6 +435,8 @@
      *
      * @param   anObject   the object to compare this <code>String</code>
      *                     against.
  +   *
  +   * NEEDSDOC @param obj2
      * @return  <code>true</code> if the <code>String </code>are equal;
      *          <code>false</code> otherwise.
      * @see     java.lang.String#compareTo(java.lang.String)
  @@ -395,19 +444,19 @@
      */
     public boolean equals(Object obj2)
     {
  -    if(null == obj2)
  +
  +    if (null == obj2)
         return false;
  -      
  -    // In order to handle the 'all' semantics of 
  -    // nodeset comparisons, we always call the 
  -    // nodeset function.
  +
  +      // In order to handle the 'all' semantics of 
  +      // nodeset comparisons, we always call the 
  +      // nodeset function.
       else if (obj2 instanceof XNodeSet)
         return obj2.equals(this);
       else
         return str().equals(obj2.toString());
     }
   
  -
     /**
      * Compares this <code>String</code> to another <code>String</code>,
      * ignoring case considerations.  Two strings are considered equal
  @@ -432,6 +481,8 @@
      * Compares two strings lexicographically.
      *
      * @param   anotherString   the <code>String</code> to be compared.
  +   *
  +   * NEEDSDOC @param xstr
      * @return  the value <code>0</code> if the argument string is equal to
      *          this string; a value less than <code>0</code> if this string
      *          is lexicographically less than the string argument; and a
  @@ -440,9 +491,30 @@
      * @exception java.lang.NullPointerException if <code>anotherString</code>
      *          is <code>null</code>.
      */
  -  public int compareTo(XMLString anotherString)
  +  public int compareTo(XMLString xstr)
     {
  -    return str().compareTo(anotherString.toString());
  +
  +    int len1 = this.length();
  +    int len2 = xstr.length();
  +    int n = Math.min(len1, len2);
  +    int i = 0;
  +    int j = 0;
  +
  +    while (n-- != 0)
  +    {
  +      char c1 = this.charAt(i);
  +      char c2 = xstr.charAt(j);
  +
  +      if (c1 != c2)
  +      {
  +        return c1 - c2;
  +      }
  +
  +      i++;
  +      j++;
  +    }
  +
  +    return len1 - len2;
     }
   
     /**
  @@ -507,8 +579,74 @@
      *          <code>null</code>.
      */
     public boolean startsWith(String prefix)
  +  {
  +    return startsWith(prefix, 0);
  +  }
  +
  +  /**
  +   * Tests if this string starts with the specified prefix beginning
  +   * a specified index.
  +   *
  +   * @param   prefix    the prefix.
  +   * @param   toffset   where to begin looking in the string.
  +   * @return  <code>true</code> if the character sequence represented by the
  +   *          argument is a prefix of the substring of this object starting
  +   *          at index <code>toffset</code>; <code>false</code> otherwise.
  +   *          The result is <code>false</code> if <code>toffset</code> is
  +   *          negative or greater than the length of this
  +   *          <code>String</code> object; otherwise the result is the same
  +   *          as the result of the expression
  +   *          <pre>
  +   *          this.subString(toffset).startsWith(prefix)
  +   *          </pre>
  +   * @exception java.lang.NullPointerException if <code>prefix</code> is
  +   *          <code>null</code>.
  +   */
  +  public boolean startsWith(XMLString prefix, int toffset)
  +  {
  +
  +    int to = toffset;
  +    int tlim = this.length();
  +    int po = 0;
  +    int pc = prefix.length();
  +
  +    // Note: toffset might be near -1>>>1.
  +    if ((toffset < 0) || (toffset > tlim - pc))
  +    {
  +      return false;
  +    }
  +
  +    while (--pc >= 0)
  +    {
  +      if (this.charAt(to) != prefix.charAt(po))
  +      {
  +        return false;
  +      }
  +
  +      to++;
  +      po++;
  +    }
  +
  +    return true;
  +  }
  +
  +  /**
  +   * Tests if this string starts with the specified prefix.
  +   *
  +   * @param   prefix   the prefix.
  +   * @return  <code>true</code> if the character sequence represented by the
  +   *          argument is a prefix of the character sequence represented by
  +   *          this string; <code>false</code> otherwise.
  +   *          Note also that <code>true</code> will be returned if the
  +   *          argument is an empty string or is equal to this
  +   *          <code>String</code> object as determined by the
  +   *          {@link #equals(Object)} method.
  +   * @exception java.lang.NullPointerException if <code>prefix</code> is
  +   *          <code>null</code>.
  +   */
  +  public boolean startsWith(XMLString prefix)
     {
  -    return str().startsWith(prefix);
  +    return startsWith(prefix, 0);
     }
   
     /**
  @@ -671,7 +809,7 @@
     {
       return str().indexOf(str);
     }
  -  
  +
     /**
      * Returns the index within this string of the first occurrence of the
      * specified substring. The integer returned is the smallest value
  @@ -915,7 +1053,7 @@
     {
       return new XString(str().trim());
     }
  -  
  +
     /**
      * Returns whether the specified <var>ch</var> conforms to the XML 1.0 definition
      * of whitespace.  Refer to <A href="http://www.w3.org/TR/1998/REC-xml-19980210#NT-S">
  @@ -927,7 +1065,7 @@
     {
       return XMLCharacterRecognizer.isWhiteSpace(ch);  // Take the easy way out for now.
     }
  -  
  +
     /**
      * Conditionally trim all leading and trailing whitespace in the specified String.
      * All strings of white space are
  @@ -936,21 +1074,22 @@
      * This function may be useful to a formatter, but to get first class
      * results, the formatter should probably do it's own white space handling
      * based on the semantics of the formatting object.
  -   * 
  +   *
      * @param   trimHead    Trim leading whitespace?
      * @param   trimTail    Trim trailing whitespace?
      * @param   doublePunctuationSpaces    Use double spaces for punctuation?
      * @return              The trimmed string.
      */
  -  public XMLString fixWhiteSpace(boolean trimHead,
  -                                 boolean trimTail,
  +  public XMLString fixWhiteSpace(boolean trimHead, boolean trimTail,
                                    boolean doublePunctuationSpaces)
     {
  -    // %OPT% !!!!!!!
   
  +    // %OPT% !!!!!!!
       int len = this.length();
       char[] buf = new char[len];
  +
       this.getChars(0, len, buf, 0);
  +
       boolean edit = false;
       int s;
   
  @@ -1026,7 +1165,7 @@
       }
   
       XMLStringFactory xsf = XMLStringFactoryImpl.getFactory();
  -    return edit ? xsf.newstr( new String(buf, start, d - start) ) : this;
  -  }
   
  +    return edit ? xsf.newstr(new String(buf, start, d - start)) : this;
  +  }
   }
  
  
  
  1.1.2.2   +21 -0     xml-xalan/java/src/org/apache/xpath/objects/Attic/XStringForChars.java
  
  Index: XStringForChars.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/Attic/XStringForChars.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- XStringForChars.java	2001/05/18 07:17:23	1.1.2.1
  +++ XStringForChars.java	2001/05/19 07:05:58	1.1.2.2
  @@ -59,6 +59,27 @@
     {
       throw new RuntimeException("fsb() not supported for XStringForChars!");
     }
  +  
  +  /**
  +   * Cast result object to a string.
  +   *
  +   * @return The string this wraps or the empty string if null
  +   */
  +  public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb)
  +  {
  +    fsb.append((char[])m_obj, m_start, m_length);
  +  }
  +
  +  
  +  /**
  +   * Tell if this object contains a java String object.
  +   * 
  +   * @return true if this XMLString can return a string without creating one.
  +   */
  +  public boolean hasString()
  +  {
  +    return (null != m_strCache);
  +  }
   
     
     /**
  
  
  
  1.1.2.2   +234 -6    xml-xalan/java/src/org/apache/xpath/objects/Attic/XStringForFSB.java
  
  Index: XStringForFSB.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/Attic/XStringForFSB.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- XStringForFSB.java	2001/05/18 07:17:24	1.1.2.1
  +++ XStringForFSB.java	2001/05/19 07:05:59	1.1.2.2
  @@ -124,8 +124,35 @@
     {
       return ((FastStringBuffer) m_obj);
     }
  +  
  +  /**
  +   * Cast result object to a string.
  +   *
  +   * @return The string this wraps or the empty string if null
  +   */
  +  public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb)
  +  {
  +    // %OPT% !!! FSB has to be updated to take partial fsb's for append.
  +    fsb.append(str());
  +  }
   
     /**
  +   * Tell if this object contains a java String object.
  +   *
  +   * @return true if this XMLString can return a string without creating one.
  +   */
  +  public boolean hasString()
  +  {
  +    return (null != m_strCache);
  +  }
  +
  +//  /** NEEDSDOC Field strCount */
  +//  public static int strCount = 0;
  +//
  +//  /** NEEDSDOC Field xtable */
  +//  static java.util.Hashtable xtable = new java.util.Hashtable();
  +
  +  /**
      * Cast result object to a string.
      *
      * @return The string this wraps or the empty string if null
  @@ -134,8 +161,33 @@
     {
   
       if (null == m_strCache)
  +    {
         m_strCache = fsb().getString(m_start, m_length);
   
  +//      strCount++;
  +//
  +//      RuntimeException e = new RuntimeException("Bad!  Bad!");
  +//      java.io.CharArrayWriter writer = new java.io.CharArrayWriter();
  +//      java.io.PrintWriter pw = new java.io.PrintWriter(writer);
  +//
  +//      e.printStackTrace(pw);
  +//
  +//      String str = writer.toString();
  +//
  +//      str = str.substring(0, 600);
  +//
  +//      if (null == xtable.get(str))
  +//      {
  +//        xtable.put(str, str);
  +//        System.out.println(str);
  +//      }
  +//      System.out.println("strCount: " + strCount);
  +
  +//      throw e;
  +//      e.printStackTrace();
  +      // System.exit(-1);
  +    }
  +
       return m_strCache;
     }
   
  @@ -197,7 +249,7 @@
      */
     public char charAt(int index)
     {
  -    return fsb().charAt(m_start+index);
  +    return fsb().charAt(m_start + index);
     }
   
     /**
  @@ -281,6 +333,7 @@
           {
             return false;
           }
  +
           i++;
           j++;
         }
  @@ -323,6 +376,7 @@
           {
             return false;
           }
  +
           i++;
           j++;
         }
  @@ -361,6 +415,7 @@
           {
             return false;
           }
  +
           i++;
           j++;
         }
  @@ -457,6 +512,7 @@
         {
           return c1 - c2;
         }
  +
         i++;
         j++;
       }
  @@ -503,6 +559,7 @@
         {
           return c1 - c2;
         }
  +
         i++;
         j++;
       }
  @@ -537,6 +594,7 @@
         for (int i = 0; i < len; i++)
         {
           h = 31 * h + fsb.charAt(off);
  +
           off++;
         }
   
  @@ -547,6 +605,74 @@
     }
   
     /**
  +   * Tests if this string starts with the specified prefix beginning
  +   * a specified index.
  +   *
  +   * @param   prefix    the prefix.
  +   * @param   toffset   where to begin looking in the string.
  +   * @return  <code>true</code> if the character sequence represented by the
  +   *          argument is a prefix of the substring of this object starting
  +   *          at index <code>toffset</code>; <code>false</code> otherwise.
  +   *          The result is <code>false</code> if <code>toffset</code> is
  +   *          negative or greater than the length of this
  +   *          <code>String</code> object; otherwise the result is the same
  +   *          as the result of the expression
  +   *          <pre>
  +   *          this.subString(toffset).startsWith(prefix)
  +   *          </pre>
  +   * @exception java.lang.NullPointerException if <code>prefix</code> is
  +   *          <code>null</code>.
  +   */
  +  public boolean startsWith(XMLString prefix, int toffset)
  +  {
  +
  +    FastStringBuffer fsb = fsb();
  +    int to = m_start + toffset;
  +    int tlim = m_start + m_length;
  +    int po = 0;
  +    int pc = prefix.length();
  +
  +    // Note: toffset might be near -1>>>1.
  +    if ((toffset < 0) || (toffset > m_length - pc))
  +    {
  +      return false;
  +    }
  +
  +    while (--pc >= 0)
  +    {
  +      if (fsb.charAt(to) != prefix.charAt(po))
  +      {
  +        return false;
  +      }
  +
  +      to++;
  +      po++;
  +    }
  +
  +    return true;
  +  }
  +
  +  /**
  +   * Tests if this string starts with the specified prefix.
  +   *
  +   * @param   prefix   the prefix.
  +   * @return  <code>true</code> if the character sequence represented by the
  +   *          argument is a prefix of the character sequence represented by
  +   *          this string; <code>false</code> otherwise.
  +   *          Note also that <code>true</code> will be returned if the
  +   *          argument is an empty string or is equal to this
  +   *          <code>String</code> object as determined by the
  +   *          {@link #equals(Object)} method.
  +   * @exception java.lang.NullPointerException if <code>prefix</code> is
  +   *          <code>null</code>.
  +   * @since   JDK1. 0
  +   */
  +  public boolean startsWith(XMLString prefix)
  +  {
  +    return startsWith(prefix, 0);
  +  }
  +
  +  /**
      * Returns the index within this string of the first occurrence of the
      * specified character. If a character with value <code>ch</code> occurs
      * in the character sequence represented by this <code>String</code>
  @@ -643,12 +769,15 @@
      */
     public XMLString substring(int beginIndex)
     {
  +
       int len = m_length - beginIndex;
  -    if(len <= 0)
  +
  +    if (len <= 0)
         return XString.EMPTYSTRING;
       else
       {
  -      int start = m_start+beginIndex;
  +      int start = m_start + beginIndex;
  +
         return new XStringForFSB(fsb(), start, len);
       }
     }
  @@ -671,14 +800,18 @@
      */
     public XMLString substring(int beginIndex, int endIndex)
     {
  +
       int len = endIndex - beginIndex;
  -    if(len > m_length)
  +
  +    if (len > m_length)
         len = m_length;
  -    if(len <= 0)
  +
  +    if (len <= 0)
         return XString.EMPTYSTRING;
       else
       {
  -      int start = m_start+beginIndex;
  +      int start = m_start + beginIndex;
  +
         return new XStringForFSB(fsb(), start, len);
       }
     }
  @@ -812,4 +945,99 @@
   
       return edit ? xsf.newstr(buf, start, d - start) : this;
     }
  +
  +  /**
  +   * Convert a string to a double -- Allowed input is in fixed
  +   * notation ddd.fff.
  +   *
  +   * @return A double value representation of the string, or return Double.NaN 
  +   * if the string can not be converted.
  +   */
  +  public double toDouble()
  +  {
  +
  +    int start = m_start;
  +    int end = m_length+start;
  +    
  +    if(0 == end)
  +      return Double.NaN;
  +      
  +    double result = 0.0;
  +    int punctPos = end-1;
  +    FastStringBuffer fsb = fsb();
  +    
  +    // Scan to first whitespace character.
  +    for (int i = start; i < end; i++) 
  +    {
  +      char c = fsb.charAt(i);
  +      if( !Character.isSpaceChar( c ) )
  +      {
  +        break;
  +      }
  +      else
  +        start++;
  +    }
  +
  +    double sign = 1.0;
  +    if (start < end && fsb.charAt(start) == '-')
  +    {
  +      sign = -1.0;
  +
  +      start++;
  +    }
  +    
  +    int digitsFound = 0;
  +    for (int i = start; i < end; i++)  // parse the string from left to right converting the integer part
  +    {
  +      char c = fsb.charAt(i);
  +      if (c != '.')
  +      {
  +        if(Character.isSpaceChar(c))
  +          break;
  +        else if (Character.isDigit(c))
  +        {
  +          result = result * 10.0 + (c - 0x30);
  +          digitsFound++;
  +        }
  +        else
  +        {
  +          return Double.NaN;
  +        }
  +      }
  +      else
  +      {
  +        punctPos = i;
  +
  +        break;
  +      }
  +    }
  +    
  +    if (fsb.charAt(punctPos) == '.')  // parse the string from the end to the '.' converting the fractional part
  +    {
  +      double fractPart = 0.0;
  +      for (int i = end - 1; i > punctPos; i--)
  +      {
  +        char c = fsb.charAt(i);
  +        if(Character.isSpaceChar(c))
  +          break;
  +        else if (Character.isDigit(c))
  +        {
  +          fractPart = fractPart / 10.0 + (c - 0x30);
  +          digitsFound++;
  +        }
  +        else
  +        {
  +          return Double.NaN;
  +        }
  +      }
  +
  +      result += fractPart / 10.0;
  +    }
  +    
  +    if(0 == digitsFound)
  +      return Double.NaN;
  +
  +    return result * sign;
  +  }
  +
   }
  
  
  

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