2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.spellchecker
.util
;
18 import java
.util
.List
;
23 public final class Strings
{
27 public static boolean isCapitalized(String word
) {
28 if (word
.length() == 0) return false;
30 boolean lowCase
= true;
31 for (int i
= 1; i
< word
.length() && lowCase
; i
++) {
32 lowCase
= Character
.isLowerCase(word
.charAt(i
));
35 return Character
.isUpperCase(word
.charAt(0)) && lowCase
;
38 public static boolean isUpperCase(String word
) {
39 boolean upperCase
= true;
40 for (int i
= 0; i
< word
.length() && upperCase
; i
++) {
41 upperCase
= Character
.isUpperCase(word
.charAt(i
));
47 public static boolean isMixedCase(String word
) {
48 if (word
.length() < 2) return false;
50 String tail
= word
.substring(1);
51 String lowerCase
= tail
.toLowerCase();
52 return !tail
.equals(lowerCase
) && !isUpperCase(word
);
55 public static String
capitalize(String word
) {
56 if (word
.length() == 0) return word
;
58 StringBuffer buf
= new StringBuffer(word
);
59 buf
.setCharAt(0, Character
.toUpperCase(buf
.charAt(0)));
60 return buf
.toString();
63 public static void capitalize(List
<String
> words
) {
64 for (int i
= 0; i
< words
.size(); i
++) {
65 words
.set(i
, capitalize(words
.get(i
)));
69 public static void upperCase(List
<String
> words
) {
70 for (int i
= 0; i
< words
.size(); i
++) {
71 words
.set(i
, words
.get(i
).toUpperCase());