List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:org.sd.token.StandardTokenizerOptions.java
public boolean isLetterOrDigit(int codePoint) { boolean result = Character.isLetterOrDigit(codePoint); if (!result && symbolDigitsCodePoints != null) { result = symbolDigitsCodePoints.contains(codePoint); }/*from ww w. jav a 2s . c om*/ if (!result && symbolUppersCodePoints != null) { result = symbolUppersCodePoints.contains(codePoint); } if (!result && symbolLowersCodePoints != null) { result = symbolLowersCodePoints.contains(codePoint); } return result; }
From source file:org.eclipse.orion.server.useradmin.servlets.UserHandlerV1.java
/** * Validates that the provided login is valid. Login must consistent of alphanumeric characters only for now. * @return <code>null</code> if the login is valid, and otherwise a string message stating the reason * why it is not valid./*from www. j ava 2 s . c o m*/ */ private String validateLogin(String login, boolean isGuest) { if (login == null || login.length() == 0) return "User login not specified"; int length = login.length(); if (length < USERNAME_MIN_LENGTH) return NLS.bind("Username must contain at least {0} characters", USERNAME_MIN_LENGTH); if (length > USERNAME_MAX_LENGTH) return NLS.bind("Username must contain no more than {0} characters", USERNAME_MAX_LENGTH); if (login.equals("ultramegatron")) return "Nice try, Mark"; // Guest usernames can contain a few special characters (eg. +, /) if (!isGuest) { for (int i = 0; i < length; i++) { if (!Character.isLetterOrDigit(login.charAt(i))) return NLS.bind("Username {0} contains invalid character ''{1}''", login, login.charAt(i)); } } return null; }
From source file:org.curriki.xwiki.plugin.lucene.ResourcesSearchCursor.java
public String getShortTokenizedDescription() { String r = currentDoc.get("CurrikiCode.AssetClass.description"); if (r == null) return ""; StringBuffer buff = new StringBuffer(Math.min(100, r.length())); for (int i = 0, l = r.length(); i < l; i++) { char c = r.charAt(i); if (Character.isWhitespace(c)) { buff.append(" "); } else if (Character.isLetterOrDigit(c)) buff.append(c);//from www. j ava2 s . co m if (buff.length() >= 100) { buff.append("..."); break; } } return buff.toString(); }
From source file:com.cohort.util.String2.java
/** * This goes beyond indexOfIgnoreCase by looking after punctuation removed. * * @param s/*from w ww. ja v a 2 s . c o m*/ * @param find * @return true if find is loosely in s. Return false if s or find !isSomething. */ public static boolean looselyContains(String s, String find) { if (s == null || find == null) return false; int sLength = s.length(); StringBuilder ssb = new StringBuilder(); for (int i = 0; i < sLength; i++) { char ch = s.charAt(i); if (Character.isLetterOrDigit(ch)) ssb.append(Character.toLowerCase(ch)); } if (ssb.length() == 0) return false; int fLength = find.length(); StringBuilder fsb = new StringBuilder(); for (int i = 0; i < fLength; i++) { char ch = find.charAt(i); if (Character.isLetterOrDigit(ch)) fsb.append(Character.toLowerCase(ch)); } if (fsb.length() == 0) return false; return ssb.indexOf(fsb.toString()) >= 0; }
From source file:forge.quest.QuestUtil.java
/** Duplicate in DeckEditorQuestMenu and * probably elsewhere...can streamline at some point * (probably shouldn't be here)./* w w w . j a va 2 s . com*/ * * @param in   {@link java.lang.String} * @return {@link java.lang.String} */ public static String cleanString(final String in) { final StringBuilder out = new StringBuilder(); final char[] c = in.toCharArray(); for (final char aC : c) { if (Character.isLetterOrDigit(aC) || (aC == '-') || (aC == '_') || (aC == ' ')) { out.append(aC); } } return out.toString(); }
From source file:net.sf.jabref.gui.maintable.MainTableSelectionListener.java
/** * Receive key event on the main table. If the key is a letter or a digit, * we should select the first entry in the table which starts with the given * letter in the column by which the table is sorted. * @param e The KeyEvent/*w w w .j a va 2s . c o m*/ */ @Override public void keyTyped(KeyEvent e) { if ((!e.isActionKey()) && Character.isLetterOrDigit(e.getKeyChar()) && (e.getModifiers() == 0)) { long time = System.currentTimeMillis(); final long QUICK_JUMP_TIMEOUT = 2000; if ((time - lastPressedTime) > QUICK_JUMP_TIMEOUT) { lastPressedCount = 0; // Reset last pressed character } // Update timestamp: lastPressedTime = time; // Add the new char to the search array: int c = e.getKeyChar(); if (lastPressedCount < lastPressed.length) { lastPressed[lastPressedCount] = c; lastPressedCount++; } int sortingColumn = table.getSortingColumn(0); if (sortingColumn == -1) { return; // No sorting? TODO: look up by author, etc.? } // TODO: the following lookup should be done by a faster algorithm, // such as binary search. But the table may not be sorted properly, // due to marked entries, search etc., which rules out the binary search. for (int i = 0; i < table.getRowCount(); i++) { Object o = table.getValueAt(i, sortingColumn); if (o == null) { continue; } String s = o.toString().toLowerCase(); if (s.length() >= lastPressedCount) { for (int j = 0; j < lastPressedCount; j++) { if (s.charAt(j) != lastPressed[j]) { break; // Escape the loop immediately when we find a mismatch } else if (j == (lastPressedCount - 1)) { // We found a match: table.setRowSelectionInterval(i, i); table.ensureVisible(i); return; } } } } } else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) { lastPressedCount = 0; } }
From source file:org.projectforge.core.BaseDao.java
/** * If the search string starts with "'" then the searchString will be returned without leading "'". If the search string consists only of * alphanumeric characters and allowed chars and spaces the wild card character '*' will be appended for enable ...* search. Otherwise the * searchString itself will be returned. * @param searchString//from w w w . j a v a 2 s . c o m * @param andSearch If true then all terms must match (AND search), otherwise OR will used (default) * @see #ALLOWED_CHARS * @see #ALLOWED_BEGINNING_CHARS * @see #ESCAPE_CHARS * @return The modified search string or the original one if no modification was done. */ public static String modifySearchString(final String searchString, final boolean andSearch) { if (searchString == null) { return ""; } if (searchString.startsWith("'") == true) { return searchString.substring(1); } for (int i = 0; i < searchString.length(); i++) { final char ch = searchString.charAt(i); if (Character.isLetterOrDigit(ch) == false && Character.isWhitespace(ch) == false) { final String allowed = (i == 0) ? ALLOWED_BEGINNING_CHARS : ALLOWED_CHARS; if (allowed.indexOf(ch) < 0) { return searchString; } } } final String[] tokens = StringUtils.split(searchString, ' '); final StringBuffer buf = new StringBuffer(); boolean first = true; for (final String token : tokens) { if (first == true) { first = false; } else { buf.append(" "); } if (ArrayUtils.contains(luceneReservedWords, token) == false) { final String modified = modifySearchToken(token); if (tokens.length > 1 && andSearch == true && StringUtils.containsNone(modified, ESCAPE_CHARS) == true) { buf.append("+"); } buf.append(modified); if (modified.endsWith("*") == false && StringUtils.containsNone(modified, ESCAPE_CHARS) == true) { if (andSearch == false || tokens.length > 1) { // Don't append '*' if used by SearchForm and only one token is given. It's will be appended automatically by BaseDao before the // search is executed. buf.append('*'); } } } else { buf.append(token); } } return buf.toString(); }
From source file:net.sf.jabref.importer.fileformat.BibtexParser.java
/** * This method is used to parse string labels, field names, entry type and * numbers outside brackets.//from ww w .j a va 2 s .c om */ private String parseTextToken() throws IOException { StringBuilder token = new StringBuilder(20); while (true) { int character = read(); if (character == -1) { eof = true; return token.toString(); } if (Character.isLetterOrDigit((char) character) || (":-_*+./'".indexOf(character) >= 0)) { token.append((char) character); } else { unread(character); return token.toString(); } } }
From source file:marytts.tools.dbselection.DatabaseSelector.java
/** * Read and check the command line arguments * // w w w . ja v a2 s. c om * @param args the arguments * @param log a StringBufffer for logging * @return true if args can be parsed and all essential args are there, * false otherwise */ private static boolean readArgs(String[] args, StringBuffer log) throws Exception { //initialise default values String currentDir = System.getProperty("user.dir"); String maryBaseDir = System.getenv("MARY_BASE"); System.out.println("Current directory: " + currentDir + " MARY_BASE=" + maryBaseDir); locale = null; selectionDirName = null; initFileName = null; covDefConfigFileName = null; featDefFileName = null; overallLogFile = null; holdVectorsInMemory = true; verbose = false; logCovDevelopment = false; mysqlHost = null; mysqlDB = null; mysqlUser = null; mysqlPasswd = null; selectedSentencesTableName = null; tableDescription = ""; considerOnlyReliableSentences = true; stopCriterion = null; // Default values for holdVectorsInMemory = true; verbose = false; logCovDevelopment = false; int i = 0; int numEssentialArgs = 0; //loop over args while (args.length > i) { if (args[i].equals("-locale")) { if (args.length > i + 1) { i++; locale = args[i]; log.append("locale : " + args[i] + "\n"); System.out.println(" locale : " + args[i]); numEssentialArgs++; } else { System.out.println("No locale."); printUsage(); return false; } i++; continue; } if (args[i].equals("-mysqlHost")) { if (args.length > i + 1) { i++; mysqlHost = args[i]; log.append("mysqlHost : " + args[i] + "\n"); System.out.println(" mysqlHost : " + args[i]); numEssentialArgs++; } else { System.out.println("No mysqlHost."); printUsage(); return false; } i++; continue; } if (args[i].equals("-mysqlDB")) { if (args.length > i + 1) { i++; mysqlDB = args[i]; log.append("mysqlDB : " + args[i] + "\n"); System.out.println(" mysqlDB : " + args[i]); numEssentialArgs++; } else { System.out.println("No mysqlDB."); printUsage(); return false; } i++; continue; } if (args[i].equals("-mysqlUser")) { if (args.length > i + 1) { i++; mysqlUser = args[i]; log.append("mysqlUser : " + args[i] + "\n"); System.out.println(" mysqlUser : " + args[i]); numEssentialArgs++; } else { System.out.println("No mysqlUser."); printUsage(); return false; } i++; continue; } if (args[i].equals("-mysqlPasswd")) { if (args.length > i + 1) { i++; mysqlPasswd = args[i]; log.append("mysqlPasswd : " + args[i] + "\n"); System.out.println(" mysqlPasswd : " + args[i]); numEssentialArgs++; } else { System.out.println("No mysqlPasswd."); printUsage(); return false; } i++; continue; } if (args[i].equals("-featDef")) { if (args.length > i + 1) { i++; featDefFileName = args[i]; log.append("FeatDefFileName : " + args[i] + "\n"); System.out.println(" FeatDefFileName : " + args[i]); } else { System.out.println("No featDef file"); printUsage(); return false; } i++; continue; } if (args[i].equals("-initFile")) { if (args.length > i + 1) { i++; initFileName = args[i]; log.append("initFile : " + args[i] + "\n"); System.out.println(" initFile : " + args[i]); } else { System.out.println("No initFile"); printUsage(); return false; } i++; continue; } if (args[i].equals("-tableName")) { if (args.length > i + 1) { i++; selectedSentencesTableName = args[i]; log.append("selectedSentencesTable name : " + args[i] + "\n"); System.out.println(" selectedSentencesTable name: " + args[i]); numEssentialArgs++; } else { System.out.println("No selectedSentencesTable name"); printUsage(); return false; } i++; continue; } if (args[i].equals("-tableDescription")) { if (args.length > i + 1) { i++; tableDescription = args[i]; log.append("tableDescription : " + args[i] + "\n"); System.out.println(" tableDescription: " + args[i]); } else { System.out.println("No tableDescription"); printUsage(); return false; } i++; continue; } if (args[i].equals("-vectorsOnDisk")) { holdVectorsInMemory = false; log.append("vectorsOnDisk"); System.out.println(" vectorsOnDisk"); i++; continue; } if (args[i].equals("-verbose")) { verbose = true; log.append("verbose"); System.out.println(" verbose"); i++; continue; } if (args[i].equals("-logCoverageDevelopment")) { logCovDevelopment = true; log.append("logCoverageDevelopment"); System.out.println(" logCoverageDevelopment"); i++; continue; } if (args[i].equals("-selectionDir")) { if (args.length > i + 1) { i++; selectionDirName = args[i]; //make sure we have a slash at the end char lastChar = selectionDirName.charAt(selectionDirName.length() - 1); if (Character.isLetterOrDigit(lastChar)) { selectionDirName = selectionDirName + "/"; } log.append("selectionDir : " + args[i] + "\n"); System.out.println(" selectionDir : " + args[i]); } else { System.out.println("No selectionDir"); printUsage(); return false; } i++; continue; } if (args[i].equals("-coverageConfig")) { if (args.length > i + 1) { i++; covDefConfigFileName = args[i]; log.append("coverageConfig : " + args[i] + "\n"); System.out.println(" coverageConfig : " + args[i]); } else { System.out.println("No coverageConfig"); printUsage(); return false; } i++; continue; } if (args[i].equals("-stop")) { StringBuilder tmp = new StringBuilder(); i++; while (args.length > i) { if (args[i].startsWith("-")) break; tmp.append(args[i] + " "); i++; } stopCriterion = tmp.toString(); log.append("stop criterion : " + stopCriterion + "\n"); System.out.println(" stop criterion : " + stopCriterion); continue; } if (args[i].equals("-overallLog")) { if (args.length > i + 1) { i++; overallLogFile = args[i]; log.append("overallLogFile : " + args[i] + "\n"); System.out.println(" overallLogFile : " + args[i]); } else { System.out.println("No overall log file"); printUsage(); return false; } i++; continue; } /* It is currently not possible to use unreliable sentences. * The place where this can be influenced is the FeatureMaker, * in its setting "" if (args[i].equals("-reliableOnly")) { // optionally, request that only "reliable" sentences be used in selection considerOnlyReliableSentences = true; log.append("using only reliable sentences\n"); System.out.println("using only reliable sentences"); i++; continue; } */ i++; } System.out.println(); if (numEssentialArgs < 6) { //not all essential arguments were given System.out.println( "You must at least specify locale, mysql (host,user,paswd,DB), selectedSentencesTableName"); printUsage(); return false; } if (selectedSentencesTableName == null) { System.out.println("Please provide a name for the selectedSentencesTable."); printUsage(); return false; } if (stopCriterion == null) { stopCriterion = "numSentences 90 simpleDiphones simpleProsody"; } if (selectionDirName == null) { selectionDirName = currentDir + "/selection/"; } if (initFileName == null) { initFileName = currentDir + "/init.bin"; } if (overallLogFile == null) { overallLogFile = currentDir + "/overallLog.txt"; } if (featDefFileName == null) { // check first if there exists one in the current directory // if not ask the user to provide one, it should have been automatically generated by the FeatureMaker in previous step // See: http://mary.opendfki.de/wiki/NewLanguageSupport step 5 System.out.println("Checking if there is [locale]_featureDefinition.txt in the current directory"); File feaDef = new File(currentDir + "/" + locale + "_featureDefinition.txt"); if (feaDef.exists()) { System.out.println("Using " + locale + "_featureDefinition.txt in current directory."); featDefFileName = currentDir + "/" + locale + "_featureDefinition.txt"; } else System.out.println( "Please provide a [locale]_featureDefinition.txt, it should have been generated by the FeatureMaker. \n" + " See: http://mary.opendfki.de/wiki/NewLanguageSupport step 5."); } if (covDefConfigFileName == null) { // check if there is already a covDef.config file in the current directory // if not then copy the default covDef.config from jar archive resource (marytts/tools/dbselection/covDef.config) System.out.println("\nChecking if there is already a covDef.config in the current directory"); File covDef = new File(currentDir + "/covDef.config"); if (covDef.exists()) System.out.println("Using covDef.config in current directory."); else { System.out.println("Copying default covDef.config file from archive"); FileUtils.copyInputStreamToFile(DatabaseSelector.class.getResourceAsStream("covDef.config"), covDef); } covDefConfigFileName = currentDir + "/covDef.config"; System.out.println("covDefConfigFileName = " + covDefConfigFileName); } return true; }
From source file:org.eclipse.lyo.oslc.am.resource.ResourceService.java
private String filterCharacters(String str) { if (str == null || str.length() == 0) return ""; StringBuffer inBuf = new StringBuffer(str); StringBuffer outBuf = new StringBuffer(); int len = inBuf.length(); for (int i = 0; i < len; i++) { char ch = inBuf.charAt(i); if (Character.isWhitespace(ch)) { outBuf.append(' '); } else if (Character.isLetterOrDigit(ch) || ch == '\'') { outBuf.append(ch);/*from ww w . j av a 2 s .com*/ } } return outBuf.toString(); }