List of usage examples for org.apache.commons.lang3 CharUtils isAsciiAlphanumeric
public static boolean isAsciiAlphanumeric(final char ch)
Checks whether the character is ASCII 7 bit numeric.
CharUtils.isAsciiAlphanumeric('a') = true CharUtils.isAsciiAlphanumeric('A') = true CharUtils.isAsciiAlphanumeric('3') = true CharUtils.isAsciiAlphanumeric('-') = false CharUtils.isAsciiAlphanumeric('\n') = false CharUtils.isAsciiAlphanumeric('©') = false From source file:com.norconex.commons.lang.file.FileUtil.java
/** * Converts any String to a valid file-system file name representation. The * valid file name is constructed so it can be written to virtually any * operating system.//from w w w . j a va2 s . c o m * Use {@link #fromSafeFileName(String)} to get back the original name. * @param unsafeFileName the file name to make safe. * @return valid file name */ public static String toSafeFileName(String unsafeFileName) { if (unsafeFileName == null) { return null; } StringBuilder b = new StringBuilder(); for (int i = 0; i < unsafeFileName.length(); i++) { char ch = unsafeFileName.charAt(i); if (CharUtils.isAsciiAlphanumeric(ch) || ch == '-' || ch == '.') { b.append(ch); } else { b.append('_'); b.append((int) ch); b.append('_'); } } return b.toString(); }
From source file:com.google.api.tools.framework.importers.swagger.MultiSwaggerParser.java
/** Replaces all non alphanumeric characters in input string with '_' */ private static String stringToAlphanumeric(String input) { StringBuilder alphaNumeric = new StringBuilder(); for (char hostnameChar : input.toCharArray()) { if (CharUtils.isAsciiAlphanumeric(hostnameChar)) { alphaNumeric.append(hostnameChar); } else {/*from w w w. ja v a 2 s . co m*/ alphaNumeric.append(API_NAME_FILLER_CHAR); } } return alphaNumeric.toString(); }
From source file:net.tachtler.browscap4j.Browscap4jFileReader.java
/** * Format the given String to a Java regular expression formatted String. * //from w w w .j a v a 2 s.co m * @param regexPattern * @return regexPattern formatted String */ private static String convertToRegex(String regexPattern) { StringBuffer stringBuffer = new StringBuffer(); /* * Add the regular expression anchor at the beginning of the line. */ stringBuffer.append("^"); /* * Convert char by char by following rule set. */ for (final char c : regexPattern.toCharArray()) { switch (c) { case '*': stringBuffer.append(".*?"); break; case '?': stringBuffer.append("."); break; default: if (CharUtils.isAsciiAlphanumeric(c) || c == ' ') { stringBuffer.append(c); } else { stringBuffer.append("\\").append(c); } } } /* * Add the regular expression anchor at the end of the line. */ stringBuffer.append("$"); return stringBuffer.toString().toLowerCase(); }
From source file:org.cryptomator.ui.controllers.UnlockController.java
private void filterAlphanumericKeyEvents(KeyEvent t) { if (t.getCharacter() == null || t.getCharacter().length() == 0) { return;/*ww w . j a va 2 s .co m*/ } char c = CharUtils.toChar(t.getCharacter()); if (!(CharUtils.isAsciiAlphanumeric(c) || c == '_')) { t.consume(); } }
From source file:org.cryptomator.ui.InitializeController.java
public void filterAlphanumericKeyEvents(KeyEvent t) { if (t.getCharacter() == null || t.getCharacter().length() == 0) { return;//from www . j ava 2 s .c o m } char c = t.getCharacter().charAt(0); if (!CharUtils.isAsciiAlphanumeric(c)) { t.consume(); } }
From source file:org.xlrnet.tibaija.processor.ExecutionEnvironment.java
/** * Register a command as an expression function in the execution environment. All programs and other commands can * use the new function once it has been registered. Every command may only be associated with at most one execution * environment. If a command is registered as a function expression (i.e. through this function) it can be used in * or as an expression and must return a value. * * @param commandName/*w w w .j a v a2s . co m*/ * Name of the new command under which it can be accessed. * @param command * An instance of the concrete command. */ public void registerExpressionFunction(@NotNull String commandName, @NotNull Command command) throws TIRuntimeException { checkNotNull(commandName); checkNotNull(command); checkArgument(StringUtils.isNotBlank(commandName), "Expression function name may not be blank"); Character firstChar = commandName.charAt(0); checkArgument(CharUtils.isAsciiAlphaLower(firstChar) || !CharUtils.isAsciiAlphanumeric(firstChar), "Expression function name must begin with a lowercase letter or be non-alphanumeric"); if (expressionFunction.get(commandName) != null) throw new DuplicateCommandException("Function expression name is already registered: " + commandName); if (command.getEnvironment() != null) throw new DuplicateCommandException( "New command instance is already registered in another environment"); command.setEnvironment(this); expressionFunction.put(commandName, command); LOGGER.debug("Registered new expression function '{}'", commandName); }