2 // This software is now distributed according to
3 // the Lesser Gnu Public License. Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
8 package com.stevesoft.pat;
11 * Encapsulates the Unicode definitions of Upper, Lower, and Title case as
12 * defined by <a href="http://www.unicode.org"> unicode.org</a>.
14 * The performance of the methods found in String and Character is better, but
15 * these methods work both in java 1.0 and 1.1. If it is desirable, either to
16 * gain a slight performance increase or to accomodate application specific
17 * modifications to the definitions of upper, lower, and title case then it
18 * should be a straightforward task to substitute your own methods for these.
20 final public class CaseMgr
22 final static boolean java_1_0 = false;
24 /** Convert a character to upper case . */
25 public static char toUpperCase(char c)
2054 return Character.toUpperCase(c);
2057 /** Convert a character to lower case. */
2058 public static char toLowerCase(char c)
4180 return Character.toLowerCase(c);
4183 /** Convert a String to title case. */
4184 public static String toTitleCase(String s)
4186 StringBuffer sb = new StringBuffer();
4187 for (int i = 0; i < s.length(); i++)
4189 sb.append(CaseMgr.toTitleCase(s.charAt(i)));
4191 return sb.toString();
4194 /** Convert a String to upper case. */
4195 public static String toUpperCase(String s)
4197 StringBuffer sb = new StringBuffer();
4198 for (int i = 0; i < s.length(); i++)
4200 sb.append(CaseMgr.toUpperCase(s.charAt(i)));
4202 return sb.toString();
4205 /** Convert a String to lower case. */
4206 public static String toLowerCase(String s)
4208 StringBuffer sb = new StringBuffer();
4209 for (int i = 0; i < s.length(); i++)
4211 sb.append(CaseMgr.toLowerCase(s.charAt(i)));
4213 return sb.toString();
4216 /** Convert a character to title case. */
4217 public static char toTitleCase(char c)
4221 int ret = (int) toUpperCase(c);
4263 return Character.toTitleCase(c);
4267 * Duplicates the regionMatches routine of String -- but makes use of the
4268 * definitions of upper, lower, and title case in this class when ignoreCase
4271 public static boolean regionMatches(StringLike s1, boolean ign, int i1,
4272 StringLike s2, int i2, int i3)
4275 if (itot > s2.length() || i1 + i3 > s1.length())
4281 for (int i = i2; i < itot; i++)
4283 if (s2.charAt(i) != s1.charAt(i1++))
4291 for (int i = i2; i < itot; i++)
4293 if (toLowerCase(s2.charAt(i)) != toLowerCase(s1.charAt(i1++)))
4303 * Duplicates the regionMatches routine of String -- but makes use of the
4304 * definitions of upper, lower, and title case in this class when ignoreCase
4307 public static boolean regionMatches(String s1, boolean ign, int i1,
4308 StringLike s2, int i2, int i3)
4311 if (itot > s2.length() || i1 + i3 > s1.length())
4317 for (int i = i2; i < itot; i++)
4319 if (s2.charAt(i) != s1.charAt(i1++))
4327 for (int i = i2; i < itot; i++)
4329 if (toLowerCase(s2.charAt(i)) != toLowerCase(s1.charAt(i1++)))
4339 * Duplicates the regionMatches routine of String -- but makes use of the
4340 * definitions of upper, lower, and title case in this class when ignoreCase
4343 public static boolean regionMatches(StringLike s1, boolean ign, int i1,
4344 String s2, int i2, int i3)
4347 if (itot > s2.length() || i1 + i3 > s1.length())
4353 for (int i = i2; i < itot; i++)
4355 if (s2.charAt(i) != s1.charAt(i1++))
4363 for (int i = i2; i < itot; i++)
4365 if (toLowerCase(s2.charAt(i)) != toLowerCase(s1.charAt(i1++)))
4375 * Duplicates the regionMatches routine of String -- but makes use of the
4376 * definitions of upper, lower, and title case in this class when ignoreCase
4379 public static boolean regionMatches(String s1, boolean ign, int i1,
4380 String s2, int i2, int i3)
4383 if (itot > s2.length() || i1 + i3 > s1.length())
4389 for (int i = i2; i < itot; i++)
4391 if (s2.charAt(i) != s1.charAt(i1++))
4399 for (int i = i2; i < itot; i++)
4401 if (toLowerCase(s2.charAt(i)) != toLowerCase(s1.charAt(i1++)))