All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.siashan.toolkit.crypt.util.CharSequenceUtils Maven / Gradle / Ivy

package com.siashan.toolkit.crypt.util;

/**
 * 

* 对{@link CharSequence}进行的{@code null}安全的操作。 *

*

* 2014年4月10日(3.3.2发布之日)从Apache Commons Lang r1586295复制而来。 *

* * @see CharSequence * @since 1.0.7 */ public class CharSequenceUtils { /** * regionMatches的绿色实现 * *

注意:此函数与Apache Commons Lang中的当前实现不同 * 其中输入索引无效。它只在这个包中使用. * * @param cs * 要处理的{@code CharSequence} * @param ignoreCase * 是否不区分大小写 * @param thisStart * 从{@code cs}字符序列开始的索引 * @param substring * 要查找的{@code CharSequence} * @param start * 从{@code substring}字符序列开始的索引 * @param length * 区域的字符长度 * @return 区域是否匹配 */ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart, final CharSequence substring, final int start, final int length) { if (cs instanceof String && substring instanceof String) { return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length); } int index1 = thisStart; int index2 = start; int tmpLen = length; while (tmpLen-- > 0) { final char c1 = cs.charAt(index1++); final char c2 = substring.charAt(index2++); if (c1 == c2) { continue; } if (!ignoreCase) { return false; } // The same check as in String.regionMatches(): if (Character.toUpperCase(c1) != Character.toUpperCase(c2) && Character.toLowerCase(c1) != Character.toLowerCase(c2)) { return false; } } return true; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy