List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:piramide.multimodal.applicationserver.rest.DirectoriesManager.java
private boolean needsToBeEncoded(final String arg) { boolean needsToBeEncoded = false; for (char c : arg.toCharArray()) if (!Character.isLetterOrDigit(c) && c != '.' && c != '_' && c != '-') needsToBeEncoded = true;/*from w w w . j av a 2s .c o m*/ return needsToBeEncoded; }
From source file:org.wisdom.test.internals.RunnerUtils.java
/** * Get the symbolic name as groupId + "." + artifactId, with the following exceptions. Unlike the original method * from the Maven Bundle Plugin, this method does not use the bundle inspection, * as the artifact's file does not exist when this method is called. * <ul>// w w w .ja v a 2 s .c om * <li>if artifactId is equal to last section of groupId then groupId is returned. eg. * org.apache.maven:maven -> org.apache.maven</li> * <li>if artifactId starts with last section of groupId that portion is removed. eg. * org.apache.maven:maven-core -> org.apache.maven.core</li> * <li>if artifactId starts with groupId then the artifactId is removed. eg. * org.apache:org.apache.maven.core -> org.apache.maven.core</li> * </ul> * * @param groupId the groupId * @param artifactId the artifactId * @return the symbolic name for the given artifact coordinates */ public static String getBundleSymbolicName(String groupId, String artifactId) { int i = groupId.lastIndexOf('.'); String lastSection = groupId.substring(++i); if (artifactId.equals(lastSection)) { return groupId; } if (artifactId.equals(groupId) || artifactId.startsWith(groupId + ".")) { return artifactId; } if (artifactId.startsWith(lastSection)) { artifactId = artifactId.substring(lastSection.length()); if (!Character.isLetterOrDigit(artifactId.charAt(0))) { return (groupId + "." + artifactId.substring(1)).replace("-", "."); } // Else fall to the default case. } return (groupId + "." + artifactId).replace("-", "."); }
From source file:opennlp.tools.textsimilarity.TextProcessor.java
public static boolean isStringAllPunc(String token) { for (int i = 0; i < token.length(); i++) { if (Character.isLetterOrDigit(token.charAt(i))) { return false; }// w ww . j ava 2s .com } return true; }
From source file:com.google.dart.engine.services.refactoring.NamingConventions.java
private static RefactoringStatus validateIdentifier0(String identifier, String identifierName) { // has leading/trailing spaces String trimmed = identifier.trim(); if (!identifier.equals(trimmed)) { String message = MessageFormat.format("{0} must not start or end with a blank.", identifierName); return RefactoringStatus.createErrorStatus(message); }//from w w w .j av a 2 s .c o m // empty int length = identifier.length(); if (length == 0) { String message = MessageFormat.format("{0} must not be empty.", identifierName); return RefactoringStatus.createErrorStatus(message); } char currentChar = identifier.charAt(0); if (!Character.isLetter(currentChar) && currentChar != '_') { String message = MessageFormat.format("{0} must not start with ''{1}''.", identifierName, currentChar); return RefactoringStatus.createErrorStatus(message); } for (int i = 1; i < length; i++) { currentChar = identifier.charAt(i); if (!Character.isLetterOrDigit(currentChar) && currentChar != '_') { String message = MessageFormat.format("{0} must not contain ''{1}''.", identifierName, currentChar); return RefactoringStatus.createErrorStatus(message); } } return new RefactoringStatus(); }
From source file:org.apache.qpid.server.security.access.config.RuleSet.java
/** Return true if the name is well-formed (contains legal characters). */ protected boolean checkName(String name) { for (int i = 0; i < name.length(); i++) { Character c = name.charAt(i); if (!Character.isLetterOrDigit(c) && c != '-' && c != '_' && c != '@' && c != '.' && c != '/') { return false; }/*ww w .j av a 2s. c o m*/ } return true; }
From source file:com.unboundid.scim2.common.utils.Parser.java
/** * Read a path token. A token is either: * <ul>//from ww w .j av a 2s .c o m * <li> * An attribute name terminated by a period. * </li> * <li> * An attribute name terminated by an opening brace. * </li> * <li> * </ul> * * @param reader The reader to read from. * * @return The token at the current position, or {@code null} if the end of * the input has been reached. * @throws BadRequestException If the path string could not be parsed. */ private static String readPathToken(final StringReader reader) throws BadRequestException { reader.mark(0); int c = reader.read(); StringBuilder b = new StringBuilder(); while (c > 0) { if (c == '.') { if (reader.pos >= reader.string.length()) { // There is nothing after the period. throw BadRequestException.invalidPath("Unexpected end of path string"); } // Terminating period. Consume it and return token. return b.toString(); } if (c == '[') { // Terminating opening brace. Consume it and return token. b.append((char) c); return b.toString(); } if (c == '-' || c == '_' || c == '$' || Character.isLetterOrDigit(c)) { b.append((char) c); } else { final String msg = String.format( "Unexpected character '%s' at position %d for token starting at %d", (char) c, reader.pos - 1, reader.mark); throw BadRequestException.invalidPath(msg); } c = reader.read(); } if (b.length() > 0) { return b.toString(); } return null; }
From source file:com.floreantpos.util.StringUtils.java
/** * Perform a series of substitutions. The substitions * are performed by replacing $variable in the target * string with the value of provided by the key "variable" * in the provided hashtable.//from ww w .j a v a2s . co m * * @param argStr target string * @param vars name/value pairs used for substitution * @return String target string with replacements. */ public static StringBuffer stringSubstitution(String argStr, Map vars) { StringBuffer argBuf = new StringBuffer(); for (int cIdx = 0; cIdx < argStr.length();) { char ch = argStr.charAt(cIdx); switch (ch) { case '$': StringBuilder nameBuf = new StringBuilder(); for (++cIdx; cIdx < argStr.length(); ++cIdx) { ch = argStr.charAt(cIdx); if (ch == '_' || Character.isLetterOrDigit(ch)) nameBuf.append(ch); else break; } if (nameBuf.length() > 0) { String value = (String) vars.get(nameBuf.toString()); if (value != null) { argBuf.append(value); } } break; default: argBuf.append(ch); ++cIdx; break; } } return argBuf; }
From source file:bboss.org.apache.velocity.util.StringUtils.java
/** * Perform a series of substitutions. The substitions * are performed by replacing $variable in the target * string with the value of provided by the key "variable" * in the provided hashtable./*from w ww. j av a 2 s. com*/ * * @param argStr target string * @param vars name/value pairs used for substitution * @return String target string with replacements. */ public static StringBuffer stringSubstitution(String argStr, Map vars) { StringBuffer argBuf = new StringBuffer(); for (int cIdx = 0; cIdx < argStr.length();) { char ch = argStr.charAt(cIdx); switch (ch) { case '$': StringBuffer nameBuf = new StringBuffer(); for (++cIdx; cIdx < argStr.length(); ++cIdx) { ch = argStr.charAt(cIdx); if (ch == '_' || Character.isLetterOrDigit(ch)) nameBuf.append(ch); else break; } if (nameBuf.length() > 0) { String value = (String) vars.get(nameBuf.toString()); if (value != null) { argBuf.append(value); } } break; default: argBuf.append(ch); ++cIdx; break; } } return argBuf; }
From source file:net.sourceforge.squirrel_sql.fw.util.StringUtilities.java
public static String javaNormalize(String text) { StringBuffer buf = new StringBuffer(text.length()); if (Character.isJavaIdentifierStart(text.charAt(0))) { buf.append(text.charAt(0));//from w ww .jav a 2 s. c om } else { buf.append('_'); } for (int i = 1; i < text.length(); ++i) { if (Character.isLetterOrDigit(text.charAt(i))) { buf.append(text.charAt(i)); } else { buf.append('_'); } } String ret = buf.toString(); return ret; }
From source file:org.scilla.core.CacheManager.java
private static String fnEncodeCharacters(String in) { // encode this to a legal filename StringBuffer out = new StringBuffer(); char[] data = in.toCharArray(); for (int i = 0; i < data.length; i++) { if (Character.isLetterOrDigit(data[i])) { out.append(data[i]);/*from www. j a va 2s .c o m*/ } else { out.append("_" + (int) data[i]); } } return out.toString(); }