List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:cx.fbn.nevernote.threads.IndexRunner.java
private void addToIndex(String guid, String word, String type) { if (foundWords.contains(word)) return;/* ww w . j ava2s.c om*/ StringBuffer buffer = new StringBuffer(word.toLowerCase()); for (int i = buffer.length() - 1; i >= 0; i--) { if (!Character.isLetterOrDigit(buffer.charAt(i)) && specialIndexCharacters.indexOf(buffer.charAt(i)) == -1) buffer.deleteCharAt(i); else break; } buffer = buffer.reverse(); for (int i = buffer.length() - 1; i >= 0; i--) { if (!Character.isLetterOrDigit(buffer.charAt(i))) buffer.deleteCharAt(i); else break; } buffer = buffer.reverse(); if (buffer.length() > 0) { // We have a good word, now let's trim off junk at the beginning or end if (!foundWords.contains(buffer.toString())) { foundWords.add(buffer.toString()); foundWords.add(word); conn.getWordsTable().addWordToNoteIndex(guid, buffer.toString(), type, 100); uncommittedCount++; if (uncommittedCount > 100) { conn.commitTransaction(); uncommittedCount = 0; } } } return; }
From source file:org.jboss.tools.jst.web.ui.palette.html.wizard.AbstractNewHTMLWidgetWizardPage.java
static void addRangesInJavaScript(String text, int startOffset, int endOffset, ArrayList<StyleRange> regionList) { boolean inLineComments = false; boolean inBlockComments = false; char quota = '\0'; boolean word = false; StringBuilder name = new StringBuilder(); int offset = -1; for (int i = startOffset; i < endOffset; i++) { char ch = text.charAt(i); if (inBlockComments) { if (ch == '*' && i + 1 < endOffset && text.charAt(i + 1) == '/') { addRange(offset, i + 2 - offset, commentColor, false, regionList); inBlockComments = false; i++;// w w w.j a v a 2s .c o m } } else if (inLineComments) { if (ch == '\n' || ch == '\r') { addRange(offset, i - offset, commentColor, false, regionList); inLineComments = false; } } else if (quota != '\0') { if (ch == quota) { quota = '\0'; addRange(offset, i + 1 - offset, valueColor, false, regionList); } } else if (ch == '\'' || ch == '"') { quota = ch; offset = i; } else { if (Character.isLetterOrDigit(ch) || ch == '_') { if (word) { name.append(ch); } else if (Character.isJavaIdentifierStart(ch)) { word = true; name.append(ch); offset = i; } } else { if (word && name.length() > 0) { if (keywords.contains(name.toString())) { addRange(offset, name.length(), keywordColor, false, true, regionList); } name.setLength(0); } word = false; } if (ch == '/' && i + 1 < endOffset) { char ch1 = text.charAt(i + 1); if (ch1 == '/') { inLineComments = true; offset = i; } else if (ch1 == '*') { inBlockComments = true; offset = i; i++; } } } } }
From source file:org.deegree.services.wfs.query.QueryAnalyzer.java
private QName getPropertyNameAsQName(ValueReference propName) { QName name = null;//from ww w. j a va 2 s .co m NamespaceContext nsContext = propName.getNsContext(); String s = propName.getAsText(); int colonIdx = s.indexOf(':'); if (!s.contains("/") && colonIdx != -1) { if (Character.isLetterOrDigit(s.charAt(0)) && Character.isLetterOrDigit(s.charAt(s.length() - 1))) { String prefix = s.substring(0, colonIdx); String localName = s.substring(colonIdx + 1, s.length()); String nsUri = null; if (nsContext != null) { nsUri = nsContext.translateNamespacePrefixToUri(prefix); } else { nsUri = service.getPrefixToNs().get(prefix); if (nsUri == null) { nsUri = ""; } } name = new QName(nsUri, localName, prefix); } } else { if (!s.contains("/") && !s.isEmpty() && Character.isLetterOrDigit(s.charAt(0)) && Character.isLetterOrDigit(s.charAt(s.length() - 1))) { name = new QName(s); } } return name; }
From source file:net.evendanan.android.thumbremote.ui.RemoteUiActivity.java
/** * Handler an android keypress and send it to boxee if appropriate. *///from ww w .java2s . c om @Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (RemoteApplication.getConfig().getHandleBack()) { Log.d(TAG, "Will handle back"); if (mBoundService != null) mBoundService.remoteBack(); return true; } else { Log.d(TAG, "Will NOT handle back"); return super.onKeyDown(keyCode, event); } case KeyEvent.KEYCODE_DPAD_CENTER: if (mBoundService != null) mBoundService.remoteSelect(); return true; case KeyEvent.KEYCODE_DPAD_DOWN: if (mBoundService != null) mBoundService.remoteDown(); return true; case KeyEvent.KEYCODE_DPAD_UP: if (mBoundService != null) mBoundService.remoteUp(); return true; case KeyEvent.KEYCODE_DPAD_LEFT: if (mBoundService != null) mBoundService.remoteLeft(); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: if (mBoundService != null) mBoundService.remoteRight(); return true; case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: final int volumeFactor = (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ? -1 : 1; final int volumeOffset = (volumeFactor * RemoteApplication.getConfig().getVolumeStep()); if (mBoundService != null) mBoundService.remoteVolumeOffset(volumeOffset); return true; case KeyEvent.KEYCODE_DEL: if (mBoundService != null) mBoundService.remoteKeypress((char) 8); return true; default: final char unicodeChar = (char) event.getUnicodeChar(); // Log.d(TAG, "Unicode is " + ((char)unicodeChar)); if (Character.isLetterOrDigit(unicodeChar) || msPunctuation.contains(unicodeChar)) { // Log.d(TAG, "handling " + ((char)unicodeChar)); if (mBoundService != null) mBoundService.remoteKeypress(unicodeChar); return true; } else { return super.onKeyDown(keyCode, event); } } }
From source file:immf.MyHtmlEmail.java
private static String random(int count, int start, int end, boolean letters, boolean numbers, char chars[], Random random) {/*w w w .j a va 2 s . c om*/ if (count == 0) return ""; if (count < 0) throw new IllegalArgumentException("Requested random string length " + count + " is less than 0."); if (start == 0 && end == 0) { end = 123; start = 32; if (!letters && !numbers) { start = 0; end = 2147483647; } } StringBuffer buffer = new StringBuffer(); int gap = end - start; while (count-- != 0) { char ch; if (chars == null) ch = (char) (random.nextInt(gap) + start); else ch = chars[random.nextInt(gap) + start]; if (letters && numbers && Character.isLetterOrDigit(ch) || letters && Character.isLetter(ch) || numbers && Character.isDigit(ch) || !letters && !numbers) buffer.append(ch); else count++; } return buffer.toString(); }
From source file:org.loklak.geo.GeoNames.java
public static String normalize(final String text) { final StringBuilder l = new StringBuilder(); for (int i = 0; i < text.length(); i++) { final char c = text.charAt(i); if (Character.isLetterOrDigit(c)) { l.append(Character.toLowerCase(c)); } else {/* w ww . j av a 2s . c o m*/ if (l.length() > 0 && l.charAt(l.length() - 1) != ' ') l.append(' '); } } if (l.length() > 0 && l.charAt(l.length() - 1) == ' ') l.setLength(l.length() - 1); return l.toString(); }
From source file:org.sakaiproject.tool.assessment.data.dao.assessment.ItemData.java
public boolean isNotEmpty(String wyzText) { if (wyzText != null) { int index = 0; String t = (wyzText.replaceAll("(?i)<(?!img|/img).*?>", " ")).trim(); while (index < t.length()) { char c = t.charAt(index); if (Character.isLetterOrDigit(c)) { return true; }// w ww . ja va2 s . co m index++; } } return false; }
From source file:net.sf.jabref.importer.fileformat.BibtexParser.java
/** * This method is used to parse the bibtex key for an entry. *///from w w w .j a va2 s .com private String parseKey() throws IOException { StringBuilder token = new StringBuilder(20); while (true) { int character = read(); if (character == -1) { eof = true; return token.toString(); } if (!Character.isWhitespace((char) character) && (Character.isLetterOrDigit((char) character) || (character == ':') || ("#{}~,=\uFFFD".indexOf(character) == -1))) { token.append((char) character); } else { if (Character.isWhitespace((char) character)) { // We have encountered white space instead of the comma at // the end of // the key. Possibly the comma is missing, so we try to // return what we // have found, as the key and try to restore the rest in fixKey(). return token + fixKey(); } else if ((character == ',') || (character == '}')) { unread(character); return token.toString(); } else if (character == '=') { // If we find a '=' sign, it is either an error, or // the entry lacked a comma signifying the end of the key. return token.toString(); } else { throw new IOException("Error in line " + line + ":" + "Character '" + (char) character + "' is not " + "allowed in bibtex keys."); } } } }
From source file:net.java.sip.communicator.gui.AuthenticationSplash.java
public boolean valid() { int idx;//from w w w. j a v a2 s . co m boolean usern = true, pwd = true, nme = true, lnme = true, ml = true; // Username checks // Starts with a letter if (userName.length() == 0) usern = false; else if (!Character.isLetter(userName.charAt(0))) usern = false; // Contains only letters and numbers for (idx = 0; idx < userName.length(); idx++) { if (!Character.isLetterOrDigit(userName.charAt(idx))) usern = false; } // Is between 4 and 10 characters if ((userName.length() < 4) || (userName.length() > 18)) usern = false; // Name and last name checks // Both begin with uppercase if (name.length() == 0) nme = false; else if (!Character.isUpperCase(name.charAt(0))) nme = false; if (lastName.length() == 0) lnme = false; else if (!Character.isUpperCase(lastName.charAt(0))) lnme = false; // Both contain only letters for (idx = 0; idx < name.length(); idx++) { if (!Character.isLetter(name.charAt(idx))) nme = false; } for (idx = 0; idx < lastName.length(); idx++) { if (!Character.isLetter(lastName.charAt(idx))) lnme = false; } // Mail chekcs Pattern ptr = Pattern.compile( "(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*|(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?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>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*))*)?;\\s*)"); if (!ptr.matcher(mail).matches()) ml = false; // Password checks // Check that we have a variety of different characters boolean lower = false, upper = false, number = false, other = false; for (idx = 0; idx < password.length(); idx++) { if (Character.isUpperCase(password.charAt(idx))) upper = true; if (Character.isLowerCase(password.charAt(idx))) lower = true; if (!Character.isLetterOrDigit(password.charAt(idx))) other = true; if (Character.isDigit(password.charAt(idx))) number = true; } if (!(upper && lower && number && other)) pwd = false; // Verify that the size is acceptable if (password.length() < 6 || password.length() > 30) pwd = false; // Change the label colors if (!nme) { nameLabel.setForeground(Color.RED); nameTextField.setText(""); } if (!lnme) { lastNameLabel.setForeground(Color.RED); lastNameTextField.setText(""); } if (!ml) { mailLabel.setForeground(Color.RED); mailTextField.setText(""); } if (!usern) { userNameLabel.setForeground(Color.RED); userNameTextField.setText(""); } if (!pwd) { passwordLabel.setForeground(Color.RED); passwordTextField.setText(""); } if (!(nme && lnme && usern && ml && pwd)) return false; return true; }
From source file:org.dasein.cloud.aws.platform.SimpleDB.java
private String validateName(String name) { StringBuilder str = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if (Character.isLetterOrDigit(c)) { str.append(c);//from w w w . j a v a 2 s .c o m } else if (c == '-' || c == '_' || c == '.') { str.append(c); } } if (str.length() < 3) { if (str.length() < 2) { if (str.length() < 1) { return "aaa"; } return str.toString() + "aa"; } return str.toString() + "a"; } else if (str.length() > 255) { return str.toString().substring(0, 255); } return str.toString(); }