List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:org.janusgraph.graphdb.database.IndexSerializer.java
public Iterable<RawQuery.Result> executeQuery(IndexQueryBuilder query, final ElementCategory resultType, final BackendTransaction backendTx, final StandardJanusGraphTx transaction) { MixedIndexType index = getMixedIndex(query.getIndex(), transaction); Preconditions.checkArgument(index.getElement() == resultType, "Index is not configured for the desired result type: %s", resultType); String backingIndexName = index.getBackingIndexName(); IndexProvider indexInformation = (IndexProvider) mixedIndexes.get(backingIndexName); StringBuffer qB = new StringBuffer(query.getQuery()); final String prefix = query.getPrefix(); Preconditions.checkNotNull(prefix);/* w w w.ja va 2s . c o m*/ //Convert query string by replacing int replacements = 0; int pos = 0; while (pos < qB.length()) { pos = qB.indexOf(prefix, pos); if (pos < 0) break; int startPos = pos; pos += prefix.length(); StringBuilder keyBuilder = new StringBuilder(); boolean quoteTerminated = qB.charAt(pos) == '"'; if (quoteTerminated) pos++; while (pos < qB.length() && (Character.isLetterOrDigit(qB.charAt(pos)) || (quoteTerminated && qB.charAt(pos) != '"') || qB.charAt(pos) == '*')) { keyBuilder.append(qB.charAt(pos)); pos++; } if (quoteTerminated) pos++; int endPos = pos; String keyname = keyBuilder.toString(); Preconditions.checkArgument(StringUtils.isNotBlank(keyname), "Found reference to empty key at position [%s]", startPos); String replacement; if (keyname.equals("*")) { replacement = indexInformation.getFeatures().getWildcardField(); } else if (transaction.containsRelationType(keyname)) { PropertyKey key = transaction.getPropertyKey(keyname); Preconditions.checkNotNull(key); Preconditions.checkArgument(index.indexesKey(key), "The used key [%s] is not indexed in the targeted index [%s]", key.name(), query.getIndex()); replacement = key2Field(index, key); } else { Preconditions.checkArgument(query.getUnknownKeyName() != null, "Found reference to non-existant property key in query at position [%s]: %s", startPos, keyname); replacement = query.getUnknownKeyName(); } Preconditions.checkArgument(StringUtils.isNotBlank(replacement)); qB.replace(startPos, endPos, replacement); pos = startPos + replacement.length(); replacements++; } String queryStr = qB.toString(); if (replacements <= 0) log.warn("Could not convert given {} index query: [{}]", resultType, query.getQuery()); log.info("Converted query string with {} replacements: [{}] => [{}]", replacements, query.getQuery(), queryStr); RawQuery rawQuery = new RawQuery(index.getStoreName(), queryStr, query.getParameters()); if (query.hasLimit()) rawQuery.setLimit(query.getLimit()); rawQuery.setOffset(query.getOffset()); return Iterables.transform(backendTx.rawQuery(index.getBackingIndexName(), rawQuery), new Function<RawQuery.Result<String>, RawQuery.Result>() { @Nullable @Override public RawQuery.Result apply(@Nullable RawQuery.Result<String> result) { return new RawQuery.Result(string2ElementId(result.getResult()), result.getScore()); } }); }
From source file:org.jivesoftware.community.util.StringUtils.java
public static boolean containsNonAlphanumeric(String str) { char testChars[] = str.toCharArray(); char arr$[] = testChars; int len$ = arr$.length; for (int i$ = 0; i$ < len$; i$++) { char testChar = arr$[i$]; if (!Character.isLetterOrDigit(testChar)) return true; }//from ww w . j av a 2 s. c o m return false; }
From source file:de.acosix.alfresco.mtsupport.repo.auth.ldap.EnhancedLDAPUserRegistry.java
/** * Works around a bug in the JDK DN parsing. If an RDN has trailing escaped whitespace in the format "\\20" then * LdapName would normally strip this. This method works around this by replacing "\\20" with "\\ " and "\\0D" with * "\\\r"./*from w ww . j a va 2s .c om*/ * * @param dn * the DN * @return the parsed ldap name * @throws InvalidNameException * if the DN is invalid */ protected static LdapName fixedLdapName(final String dn) throws InvalidNameException { // Optimization for DNs without escapes in them if (dn.indexOf('\\') == -1) { return new LdapName(dn); } final StringBuilder fixed = new StringBuilder(dn.length()); final int length = dn.length(); for (int i = 0; i < length; i++) { final char c = dn.charAt(i); char c1, c2; if (c == '\\') { if (i + 2 < length && Character.isLetterOrDigit(c1 = dn.charAt(i + 1)) && Character.isLetterOrDigit(c2 = dn.charAt(i + 2))) { if (c1 == '2' && c2 == '0') { fixed.append("\\ "); } else if (c1 == '0' && c2 == 'D') { fixed.append("\\\r"); } else { fixed.append(dn, i, i + 3); } i += 2; } else if (i + 1 < length) { fixed.append(dn, i, i + 2); i += 1; } else { fixed.append(c); } } else { fixed.append(c); } } return new LdapName(fixed.toString()); }
From source file:plugin.notes.gui.NotesView.java
private void handleEnter() { // TODO: this sucks. clean it up Element elem;/* w ww. j a v a 2 s . c o m*/ int pos = editor.getCaretPosition(); ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) editor.getStyledDocument(); try { if (ExtendedHTMLEditorKit.checkParentsTag(htmlDoc.getParagraphElement(editor.getCaretPosition()), HTML.Tag.UL) || ExtendedHTMLEditorKit.checkParentsTag(htmlDoc.getParagraphElement(editor.getCaretPosition()), HTML.Tag.OL)) { elem = ExtendedHTMLEditorKit .getListItemParent(htmlDoc.getCharacterElement(editor.getCaretPosition())); int so = elem.getStartOffset(); int eo = elem.getEndOffset(); char[] temp = editor.getText(so, eo - so).toCharArray(); boolean content = false; for (char aTemp : temp) { if (!Character.isWhitespace(aTemp)) { content = true; } } int repos = -1; if (content) { int end = -1; int j = temp.length; do { j--; if (Character.isLetterOrDigit(temp[j])) { end = j; } } while ((end == -1) && (j >= 0)); j = end; do { j++; if (!Character.isSpaceChar(temp[j])) { repos = j - end - 1; } } while ((repos == -1) && (j < temp.length)); if (repos == -1) { repos = 0; } } if ((elem.getStartOffset() == elem.getEndOffset()) || !content) { manageListElement(htmlDoc); } else { if ((editor.getCaretPosition() + 1) == elem.getEndOffset()) { ExtendedHTMLEditorKit.insertListElement(editor, ""); editor.setCaretPosition(pos - repos); } else { int caret = editor.getCaretPosition(); String tempString = editor.getText(caret, eo - caret); editor.select(caret, eo - 1); editor.replaceSelection(""); ExtendedHTMLEditorKit.insertListElement(editor, tempString); Element newLi = ExtendedHTMLEditorKit .getListItemParent(htmlDoc.getCharacterElement(editor.getCaretPosition())); editor.setCaretPosition(newLi.getEndOffset()); } } } } catch (BadLocationException ble) { Logging.errorPrint(ble.getMessage(), ble); } }
From source file:com.adito.boot.Util.java
static String simplePatternToRegExp(String simplePattern) { int c = simplePattern.length(); char ch;/* w ww. ja va 2 s .c o m*/ StringBuffer buf = new StringBuffer(); for (int i = 0; i < c; i++) { ch = simplePattern.charAt(i); if (Character.isLetterOrDigit(ch)) { buf.append(ch); } else if (ch == '*') { buf.append(".*"); } else if (ch == '?') { buf.append(".?"); } else { buf.append("\\"); buf.append(ch); } } return buf.toString(); }
From source file:au.org.ala.delta.util.Utils.java
/** * Capitalises the first word in the supplied text (which may contain RTF * markup) the first letter of the word is preceded by a '|'. * //from w w w.j a v a 2s . c o m * @param text * the text to capitalise. * @return the text with the first word capitalised. */ public static String capitaliseFirstWord(String text) { if (StringUtils.isEmpty(text)) { return text; } StringBuilder tmp = new StringBuilder(); tmp.append(text); int index = 0; while (index >= 0 && index < text.length() && !Character.isLetterOrDigit(tmp.charAt(index))) { if (tmp.charAt(index) == '\\') { index = RTFUtils.skipKeyword(text, index); if (index < 0 || index >= tmp.length() || Character.isLetterOrDigit(tmp.charAt(index))) { break; } } index++; } if (index >= 0 && index < text.length() && Character.isLetter(tmp.charAt(index))) { if ((index == 0) || (tmp.charAt(index - 1) != '|')) { tmp.setCharAt(index, Character.toUpperCase(tmp.charAt(index))); } else if (tmp.charAt(index - 1) == '|') { tmp.deleteCharAt(index - 1); } } return tmp.toString(); }
From source file:org.apache.hadoop.hive.metastore.MetaStoreUtils.java
/** * Convert type to ThriftType. We do that by tokenizing the type and convert * each token.// w w w. j a v a 2s . co m */ public static String typeToThriftType(String type) { StringBuilder thriftType = new StringBuilder(); int last = 0; boolean lastAlphaDigit = Character.isLetterOrDigit(type.charAt(last)); for (int i = 1; i <= type.length(); i++) { if (i == type.length() || Character.isLetterOrDigit(type.charAt(i)) != lastAlphaDigit) { String token = type.substring(last, i); last = i; String thriftToken = typeToThriftTypeMap.get(token); thriftType.append(thriftToken == null ? token : thriftToken); lastAlphaDigit = !lastAlphaDigit; } } return thriftType.toString(); }
From source file:net.minecraftforge.common.config.Configuration.java
public void load() { if (PARENT != null && PARENT != this) { return;/*from ww w . j a v a 2 s . c o m*/ } BufferedReader buffer = null; UnicodeInputStreamReader input = null; try { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } if (!file.exists()) { // Either a previous load attempt failed or the file is new; clear maps categories.clear(); children.clear(); if (!file.createNewFile()) return; } if (file.canRead()) { input = new UnicodeInputStreamReader(new FileInputStream(file), defaultEncoding); defaultEncoding = input.getEncoding(); buffer = new BufferedReader(input); String line; ConfigCategory currentCat = null; Property.Type type = null; ArrayList<String> tmpList = null; int lineNum = 0; String name = null; loadedConfigVersion = null; while (true) { lineNum++; line = buffer.readLine(); if (line == null) { if (lineNum == 1) loadedConfigVersion = definedConfigVersion; break; } Matcher start = CONFIG_START.matcher(line); Matcher end = CONFIG_END.matcher(line); if (start.matches()) { fileName = start.group(1); categories = new TreeMap<String, ConfigCategory>(); continue; } else if (end.matches()) { fileName = end.group(1); Configuration child = new Configuration(); child.categories = categories; this.children.put(fileName, child); continue; } int nameStart = -1, nameEnd = -1; boolean skip = false; boolean quoted = false; boolean isFirstNonWhitespaceCharOnLine = true; for (int i = 0; i < line.length() && !skip; ++i) { if (Character.isLetterOrDigit(line.charAt(i)) || ALLOWED_CHARS.indexOf(line.charAt(i)) != -1 || (quoted && line.charAt(i) != '"')) { if (nameStart == -1) { nameStart = i; } nameEnd = i; isFirstNonWhitespaceCharOnLine = false; } else if (Character.isWhitespace(line.charAt(i))) { // ignore space characters } else { switch (line.charAt(i)) { case '#': if (tmpList != null) // allow special characters as part of string lists break; skip = true; continue; case '"': if (tmpList != null) // allow special characters as part of string lists break; if (quoted) { quoted = false; } if (!quoted && nameStart == -1) { quoted = true; } break; case '{': if (tmpList != null) // allow special characters as part of string lists break; name = line.substring(nameStart, nameEnd + 1); if (!caseSensitiveCustomCategories) name = name.toLowerCase(Locale.ENGLISH); String qualifiedName = ConfigCategory.getQualifiedName(name, currentCat); ConfigCategory cat = categories.get(qualifiedName); if (cat == null) { currentCat = new ConfigCategory(name, currentCat); categories.put(qualifiedName, currentCat); } else { currentCat = cat; } name = null; break; case '}': if (tmpList != null) // allow special characters as part of string lists break; if (currentCat == null) { throw new RuntimeException(String.format( "Config file corrupt, attempted to close to many categories '%s:%d'", fileName, lineNum)); } currentCat = currentCat.parent; break; case '=': if (tmpList != null) // allow special characters as part of string lists break; name = line.substring(nameStart, nameEnd + 1); if (currentCat == null) { throw new RuntimeException( String.format("'%s' has no scope in '%s:%d'", name, fileName, lineNum)); } Property prop = new Property(name, line.substring(i + 1), type, true); i = line.length(); currentCat.put(name, prop); break; case ':': if (tmpList != null) // allow special characters as part of string lists break; type = Property.Type.tryParse(line.substring(nameStart, nameEnd + 1).charAt(0)); nameStart = nameEnd = -1; break; case '<': if ((tmpList != null && i + 1 == line.length()) || (tmpList == null && i + 1 != line.length())) { throw new RuntimeException( String.format("Malformed list property \"%s:%d\"", fileName, lineNum)); } else if (i + 1 == line.length()) { name = line.substring(nameStart, nameEnd + 1); if (currentCat == null) { throw new RuntimeException(String.format("'%s' has no scope in '%s:%d'", name, fileName, lineNum)); } tmpList = new ArrayList<String>(); skip = true; } break; case '>': if (tmpList == null) { throw new RuntimeException( String.format("Malformed list property \"%s:%d\"", fileName, lineNum)); } if (isFirstNonWhitespaceCharOnLine) { currentCat.put(name, new Property(name, tmpList.toArray(new String[tmpList.size()]), type)); name = null; tmpList = null; type = null; } // else allow special characters as part of string lists break; case '~': if (tmpList != null) // allow special characters as part of string lists break; if (line.startsWith(CONFIG_VERSION_MARKER)) { int colon = line.indexOf(':'); if (colon != -1) loadedConfigVersion = line.substring(colon + 1).trim(); skip = true; } break; default: if (tmpList != null) // allow special characters as part of string lists break; throw new RuntimeException(String.format("Unknown character '%s' in '%s:%d'", line.charAt(i), fileName, lineNum)); } isFirstNonWhitespaceCharOnLine = false; } } if (quoted) { throw new RuntimeException(String.format("Unmatched quote in '%s:%d'", fileName, lineNum)); } else if (tmpList != null && !skip) { tmpList.add(line.trim()); } } } } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(buffer); IOUtils.closeQuietly(input); } resetChangedState(); }
From source file:org.jivesoftware.community.util.StringUtils.java
public static boolean isWebSafeString(String str, String otherSafeCharacters) { if (str == null) throw new NullPointerException("String to be tested cannot be null"); int sz = str.length(); for (int i = 0; i < sz; i++) { char iChar = str.charAt(i); if (Character.isLetterOrDigit(iChar) || Character.isSpaceChar(iChar)) continue; boolean found = false; int j = 0; do {/*from w ww . j a va 2 s . c o m*/ if (j >= otherSafeCharacters.length()) break; char other = otherSafeCharacters.charAt(j); if (other == iChar) { found = true; break; } j++; } while (true); if (!found) return false; } return true; }
From source file:org.renjin.parser.RLexer.java
private int consumeSymbolValue(int c) { StringBuffer buffer = new StringBuffer(); do {// w ww .ja va2 s .c o m buffer.appendCodePoint(c); } while ((c = xxgetc()) != R_EOF && (Character.isLetterOrDigit(c) || c == '.' || c == '_')); xxungetc(c); int keyword; if ((keyword = lookupKeyword(buffer.toString())) != 0) { if (keyword == FUNCTION) { parseState.getFunctionSource().descend(); } return keyword; } yylval = Symbol.get(buffer.toString()); return SYMBOL; }