List of usage examples for org.apache.commons.lang CharSet contains
public boolean contains(char ch)
Does the CharSet
contain the specified character ch
.
From source file:CharSetExampleV1.java
public static void main(String args[]) { CharSet set = CharSet.getInstance("the apprentice"); System.err.println(set.contains('q')); CharRange[] range = set.getCharRanges(); System.err.println(ArrayUtils.toString(range)); }
From source file:MainClass.java
public static void main(String[] args) { //Create a new vowel character set CharSet vChs = CharSet.getInstance("aeiou"); String strTest = "The quick brown fox jumps over the lazy dog."; int iVowelCnt = 0; int iTestLen = strTest.length(); for (int i = 0; i < iTestLen; i++) { if (vChs.contains(strTest.charAt(i))) { iVowelCnt++; //increment count on a vowel being found }//from w w w. j ava 2 s. co m } System.out.println("String >>" + strTest); System.out.println("Number of vowels in the string is " + iVowelCnt); }
From source file:VowelCharSetTrial.java
public static void main(String[] args) { // Create a new vowel character set CharSet vChs = CharSet.getInstance("aeiou"); String strTest = "The quick brown fox jumps over the lazy dog."; int iVowelCnt = 0; int iTestLen = strTest.length(); for (int i = 0; i < iTestLen; i++) { if (vChs.contains(strTest.charAt(i))) { iVowelCnt++; // increment count on a vowel being found }// w w w.j a v a 2s . c o m } System.out.println("String >>" + strTest); System.out.println("Number of vowels in the string is " + iVowelCnt); }
From source file:org.cesecore.util.StringTools.java
/** * Characters from 'str' will be stripped like this: * any character that is in the 'stripThis' set will be replaced with '/'. * any character that is escaped (preceded with '\') and not in the {@value #allowedEscapeChars} set will be replaced with '/'. * when a character is replaced with '/' and also escaped then the preceding escape character '\' will be removed. * /* w w w. ja va2s . c om*/ * @param str the original string * @param stripThis set of characters that should be stripped. * @return the stripped string */ private static String strip(final String str, final CharSet stripThis) { if (str == null) { return null; } final StringBuilder buf = new StringBuilder(str); int index = 0; int end = buf.length(); while (index < end) { if (buf.charAt(index) == '\\') { // Found an escape character. if (index + 1 == end) { // If this is the last character we should remove it. buf.setCharAt(index, '/'); } else if (!isAllowedEscape(buf.charAt(index + 1))) { // We did not allow this character to be escaped. Replace both the \ and the character with a single '/'. buf.setCharAt(index, '/'); buf.deleteCharAt(index + 1); end--; } else { index++; } } else if (stripThis.contains(buf.charAt(index))) { // Illegal character. Replace it with a '/'. buf.setCharAt(index, '/'); } index++; } final String result = buf.toString(); if (log.isDebugEnabled() && !result.equals(str)) { log.debug("Some chars stripped. Was '" + str + "' is now '" + result + "'."); } return result; }
From source file:org.cesecore.util.StringTools.java
/** * Check if 'str' has any chars that should be stripped by a call to {@link #strip(String, CharSet)}. * @param str the string to be tested.// www.j av a2 s . co m * @param checkThese characters that must be stripped. * @return true if a call to {@link #strip(String, CharSet) will change 'str'. */ private static boolean hasStripChars(final String str, final CharSet checkThese) { if (str == null) { return false; } int index = 0; final int end = str.length(); while (index < end) { if (str.charAt(index) == '\\') { // Found an escape character. if (index + 1 == end) { // If this is the last character. return true; } if (!isAllowedEscape(str.charAt(index + 1))) { // We did not allow this character to be escaped. return true; } index++; // Skip one extra.. } else if (checkThese.contains(str.charAt(index))) { // Found an illegal character. return true; } index++; } return false; }