You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Fredrik Westermarck <fr...@mdh.se> on 2002/09/19 00:57:14 UTC

[lang][PATCH] StringUtils

Hi!

Here is a patch for the StringUtils class with a containsOnly-method. 
Well actually it's two patches since I also added testcases.

Fredrik Westermarck


Re: [lang][PATCH] StringUtils

Posted by Fredrik Westermarck <fr...@mdh.se>.
Henri Yandell wrote:
> 
> Thanks for patch Fredrik.
> 
> Do you mind if I change the code to:

---- 8< -----

> namely, introducing the variables to stop the length being accessed each
> time, and getting rid of the extra boolean variable?

Hi!

That seems resonable to me.

Fredrik Westermarck

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [lang][PATCH] StringUtils

Posted by Henri Yandell <ba...@generationjava.com>.
Thanks for patch Fredrik.

Do you mind if I change the code to:

    public static boolean containsOnly(String str, char[] valid) {
        if(str == null || valid == null) {
            return false;
        }

        int strSize = str.length();
        int validSize = valid.length;

        for(int i=0; i<strSize; i++) {
            boolean contains = false;
            for(int j=0; j<validSize; j++) {
                if(valid[j] == str.charAt(i)) {
                    contains = true;
                    break;
                }
            }
            if(!contains) {
                return false;
            }
        }

        return true;
    }

namely, introducing the variables to stop the length being accessed each
time, and getting rid of the extra boolean variable?

Hen

On Thu, 19 Sep 2002, Fredrik Westermarck wrote:

> Fredrik Westermarck wrote:
> > Hi!
> >
> > Here is a patch for the StringUtils class with a containsOnly-method.
> > Well actually it's two patches since I also added testcases.
>
> Since Mozilla tries to inline attachments they somehow got lost. I
> packaged them in a zip-file instead. Hopefully that it will work. :)
>
> Fredrik Westermarck
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [lang][PATCH] StringUtils

Posted by Fredrik Westermarck <fr...@mdh.se>.
Fredrik Westermarck wrote:
> Hi!
> 
> Here is a patch for the StringUtils class with a containsOnly-method. 
> Well actually it's two patches since I also added testcases.

Since Mozilla tries to inline attachments they somehow got lost. I 
packaged them in a zip-file instead. Hopefully that it will work. :)

Fredrik Westermarck