cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stuart Roebuck ...@adolos.com>
Subject Re: [Q] 1.7.3 - Fault with "substring" function = Math.round() fault
Date Wed, 10 May 2000 11:21:02 GMT
Problem solved...

> Begin forwarded message:
>
> > On Tue, 9 May 2000, Stuart Roebuck wrote:
> >
> > > I'm getting a StringIndexOutOfBoundsException trying to use the XPath    
> > > substring(string, start, length) function.  I've tried a simple:
> > >
> > > <xsl:variable name="test_variable" select="substring("1234",1,2)" />

> > >
> > > And this returns the same stack trace (see below).
> > > > java.lang.StringIndexOutOfBoundsException: String index out of range:
 
> >
> > substring() works fine for me; i couldn't reproduce your specific error,  
> > although you've made a mistake in the quoting - you can't nest double
> > quotes, so your example should be:
> >
> > <xsl:variable name="test_variable" select="substring('1234',1,2)" />
> >
> > i don't know if that's any help.
>
> Thanks for your reply.  I introduced the quoting mistake when I was
> writing the email - unfortunately that isn't the actual problem.  It looks   
> like the problem is a fault with the Math.round() function on the
> implementation of Java 1.2.2 I'm working on.
>
> I've downloaded the Xalan source, so I'm just going to try patching in a   
> call to Math.trunc() instead and see if that solves the problem.

Don't know quite what the issue is here, but I replaced the code (in file  
"xml-xalan/src/org/apache/xalan/xpath/FuncSubString.java" of Xalan 1.0.1):

-----
      {
        start = Math.round(start);
        startIndex = (start > 0) ? (int)start-1 : 0;
      }

      if(args.size() > 2)
      {
        double len = ((XObject)args.elementAt(2)).num();
        int end = (int)(Math.round(len)+start)-1;
-----

with

-----
      {
        start = Math.floor(start + 0.5);
        startIndex = (start > 0) ? (int)start-1 : 0;
      }

      if(args.size() > 2)
      {
        double len = ((XObject)args.elementAt(2)).num();
        int end = (int)(Math.floor(len + 0.5)+start)-1;

-----

converting round(x) calls to floor(x + 0.5), and this has solved the  
problem.  Perhaps this is some jitc problem on my configuration.

Regards,

Stuart.

Mime
View raw message