I'd also probably name the method something like
toASCIILowerCase()
or something so people grok it a little better.
geir
On Jan 16, 2007, at 12:07 PM, Tony Wu wrote:
Thanks Paulex.
I'll try to do this one by one if no one objects.
On 1/15/07, Yang Paulex <[EMAIL PROTECTED]> wrote:
2007/1/15, Tony Wu <[EMAIL PROTECTED]>:
>
> I found some String.toLower(Upper)Case are invoked in some place
which
> is not necessay at all.
>
> As you know, String.toLower(Upper)Case will perform locale-
sensitive
> mappings, context-sensitive mappings, and 1:M character
mappings. It
> is expensive I think.
I think so, it needs to load locale data .
In almost all of the conditions, following
> method[1] is good enough.
>
>
> For example, there is following line in java.net.URL,
> protocol = protocol.toLowerCase();
> But according to RFC 2396, the scheme is defined by "alpha *
( alpha |
> digit | "+" | "-" | "." )"
>
> And another example is the Locale,
> countryCode = country.toUpperCase();
> But country code is defined as ASCII character only.
>
> So I'd like to add methods like [1] to org.apache.harmony.luni.util
> and refactor every possible place to use it. please correct me
if I am
> wrong, any concerns are welcome.
>
> [1]
> public static String toLowerCase(String s){
> StringBuffer buffer = new StringBuffer();
> for (int i = 0; i < s.length(); i++) {
> char c = s.charAt(i);
> if ('A' <= c && c <= 'Z') {
> buffer.append((char) (c + ('a' - 'A')));
> }else{
> buffer.append(c);
> }
> }
> return buffer.toString();
> }
Sounds good, but please add clear comments to this method and the
invocations why String.toLowerCase is not preferred in these cases.
--
> Tony Wu
> China Software Development Lab, IBM
>
--
Paulex Yang
China Software Development Labotary
IBM
--
Tony Wu
China Software Development Lab, IBM