1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $(date) The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
20 *******************************************************************************/
22 // This software is now distributed according to
23 // the Lesser Gnu Public License. Please see
24 // http://www.gnu.org/copyleft/lesser.txt for
26 // -- Happy Computing!
28 package com.stevesoft.pat;
31 * Encapsulates the Unicode definitions of Upper, Lower, and Title case as
32 * defined by <a href="http://www.unicode.org"> unicode.org</a>.
34 * The performance of the methods found in String and Character is better, but
35 * these methods work both in java 1.0 and 1.1. If it is desirable, either to
36 * gain a slight performance increase or to accomodate application specific
37 * modifications to the definitions of upper, lower, and title case then it
38 * should be a straightforward task to substitute your own methods for these.
40 final public class CaseMgr
42 final static boolean java_1_0 = false;
44 /** Convert a character to upper case . */
45 public static char toUpperCase(char c)
2074 return Character.toUpperCase(c);
2077 /** Convert a character to lower case. */
2078 public static char toLowerCase(char c)
4200 return Character.toLowerCase(c);
4203 /** Convert a String to title case. */
4204 public static String toTitleCase(String s)
4206 StringBuffer sb = new StringBuffer();
4207 for (int i = 0; i < s.length(); i++)
4209 sb.append(CaseMgr.toTitleCase(s.charAt(i)));
4211 return sb.toString();
4214 /** Convert a String to upper case. */
4215 public static String toUpperCase(String s)
4217 StringBuffer sb = new StringBuffer();
4218 for (int i = 0; i < s.length(); i++)
4220 sb.append(CaseMgr.toUpperCase(s.charAt(i)));
4222 return sb.toString();
4225 /** Convert a String to lower case. */
4226 public static String toLowerCase(String s)
4228 StringBuffer sb = new StringBuffer();
4229 for (int i = 0; i < s.length(); i++)
4231 sb.append(CaseMgr.toLowerCase(s.charAt(i)));
4233 return sb.toString();
4236 /** Convert a character to title case. */
4237 public static char toTitleCase(char c)
4241 int ret = (int) toUpperCase(c);
4283 return Character.toTitleCase(c);
4287 * Duplicates the regionMatches routine of String -- but makes use of the
4288 * definitions of upper, lower, and title case in this class when ignoreCase
4291 public static boolean regionMatches(StringLike s1, boolean ign, int i1,
4292 StringLike s2, int i2, int i3)
4295 if (itot > s2.length() || i1 + i3 > s1.length())
4301 for (int i = i2; i < itot; i++)
4303 if (s2.charAt(i) != s1.charAt(i1++))
4311 for (int i = i2; i < itot; i++)
4313 if (toLowerCase(s2.charAt(i)) != toLowerCase(s1.charAt(i1++)))
4323 * Duplicates the regionMatches routine of String -- but makes use of the
4324 * definitions of upper, lower, and title case in this class when ignoreCase
4327 public static boolean regionMatches(String s1, boolean ign, int i1,
4328 StringLike s2, int i2, int i3)
4331 if (itot > s2.length() || i1 + i3 > s1.length())
4337 for (int i = i2; i < itot; i++)
4339 if (s2.charAt(i) != s1.charAt(i1++))
4347 for (int i = i2; i < itot; i++)
4349 if (toLowerCase(s2.charAt(i)) != toLowerCase(s1.charAt(i1++)))
4359 * Duplicates the regionMatches routine of String -- but makes use of the
4360 * definitions of upper, lower, and title case in this class when ignoreCase
4363 public static boolean regionMatches(StringLike s1, boolean ign, int i1,
4364 String s2, int i2, int i3)
4367 if (itot > s2.length() || i1 + i3 > s1.length())
4373 for (int i = i2; i < itot; i++)
4375 if (s2.charAt(i) != s1.charAt(i1++))
4383 for (int i = i2; i < itot; i++)
4385 if (toLowerCase(s2.charAt(i)) != toLowerCase(s1.charAt(i1++)))
4395 * Duplicates the regionMatches routine of String -- but makes use of the
4396 * definitions of upper, lower, and title case in this class when ignoreCase
4399 public static boolean regionMatches(String s1, boolean ign, int i1,
4400 String s2, int i2, int i3)
4403 if (itot > s2.length() || i1 + i3 > s1.length())
4409 for (int i = i2; i < itot; i++)
4411 if (s2.charAt(i) != s1.charAt(i1++))
4419 for (int i = i2; i < itot; i++)
4421 if (toLowerCase(s2.charAt(i)) != toLowerCase(s1.charAt(i1++)))