14fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/*
24fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Licensed to the Apache Software Foundation (ASF) under one or more
34fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * contributor license agreements.  See the NOTICE file distributed with
44fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * this work for additional information regarding copyright ownership.
54fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * The ASF licenses this file to You under the Apache License, Version 2.0
64fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * (the "License"); you may not use this file except in compliance with
74fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * the License.  You may obtain a copy of the License at
84fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *
94fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *      http://www.apache.org/licenses/LICENSE-2.0
104fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *
114fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Unless required by applicable law or agreed to in writing, software
124fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * distributed under the License is distributed on an "AS IS" BASIS,
134fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * See the License for the specific language governing permissions and
154fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * limitations under the License.
164fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */
174fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypackage org.apache.commons.io;
184fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
194fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedyimport java.io.Serializable;
204fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
214fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/**
224fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Enumeration of IO case sensitivity.
234fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * <p>
244fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Different filing systems have different rules for case-sensitivity.
254fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Windows is case-insensitive, Unix is case-sensitive.
264fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * <p>
274fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * This class captures that difference, providing an enumeration to
284fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * control how filename comparisons should be performed. It also provides
294fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * methods that use the enumeration to perform comparisons.
304fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * <p>
314fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Wherever possible, you should use the <code>check</code> methods in this
324fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * class to compare filenames.
334fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy *
344fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @author Stephen Colebourne
354fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @version $Id: IOCase.java 606345 2007-12-21 23:43:01Z ggregory $
364fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @since Commons IO 1.3
374fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */
384fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypublic final class IOCase implements Serializable {
394fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
404fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
414fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * The constant for case sensitive regardless of operating system.
424fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
434fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public static final IOCase SENSITIVE = new IOCase("Sensitive", true);
444fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
454fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
464fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * The constant for case insensitive regardless of operating system.
474fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
484fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public static final IOCase INSENSITIVE = new IOCase("Insensitive", false);
494fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
504fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
514fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * The constant for case sensitivity determined by the current operating system.
524fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Windows is case-insensitive when comparing filenames, Unix is case-sensitive.
534fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * <p>
544fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * If you derialize this constant of Windows, and deserialize on Unix, or vice
554fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * versa, then the value of the case-sensitivity flag will change.
564fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
574fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public static final IOCase SYSTEM = new IOCase("System", !FilenameUtils.isSystemWindows());
584fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
594fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /** Serialization version. */
604fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    private static final long serialVersionUID = -6343169151696340687L;
614fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
624fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /** The enumeration name. */
634fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    private final String name;
644fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
654fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /** The sensitivity flag. */
664fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    private final transient boolean sensitive;
674fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
684fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    //-----------------------------------------------------------------------
694fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
704fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Factory method to create an IOCase from a name.
714fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
724fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param name  the name to find
734fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return the IOCase object
744fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws IllegalArgumentException if the name is invalid
754fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
764fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public static IOCase forName(String name) {
774fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        if (IOCase.SENSITIVE.name.equals(name)){
784fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy            return IOCase.SENSITIVE;
794fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        }
804fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        if (IOCase.INSENSITIVE.name.equals(name)){
814fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy            return IOCase.INSENSITIVE;
824fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        }
834fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        if (IOCase.SYSTEM.name.equals(name)){
844fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy            return IOCase.SYSTEM;
854fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        }
864fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        throw new IllegalArgumentException("Invalid IOCase name: " + name);
874fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
884fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
894fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    //-----------------------------------------------------------------------
904fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
914fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Private constructor.
924fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
934fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param name  the name
944fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param sensitive  the sensitivity
954fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
964fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    private IOCase(String name, boolean sensitive) {
974fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        this.name = name;
984fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        this.sensitive = sensitive;
994fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1004fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1014fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1024fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Replaces the enumeration from the stream with a real one.
1034fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * This ensures that the correct flag is set for SYSTEM.
1044fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
1054fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return the resolved object
1064fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1074fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    private Object readResolve() {
1084fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return forName(name);
1094fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1104fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1114fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    //-----------------------------------------------------------------------
1124fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1134fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Gets the name of the constant.
1144fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
1154fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return the name of the constant
1164fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1174fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public String getName() {
1184fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return name;
1194fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1204fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1214fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1224fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Does the object represent case sensitive comparison.
1234fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
1244fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return true if case sensitive
1254fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1264fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public boolean isCaseSensitive() {
1274fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return sensitive;
1284fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1294fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1304fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    //-----------------------------------------------------------------------
1314fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1324fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Compares two strings using the case-sensitivity rule.
1334fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * <p>
1344fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * This method mimics {@link String#compareTo} but takes case-sensitivity
1354fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * into account.
1364fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
1374fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param str1  the first string to compare, not null
1384fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param str2  the second string to compare, not null
1394fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return true if equal using the case rules
1404fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws NullPointerException if either string is null
1414fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1424fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public int checkCompareTo(String str1, String str2) {
1434fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        if (str1 == null || str2 == null) {
1444fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy            throw new NullPointerException("The strings must not be null");
1454fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        }
1464fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return sensitive ? str1.compareTo(str2) : str1.compareToIgnoreCase(str2);
1474fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1484fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1494fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1504fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Compares two strings using the case-sensitivity rule.
1514fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * <p>
1524fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * This method mimics {@link String#equals} but takes case-sensitivity
1534fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * into account.
1544fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
1554fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param str1  the first string to compare, not null
1564fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param str2  the second string to compare, not null
1574fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return true if equal using the case rules
1584fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws NullPointerException if either string is null
1594fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1604fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public boolean checkEquals(String str1, String str2) {
1614fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        if (str1 == null || str2 == null) {
1624fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy            throw new NullPointerException("The strings must not be null");
1634fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        }
1644fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return sensitive ? str1.equals(str2) : str1.equalsIgnoreCase(str2);
1654fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1664fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1674fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1684fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Checks if one string starts with another using the case-sensitivity rule.
1694fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * <p>
1704fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * This method mimics {@link String#startsWith(String)} but takes case-sensitivity
1714fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * into account.
1724fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
1734fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param str  the string to check, not null
1744fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param start  the start to compare against, not null
1754fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return true if equal using the case rules
1764fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws NullPointerException if either string is null
1774fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1784fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public boolean checkStartsWith(String str, String start) {
1794fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return str.regionMatches(!sensitive, 0, start, 0, start.length());
1804fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1814fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1824fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1834fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Checks if one string ends with another using the case-sensitivity rule.
1844fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * <p>
1854fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * This method mimics {@link String#endsWith} but takes case-sensitivity
1864fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * into account.
1874fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
1884fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param str  the string to check, not null
1894fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param end  the end to compare against, not null
1904fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return true if equal using the case rules
1914fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws NullPointerException if either string is null
1924fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
1934fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public boolean checkEndsWith(String str, String end) {
1944fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        int endLen = end.length();
1954fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return str.regionMatches(!sensitive, str.length() - endLen, end, 0, endLen);
1964fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
1974fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
1984fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
1994fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Checks if one string contains another at a specific index using the case-sensitivity rule.
2004fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * <p>
2014fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * This method mimics parts of {@link String#regionMatches(boolean, int, String, int, int)}
2024fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * but takes case-sensitivity into account.
2034fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
2044fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param str  the string to check, not null
2054fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param strStartIndex  the index to start at in str
2064fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param search  the start to search for, not null
2074fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return true if equal using the case rules
2084fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @throws NullPointerException if either string is null
2094fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
2104fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public boolean checkRegionMatches(String str, int strStartIndex, String search) {
2114fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return str.regionMatches(!sensitive, strStartIndex, search, 0, search.length());
2124fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
2134fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
2144fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
2154fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Converts the case of the input String to a standard format.
2164fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Subsequent operations can then use standard String methods.
2174fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
2184fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @param str  the string to convert, null returns null
2194fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return the lower-case version if case-insensitive
2204fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
2214fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    String convertCase(String str) {
2224fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        if (str == null) {
2234fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy            return null;
2244fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        }
2254fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return sensitive ? str : str.toLowerCase();
2264fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
2274fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
2284fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    //-----------------------------------------------------------------------
2294fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    /**
2304fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * Gets a string describing the sensitivity.
2314fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     *
2324fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     * @return a string describing the sensitivity
2334fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy     */
2344fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    public String toString() {
2354fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy        return name;
2364fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy    }
2374fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy
2384fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy}
239