You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by ba...@generationjava.com on 2001/12/07 16:41:44 UTC
Re: Bay or Glen, String Replace tag broken
Doh :)
Looks like a good call. Thanks Ben.
Bay
On Fri, 7 Dec 2001, Neuman, Ben J. , AFIS-HQ/IRM wrote:
> Hi!
> The String tag replace is broken. It looks like you need to change the
> StringW class method:
>
> static public String replaceString(String text, String repl, String with,
> int n) {
> int idx = 0;
> while( (idx = text.indexOf(repl)) != -1) {
> text = text.substring(0,idx) + with +
> text.substring(idx+repl.length() );
> idx += with.length(); // jump beyond replacement
> n--;
> if(n == 0) {
> break;
> }
> }
> return text;
> }
>
> to:
>
> static public String replaceString(String text, String repl, String with,
> int n) {
> int idx = 0;
> while( (idx = text.indexOf(repl, idx)) != -1) {
> text = text.substring(0,idx) + with +
> text.substring(idx+repl.length() );
> idx += with.length(); // jump beyond replacement
> n--;
> if(n == 0) {
> break;
> }
> }
> return text;
> }
>
> If this is alleady done, please ignore. Just trying to help.
> Thanks,
> Ben
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Bay or Glen, String Replace tag broken
Posted by ba...@generationjava.com.
I've fixed it by copying over a previous rewrite from Jakarta Commons
where the code lives inside the util sub-project's StringUtils. Sadly that
code is still in a sandbox and I'm hesitant to make String-taglib
dependant on code that is still living in a sandbox.
[Then I'll need to find out how to go about making the taglib dependant on
Commons]
The rewrite basically involved switching it to using a StringBuffer for
speed.
Bay
> On Fri, 7 Dec 2001, Neuman, Ben J. , AFIS-HQ/IRM wrote:
>
> > Hi!
> > The String tag replace is broken. It looks like you need to change the
> > StringW class method:
> >
> > static public String replaceString(String text, String repl, String with,
> > int n) {
> > int idx = 0;
> > while( (idx = text.indexOf(repl)) != -1) {
> > text = text.substring(0,idx) + with +
> > text.substring(idx+repl.length() );
> > idx += with.length(); // jump beyond replacement
> > n--;
> > if(n == 0) {
> > break;
> > }
> > }
> > return text;
> > }
> >
> > to:
> >
> > static public String replaceString(String text, String repl, String with,
> > int n) {
> > int idx = 0;
> > while( (idx = text.indexOf(repl, idx)) != -1) {
> > text = text.substring(0,idx) + with +
> > text.substring(idx+repl.length() );
> > idx += with.length(); // jump beyond replacement
> > n--;
> > if(n == 0) {
> > break;
> > }
> > }
> > return text;
> > }
> >
> > If this is alleady done, please ignore. Just trying to help.
> > Thanks,
> > Ben
> >
> >
> > --
> > To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>