List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:org.asqatasun.crawler.processor.module.AsqatasunTextSeedModule.java
/** * Announce all seeds (and nonseed possible-directive lines) from * the given Reader/* ww w .j a va2 s.co m*/ * @param reader */ protected void announceSeedsFromReader(BufferedReader reader) { String s; Iterator<String> iter = new RegexLineIterator(new LineReadingIterator(reader), RegexLineIterator.COMMENT_LINE, RegexLineIterator.NONWHITESPACE_ENTRY_TRAILING_COMMENT, RegexLineIterator.ENTRY); while (iter.hasNext()) { s = iter.next(); if (Character.isLetterOrDigit(s.charAt(0))) { // consider a likely URI seedLine(s); } else { // report just in case it's a useful directive nonseedLine(s); } } publishConcludedSeedBatch(); }
From source file:com.reprezen.swagedit.editor.SwaggerDocument.java
/** * Returns position of the symbol ':' in respect to the given offset. * // ww w .ja v a 2 s . c o m * Will return -1 if reaches beginning of line of other symbol before finding ':'. * * @param offset * @return position */ public int getDelimiterPosition(int offset) { while (true) { try { char c = getChar(--offset); if (Character.isLetterOrDigit(c)) { return -1; } if (c == ':') { return offset; } if (Character.isWhitespace(c)) { continue; } if (c != ':' && !Character.isLetterOrDigit(c)) { return -1; } } catch (BadLocationException e) { return -1; } } }
From source file:com.j_o.android.imdb_client.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mediaList = new ArrayList<Media>(); mediaGrid = (GridView) findViewById(R.id.media_grid_view); editTxMediaSearch = (EditText) findViewById(R.id.edit_search_media); // Input filter that not allow special characters. InputFilter filter = new InputFilter() { @Override/*from w w w . j a v a 2 s.co m*/ public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { if (source instanceof SpannableStringBuilder) { SpannableStringBuilder sourceAsSpannableBuilder = (SpannableStringBuilder) source; for (int i = end - 1; i >= start; i--) { char currentChar = source.charAt(i); if (!Character.isLetterOrDigit(currentChar) && !Character.isSpaceChar(currentChar)) { sourceAsSpannableBuilder.delete(i, i + 1); } } return source; } else { StringBuilder filteredStringBuilder = new StringBuilder(); for (int i = 0; i < end; i++) { char currentChar = source.charAt(i); if (Character.isLetterOrDigit(currentChar) || Character.isSpaceChar(currentChar)) { filteredStringBuilder.append(currentChar); } } return filteredStringBuilder.toString(); } } }; editTxMediaSearch.setFilters(new InputFilter[] { filter }); editTxMediaSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { new AskForMediaAsyncTaks().execute(editTxMediaSearch.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editTxMediaSearch.getWindowToken(), 0); return true; } return false; } }); }
From source file:org.apache.myfaces.shared_impl.renderkit.html.util.JavascriptUtils.java
public static String getValidJavascriptName(String s, boolean checkForReservedWord) { if (checkForReservedWord && RESERVED_WORDS.contains(s)) { return s + "_"; }//from w w w . j a v a 2 s . com StringBuffer buf = null; for (int i = 0, len = s.length(); i < len; i++) { char c = s.charAt(i); if (Character.isLetterOrDigit(c)) { // allowed char if (buf != null) buf.append(c); } else { if (buf == null) { buf = new StringBuffer(s.length() + 10); buf.append(s.substring(0, i)); } buf.append('_'); if (c < 16) { // pad single hex digit values with '0' on the left buf.append('0'); } if (c < 128) { // first 128 chars match their byte representation in UTF-8 buf.append(Integer.toHexString(c).toUpperCase()); } else { byte[] bytes; try { bytes = Character.toString(c).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } for (int j = 0; j < bytes.length; j++) { int intVal = bytes[j]; if (intVal < 0) { // intVal will be >= 128 intVal = 256 + intVal; } else if (intVal < 16) { // pad single hex digit values with '0' on the left buf.append('0'); } buf.append(Integer.toHexString(intVal).toUpperCase()); } } } } return buf == null ? s : buf.toString(); }
From source file:org.sakaiproject.nakamura.util.PathUtils.java
/** * @param target//from w w w. j a v a 2 s . c o m * the target being formed into a structured path. * @param b * @return the structured path. */ private static String getStructuredHash(String target, int levels, boolean absPath) { try { // take the first element as the key for the target so that subtrees end up in the // same place. String[] elements = StringUtils.split(target, '/', 1); String pathInfo = removeFirstElement(target); target = elements[0]; target = String.valueOf(target); MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] userHash = md.digest(target.getBytes("UTF-8")); char[] chars = new char[(absPath ? 1 : 0) + levels * 3 + target.length() + pathInfo.length()]; int j = 0; if (absPath) { chars[j++] = '/'; } for (int i = 0; i < levels; i++) { byte current = userHash[i]; int hi = (current & 0xF0) >> 4; int lo = current & 0x0F; chars[j++] = (char) (hi < 10 ? ('0' + hi) : ('a' + hi - 10)); chars[j++] = (char) (lo < 10 ? ('0' + lo) : ('a' + lo - 10)); chars[j++] = '/'; } for (int i = 0; i < target.length(); i++) { char c = target.charAt(i); if (!Character.isLetterOrDigit(c)) { c = '_'; } chars[j++] = c; } for (int i = 0; i < pathInfo.length(); i++) { chars[j++] = pathInfo.charAt(i); } return new String(chars); } catch (NoSuchAlgorithmException e) { logger.error(e.getMessage(), e); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage(), e); } return null; }
From source file:net.rptools.maptool.client.functions.StrListFunctions.java
/** Prepares a string for use in regex operations. */ public static String fullyQuoteString(String s) { // We escape each non-alphanumeric character in the delimiter string StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { if (!Character.isLetterOrDigit(s.charAt(i))) { sb.append("\\"); }//from ww w . j ava 2 s .c o m sb.append(s.charAt(i)); } return sb.toString(); }
From source file:ca.uhn.hl7v2.sourcegen.SourceGenerator.java
/** * Make a Java-ish accessor method name out of a field or component description * by removing non-letters and adding "get". One complication is that some description * entries in the DB have their data types in brackets, and these should not be * part of the method name. On the other hand, sometimes critical distinguishing * information is in brackets, so we can't omit everything in brackets. The approach * taken here is to eliminate bracketed text if a it looks like a data type. *//* w ww . j a v a2s. c o m*/ public static String makeAccessorName(String fieldDesc, String parentName) { StringBuffer aName = new StringBuffer(); char[] chars = fieldDesc.toCharArray(); boolean lastCharWasNotLetter = true; int inBrackets = 0; StringBuffer bracketContents = new StringBuffer(); for (int i = 0; i < chars.length; i++) { if (chars[i] == '(') inBrackets++; if (chars[i] == ')') inBrackets--; if (Character.isLetterOrDigit(chars[i])) { if (inBrackets > 0) { //buffer everthing in brackets bracketContents.append(chars[i]); } else { //add capitalized bracketed text if appropriate if (bracketContents.length() > 0) { aName.append(capitalize(filterBracketedText(bracketContents.toString()))); bracketContents = new StringBuffer(); } if (lastCharWasNotLetter) { //first letter of each word is upper-case aName.append(Character.toUpperCase(chars[i])); } else { aName.append(chars[i]); } lastCharWasNotLetter = false; } } else { lastCharWasNotLetter = true; } } aName.append(capitalize(filterBracketedText(bracketContents.toString()))); String retVal = aName.toString(); // Accessors with these two names conflict with existing superclass accessor names if (retVal.equals("Parent")) { retVal = parentName + "Parent"; } if (retVal.equals("Name")) { retVal = parentName + "Name"; } return retVal; }
From source file:com.manydesigns.elements.util.Util.java
public static String letterOrDigitToWords(String s) { if (s == null) { return null; }/* w w w . ja va 2s . c o m*/ StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isLetterOrDigit(c)) { sb.append(Character.toLowerCase(c)); } else { sb.append(' '); } } return sb.toString(); }
From source file:com.sjsu.crawler.util.RandomStringUtilsTest.java
/** * Test the implementation/* ww w. ja v a2 s. co m*/ */ @Test public void testRandomStringUtils() { String r1 = RandomStringUtils.random(50); assertEquals("random(50) length", 50, r1.length()); String r2 = RandomStringUtils.random(50); assertEquals("random(50) length", 50, r2.length()); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.randomAscii(50); assertEquals("randomAscii(50) length", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("char between 32 and 127", r1.charAt(i) >= 32 && r1.charAt(i) <= 127); } r2 = RandomStringUtils.randomAscii(50); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.randomAlphabetic(50); assertEquals("randomAlphabetic(50)", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("r1 contains alphabetic", Character.isLetter(r1.charAt(i)) && !Character.isDigit(r1.charAt(i))); } r2 = RandomStringUtils.randomAlphabetic(50); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.randomAlphanumeric(50); assertEquals("randomAlphanumeric(50)", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("r1 contains alphanumeric", Character.isLetterOrDigit(r1.charAt(i))); } r2 = RandomStringUtils.randomAlphabetic(50); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.randomNumeric(50); assertEquals("randomNumeric(50)", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("r1 contains numeric", Character.isDigit(r1.charAt(i)) && !Character.isLetter(r1.charAt(i))); } r2 = RandomStringUtils.randomNumeric(50); assertTrue("!r1.equals(r2)", !r1.equals(r2)); String set = "abcdefg"; r1 = RandomStringUtils.random(50, set); assertEquals("random(50, \"abcdefg\")", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("random char in set", set.indexOf(r1.charAt(i)) > -1); } r2 = RandomStringUtils.random(50, set); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.random(50, (String) null); assertEquals("random(50) length", 50, r1.length()); r2 = RandomStringUtils.random(50, (String) null); assertEquals("random(50) length", 50, r2.length()); assertTrue("!r1.equals(r2)", !r1.equals(r2)); set = "stuvwxyz"; r1 = RandomStringUtils.random(50, set.toCharArray()); assertEquals("random(50, \"stuvwxyz\")", 50, r1.length()); for (int i = 0; i < r1.length(); i++) { assertTrue("random char in set", set.indexOf(r1.charAt(i)) > -1); } r2 = RandomStringUtils.random(50, set); assertTrue("!r1.equals(r2)", !r1.equals(r2)); r1 = RandomStringUtils.random(50, (char[]) null); assertEquals("random(50) length", 50, r1.length()); r2 = RandomStringUtils.random(50, (char[]) null); assertEquals("random(50) length", 50, r2.length()); assertTrue("!r1.equals(r2)", !r1.equals(r2)); final long seed = System.currentTimeMillis(); r1 = RandomStringUtils.random(50, 0, 0, true, true, null, new Random(seed)); r2 = RandomStringUtils.random(50, 0, 0, true, true, null, new Random(seed)); assertEquals("r1.equals(r2)", r1, r2); r1 = RandomStringUtils.random(0); assertEquals("random(0).equals(\"\")", "", r1); }
From source file:org.glimpse.server.manager.orm.OrmUserManager.java
private boolean isValidConnectionId(String connectionId) { if (connectionId == null) { return false; }/*from w ww . j a v a2s. c o m*/ if (connectionId.length() != CONNECTION_ID_LENGTH) { return false; } for (int i = 0; i < connectionId.length(); i++) { if (!Character.isLetterOrDigit(connectionId.charAt(i))) { return false; } } return true; }