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 toUpperCaseC(char c)
2052 // return (char) ret;
2054 return Character.toUpperCase(c);
2057 /** Convert a character to lower case. */
2058 public static char toLowerCaseC(char c)
2062 // int ret = (int) c;
4178 // return (char) ret;
4180 return Character.toLowerCase(c);
4183 /** Convert a String to title case.
4189 public static String toTitleCase(String s)
4191 StringBuffer sb = new StringBuffer();
4192 for (int i = 0; i < s.length(); i++)
4194 sb.append(CaseMgr.toTitleCaseC(s.charAt(i)));
4196 return sb.toString();
4199 /** Convert a String to upper case. */
4200 public static String toUpperCase(String s)
4202 return s.toUpperCase();
4203 // StringBuffer sb = new StringBuffer();
4204 // for (int i = 0; i < s.length(); i++)
4206 // sb.append(CaseMgr.toUpperCaseC(s.charAt(i)));
4208 // return sb.toString();
4211 /** Convert a String to lower case. */
4212 public static String toLowerCase(String s)
4214 return s.toLowerCase();
4215 // StringBuffer sb = new StringBuffer();
4216 // for (int i = 0; i < s.length(); i++)
4218 // sb.append(CaseMgr.toLowerCaseC(s.charAt(i)));
4220 // return sb.toString();
4223 /** Convert a character to title case.
4225 * SwingJS -- BH -- ignoring title case.
4228 public static char toTitleCaseC(char c)
4230 return Character.toUpperCase(c);
4233 // int ret = (int) toUpperCaseC(c);
4273 // return (char) ret;
4275 // return Character.toTitleCase(c);
4279 * Duplicates the regionMatches routine of String -- but makes use of the
4280 * definitions of upper, lower, and title case in this class when ignoreCase
4283 public static boolean regionMatchesLike(StringLike s1, boolean ign, int i1,
4284 StringLike s2, int i2, int i3)
4287 if (itot > s2.length() || i1 + i3 > s1.length())
4293 for (int i = i2; i < itot; i++)
4295 if (s2.charAt(i) != s1.charAt(i1++))
4303 for (int i = i2; i < itot; i++)
4305 if (toLowerCaseC(s2.charAt(i)) != toLowerCaseC(s1.charAt(i1++)))
4315 * Duplicates the regionMatches routine of String -- but makes use of the
4316 * definitions of upper, lower, and title case in this class when ignoreCase
4319 public static boolean regionMatches(String s1, boolean ign, int i1,
4320 StringLike s2, int i2, int i3)
4323 if (itot > s2.length() || i1 + i3 > s1.length())
4329 for (int i = i2; i < itot; i++)
4331 if (s2.charAt(i) != s1.charAt(i1++))
4339 for (int i = i2; i < itot; i++)
4341 if (toLowerCaseC(s2.charAt(i)) != toLowerCaseC(s1.charAt(i1++)))
4351 * Duplicates the regionMatches routine of String -- but makes use of the
4352 * definitions of upper, lower, and title case in this class when ignoreCase
4355 public static boolean regionMatchesLike2(StringLike s1, boolean ign, int i1,
4356 String s2, int i2, int i3)
4359 if (itot > s2.length() || i1 + i3 > s1.length())
4365 for (int i = i2; i < itot; i++)
4367 if (s2.charAt(i) != s1.charAt(i1++))
4375 for (int i = i2; i < itot; i++)
4377 if (toLowerCaseC(s2.charAt(i)) != toLowerCaseC(s1.charAt(i1++)))
4387 * Duplicates the regionMatches routine of String -- but makes use of the
4388 * definitions of upper, lower, and title case in this class when ignoreCase
4391 public static boolean regionMatches2(String s1, boolean ign, int i1,
4392 String s2, int i2, int i3)
4395 if (itot > s2.length() || i1 + i3 > s1.length())
4401 for (int i = i2; i < itot; i++)
4403 if (s2.charAt(i) != s1.charAt(i1++))
4411 for (int i = i2; i < itot; i++)
4413 if (toLowerCaseC(s2.charAt(i)) != toLowerCaseC(s1.charAt(i1++)))