List of usage examples for org.apache.commons.lang3 CharUtils isAsciiAlpha
public static boolean isAsciiAlpha(final char ch)
Checks whether the character is ASCII 7 bit alphabetic.
CharUtils.isAsciiAlpha('a') = true CharUtils.isAsciiAlpha('A') = true CharUtils.isAsciiAlpha('3') = false CharUtils.isAsciiAlpha('-') = false CharUtils.isAsciiAlpha('\n') = false CharUtils.isAsciiAlpha('©') = false From source file:com.qq.tars.validate.ConfigFileNameValidator.java
@Override public boolean isValid(String value, ConstraintValidatorContext context) { return StringUtils.isNotBlank(value) && StringUtils.isAlphanumeric(value) && CharUtils.isAsciiAlpha(value.charAt(0)); }
From source file:net.siegmar.japtproxy.packages.rpm.RpmPackageVersionComparator.java
/** * Returns the order for a single character. The order is digits, * then alpha, then non-ascii. If {@code pos} >= * {@code ca.length}, then the order is the same as for digits. * * @param ca the character array//from ww w. j a v a 2 s . c o m * @param pos the position in the character array * @return the order for the given character */ @Override protected int order(final char[] ca, final int pos) { if (pos >= ca.length) { return 0; } final char c = ca[pos]; return CharUtils.isAsciiNumeric(c) ? 0 : CharUtils.isAsciiAlpha(c) ? c : c + NON_ASCII_OFFSET; }
From source file:net.siegmar.japtproxy.packages.debian.DebianPackageVersionComparator.java
/** * Returns the order for a single character. The order is ~, then digits, * then alpha, then non-ascii. If {@code pos} >= * {@code ca.length}, then the order is the same as for digits. * * @param ca the character array/*from w w w.ja v a2 s.c o m*/ * @param pos the position in the character array * @return the order for the given character */ @Override protected int order(final char[] ca, final int pos) { if (pos >= ca.length) { return 0; } final char c = ca[pos]; return c == '~' ? -1 : CharUtils.isAsciiNumeric(c) ? 0 : CharUtils.isAsciiAlpha(c) ? c : c + NON_ASCII_OFFSET; }
From source file:com.google.api.tools.framework.importers.swagger.MultiSwaggerParser.java
/** * Generates API name in the form [hostname]_[version], with all non ASCII alphanumeric characters * replaced with '_'. Adds '_' at start if hostname is empty or starts with non alpha character, * since API names can only start with alpha or '_' *//*from w ww. j a v a 2s . c om*/ private static String generateApiName(String hostname, String version) { StringBuilder apiName = new StringBuilder(); if (hostname.isEmpty() || !CharUtils.isAsciiAlpha(hostname.charAt(0))) { apiName.append(API_NAME_FILLER_CHAR); } return apiName.append(stringToAlphanumeric(hostname)).append(API_NAME_FILLER_CHAR) .append(stringToAlphanumeric(version)).toString(); }
From source file:org.evosuite.junit.naming.variables.ExplanatoryNamingTestVisitor.java
/** * <p>/*from w ww . j a v a2 s. c o m*/ * getNumberString * </p> * * @param value * a {@link java.lang.Object} object. * @return a {@link java.lang.String} object. */ public static String getStringForPrimitiveValue(Object value) { assert (value != null); if (value.getClass().equals(char.class) || value.getClass().equals(Character.class)) { if (CharUtils.isAsciiNumeric((Character) value)) return "Numeric"; else if (CharUtils.isAsciiAlpha((Character) value)) return "Alpha"; else return "NotAlphanumeric"; } else if (value.getClass().equals(String.class)) { return ((String) value).isEmpty() ? "EmptyString" : "NonEmptyString"; } else if (value.getClass().equals(float.class) || value.getClass().equals(Float.class)) { if (value.toString().equals("" + Float.NaN)) return "NaN"; else if (value.toString().equals("" + Float.NEGATIVE_INFINITY)) return "NegativeInf"; else if (value.toString().equals("" + Float.POSITIVE_INFINITY)) return "PositiveInf"; else return (((Float) value) < 0F) ? "Negative" : (((Float) value) == 0F) ? "Zero" : "Positive"; } else if (value.getClass().equals(double.class) || value.getClass().equals(Double.class)) { if (value.toString().equals("" + Double.NaN)) return "NaN"; else if (value.toString().equals("" + Double.NEGATIVE_INFINITY)) return "NegativeInf"; else if (value.toString().equals("" + Double.POSITIVE_INFINITY)) return "PositiveInf"; else return (((Double) value) < 0.0) ? "Negative" : (((Double) value) == 0.0) ? "Zero" : "Positive"; } else if (value.getClass().equals(long.class) || value.getClass().equals(Long.class)) { return (((Long) value) < 0) ? "Negative" : (((Long) value) == 0) ? "Zero" : "Positive"; } else if (value.getClass().equals(byte.class) || value.getClass().equals(Byte.class)) { return (((Byte) value) < 0) ? "Negative" : (((Byte) value) == 0) ? "Zero" : "Positive"; } else if (value.getClass().equals(short.class) || value.getClass().equals(Short.class)) { return (((Short) value) < 0) ? "Negative" : (((Short) value) == 0) ? "Zero" : "Positive"; } else if (value.getClass().equals(int.class) || value.getClass().equals(Integer.class)) { int val = ((Integer) value).intValue(); if (val == Integer.MAX_VALUE) return "MaxInt"; else if (val == Integer.MIN_VALUE) return "MinInt"; else return (((Integer) value) < 0) ? "Negative" : (((Integer) value) == 0) ? "Zero" : "Positive"; } else if (value.getClass().isEnum() || value instanceof Enum) { return "EnumValue"; } else if (value.getClass().equals(Boolean.class)) { return capitalize(Boolean.toString((Boolean) value)); } else { // This should not happen assert (false); return value.toString(); } }
From source file:org.manalith.ircbot.plugin.keyseqconv.DubeolAutomataEngine.java
@Override public String parseKeySequenceToKorean(String keySequence) throws ParseException, IllegalArgumentException { String result = ""; LetterState stateFlag = LetterState.Null; String tICon = ""; String tIConLookahead = ""; String tIConLookaheadCombination = ""; String tVow = ""; String tVowLookahead = ""; String tVowLookaheadCombination = ""; String tFCon = ""; String tFConLookahead = ""; String tFConLookaheadCombination = ""; LetterObject syl = new LetterObject(KeyboardLayout.Dubeol); if (isEnableParsingExceptionSyntax() && StringUtils.countMatches(keySequence, "\\") % 2 == 1) throw new ParseException("Back slashes do not match", keySequence.lastIndexOf("\\", 0)); for (int i = 0; i < keySequence.length(); i++) { if (stateFlag.equals(LetterState.Null) || stateFlag.equals(LetterState.Finish)) { stateFlag = LetterState.IConsonant; }// w w w . j a v a 2s . c o m if (!CharUtils.isAsciiAlpha(keySequence.charAt(i))) { if (keySequence.charAt(i) == '\\' && isEnableParsingExceptionSyntax()) { if (i < keySequence.length() - 1) if (keySequence.charAt(i + 1) == '\\') { result += "\\"; continue; } i++; while (true) { if (i + 1 <= keySequence.length() - 1) { if (keySequence.charAt(i) == '\\') { if (keySequence.charAt(i + 1) == '\\') { i++; result += '\\'; } else break; } else { result += keySequence.charAt(i); } } else { if (keySequence.charAt(i) == '\\') { break; } else { result += keySequence.charAt(i); } } i++; } } else { result += keySequence.charAt(i); } continue; } // (??, ???) if (stateFlag.equals(LetterState.IConsonant)) { // ? tIConLookahead = tIConLookaheadCombination = ""; // ?? ? ? ? ? tICon = hasTwoSymbolinOneKey(keySequence.charAt(i)) ? Character.toString(keySequence.charAt(i)) : Character.toString(keySequence.charAt(i)).toLowerCase(); // ? ? if (i < keySequence.length() - 1) { // ?? ? ? ? ? tIConLookahead = hasTwoSymbolinOneKey(keySequence.charAt(i + 1)) ? Character.toString(keySequence.charAt(i + 1)) : Character.toString(keySequence.charAt(i + 1)).toLowerCase(); tIConLookaheadCombination = tICon + tIConLookahead; } // ??? ??? ?, ? ?. // ( , ? ) if (isFConsonant(tIConLookaheadCombination)) { // 2 step - lookahead try if (i + 2 <= keySequence.length() - 1) { String lookOverTwoStep = hasTwoSymbolinOneKey(keySequence.charAt(i + 2)) ? Character.toString(keySequence.charAt(i + 2)) : Character.toString(keySequence.charAt(i + 2)).toLowerCase(); // ?? ? , ?? ? ?, , ? if (isISingleConsonant(lookOverTwoStep) || isIDoubleConsonant(lookOverTwoStep) || !CharUtils.isAsciiAlpha(lookOverTwoStep.charAt(0))) { result += getSingleChar(getSingleCharVal(tIConLookaheadCombination)); i++; } // ?? ? ? else if (isVowel(lookOverTwoStep)) { // ??? ? ? result += getSingleChar(getSingleCharVal(tICon)); continue; } } // ? ? () ?? ? else { result += getSingleChar(getSingleCharVal(tIConLookaheadCombination)); stateFlag = LetterState.Null; break; } } // ???, ??? ( () ?? ) else { // ??? ? ? if (isISingleConsonant(tICon) || isIDoubleConsonant(tICon)) { syl.setIConsonant(tICon); // init = DubeolSymbol.DubeolIConsonant.valueOf(tICon); } // ?? ??? ? ? else if (isVowel(tICon)) { stateFlag = LetterState.Vowel; i--; continue; } // ? ? ? ?? ? if (i == keySequence.length() - 1) { result += getSingleChar(getSingleCharVal(tICon)); syl.initLetter(); stateFlag = LetterState.Null; break; } // ??? ? ? ?? ?? ? ? if (isVowel(tIConLookahead)) { stateFlag = LetterState.Vowel; continue; } // ??? ? else { result += getSingleChar(getSingleCharVal(tICon)); syl.initLetter(); } } } // (?) else if (stateFlag.equals(LetterState.Vowel)) { // ? tVowLookahead = tVowLookaheadCombination = ""; // ?? ? ? ? ? tVow = hasTwoSymbolinOneKey(keySequence.charAt(i)) ? Character.toString(keySequence.charAt(i)) : Character.toString(keySequence.charAt(i)).toLowerCase(); // ? ? if (i < keySequence.length() - 1) { // ?? ? ? ? ? tVowLookahead = hasTwoSymbolinOneKey(keySequence.charAt(i + 1)) ? Character.toString(keySequence.charAt(i + 1)) : Character.toString(keySequence.charAt(i + 1)).toLowerCase(); tVowLookaheadCombination = tVow + tVowLookahead; } // ?? ? if (isVowel(tVowLookaheadCombination)) { syl.setVowel(tVowLookaheadCombination); // vow = // DubeolSymbol.DubeolVowel.valueOf(tVowLookaheadCombination); // 2 step - lookahead try if (i + 2 <= keySequence.length() - 1) { // ?? ? ? ? ? String lookOverTwoStep = hasTwoSymbolinOneKey(keySequence.charAt(i + 2)) ? Character.toString(keySequence.charAt(i + 2)) : Character.toString(keySequence.charAt(i + 2)).toLowerCase(); i++; // ?? ?? ? ? ? , ? ?? ??? . // ?? ??? ? ? ? ? if (isVowel(lookOverTwoStep) || ((isISingleConsonant(lookOverTwoStep) || isIDoubleConsonant(lookOverTwoStep)) && !isFConsonant(lookOverTwoStep))) { stateFlag = LetterState.Finish; } // ?? ? ? ? ? , ex: else if (isFConsonant(lookOverTwoStep)) { if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVowLookaheadCombination)); stateFlag = LetterState.Null; } else { stateFlag = LetterState.FConsonant; continue; } } // ? ? else if (!CharUtils.isAsciiAlpha(lookOverTwoStep.charAt(0))) { if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVowLookaheadCombination)); syl.initLetter(); stateFlag = LetterState.Null; } else stateFlag = LetterState.Finish; } } // ? ? ? ? (? ) else { // ??? ? ? ? if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVowLookaheadCombination)); syl.initLetter(); i++; stateFlag = LetterState.Null; } else { stateFlag = LetterState.Finish; } // ?? ? ? if (i == keySequence.length() - 1) break; } } // ?? , ? ? else { // ?? if (isVowel(tVow)) { // ?? ? . if (!syl.isCompleteSyllable()) syl.setVowel(tVow); // ? ?? if (i == keySequence.length() - 1) { // ??? ? ? if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVow)); syl.initLetter(); stateFlag = LetterState.Null; } // ??? ? ? else { stateFlag = LetterState.Finish; } break; } // 2? ? ??? ?? // ?? ? ? ? delimiter // ? , ?, ? ? . if (!CharUtils.isAsciiAlpha(tVowLookahead.charAt(0))) { // ? ? ? . if (!syl.isCompleteSyllable()) { result += getSingleChar(getSingleCharVal(tVow)); syl.initLetter(); stateFlag = LetterState.IConsonant; continue; } else stateFlag = LetterState.Finish; } // *// ? ? ?. ? // ??? ? ? if (!syl.isCompleteSyllable()) { // ? ? result += getSingleChar(getSingleCharVal(tVow)); syl.initLetter(); // ?? ??? ?? if (isISingleConsonant(tVowLookahead) || isIDoubleConsonant(tVowLookahead)) stateFlag = LetterState.IConsonant; // ?? ? else if (isVowel(tVowLookahead)) stateFlag = LetterState.Vowel; continue; } else { // ?? + ? + : good! if (isFConsonant(tVowLookahead)) stateFlag = LetterState.FConsonant; // ??? ?? ? ? ? , : // ? ??? ? . else stateFlag = LetterState.Finish; } } } } // else if (stateFlag.equals(LetterState.FConsonant)) { // ? tFConLookahead = tFConLookaheadCombination = ""; // ?? ? ? ? ? tFCon = hasTwoSymbolinOneKey(keySequence.charAt(i)) ? Character.toString(keySequence.charAt(i)) : Character.toString(keySequence.charAt(i)).toLowerCase(); // ? ? if (i < keySequence.length() - 1) { tFConLookahead = hasTwoSymbolinOneKey(keySequence.charAt(i + 1)) ? Character.toString(keySequence.charAt(i + 1)) : Character.toString(keySequence.charAt(i + 1)).toLowerCase(); tFConLookaheadCombination = tFCon + tFConLookahead; } stateFlag = LetterState.Finish; // ? ? ? ??. // ???? if (isFConsonant(tFConLookaheadCombination)) { // 2 step - lookahead try if (i + 2 <= keySequence.length() - 1) { String lookOverTwoStep = hasTwoSymbolinOneKey(keySequence.charAt(i)) ? Character.toString(keySequence.charAt(i + 2)) : Character.toString(keySequence.charAt(i + 2)).toLowerCase(); // () ??? ??? ? if (isISingleConsonant(lookOverTwoStep) || isIDoubleConsonant(lookOverTwoStep) || !CharUtils.isAsciiAlpha(lookOverTwoStep.charAt(0))) { // ? ? . ??? syl.setFConsonant(tFConLookaheadCombination); i++; // ?? ? ? . , ?? + ? } else if (isVowel(lookOverTwoStep)) syl.setFConsonant(tFCon); } else { // ? ?? ?? ? ??. if (isFConsonant(tFConLookaheadCombination)) { syl.setFConsonant(tFConLookaheadCombination); } break; } } else { // ?? ? ??? ? ? . if (isFConsonant(tFCon)) syl.setFConsonant(tFCon); // ? ???? ??. if (i == keySequence.length() - 1) break; // ? ? ?? backtracking. // ? ? if (isVowel(tFConLookahead)) { syl.setFConsonant("nul"); stateFlag = LetterState.Finish; i--; } } } // ? ? ? ? ?? if (stateFlag == LetterState.Finish) { result += syl.getLetter(); syl.initLetter(); } } // . if (stateFlag == LetterState.Finish) result += syl.getLetter(); return result; }
From source file:uk.gov.gchq.gaffer.graphql.definitions.DataTypeGQLBuilder.java
/** * Strip out any non alpha characters/*from w ww. j a va 2 s.c o m*/ * * @param input The non safe string from the Gaffer Schema * @return A safe version of the string for GraphQL */ private static String getSafeName(final String input) { final StringBuilder output = new StringBuilder(); for (final char c : input.toCharArray()) { if (CharUtils.isAsciiAlpha(c)) { output.append(c); } } return output.toString(); }