List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:com.android.beyondemail.SSLUtils.java
/** * Escapes the contents a string to be used as a safe scheme name in the URI according to * http://tools.ietf.org/html/rfc3986#section-3.1 * * This does not ensure that the first character is a letter (which is required by the RFC). *//* w w w .j a va2s . c om*/ public static String escapeForSchemeName(String s) { // According to the RFC, scheme names are case-insensitive. s = s.toLowerCase(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isLetter(c) || Character.isDigit(c) || ('-' == c) || ('.' == c)) { // Safe - use as is. sb.append(c); } else if ('+' == c) { // + is used as our escape character, so double it up. sb.append("++"); } else { // Unsafe - escape. sb.append('+').append((int) c); } } return sb.toString(); }
From source file:com.oneguy.recognize.Util.java
public static String replaceInnerBlankInDigits(String data) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.length(); i++) { if (i == 0 && data.charAt(i) == ' ') { continue; }/*w w w .j a va 2 s . co m*/ sb.append(data.charAt(i)); if (Character.isDigit(data.charAt(i)) && i < data.length() - 1 && data.charAt(i + 1) == ' ') { i++; } } return sb.toString(); }
From source file:com.ning.maven.plugins.dependencyversionscheck.version.VersionElement.java
public long getNumber() { if (!hasNumbers()) { return 0L; } else {//from ww w.j a v a 2s .co m final String result; if (isNumber()) { result = element; } else { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < element.length(); i++) { if (Character.isDigit(element.charAt(i))) { sb.append(element.charAt(i)); } } result = sb.toString(); } return Long.parseLong(result, 10); } }
From source file:com.albert.util.StringUtilCommon.java
/** * Check if all characters are digits./*from w w w . j a v a2 s . com*/ * * @param str * @return boolean */ public static boolean isNumerical(String str) { boolean isNumerical = true; if (!isEmpty(str)) { int i = 0; // ensure all characters are digits while (i < str.length()) { if (!Character.isDigit(str.charAt(i))) { isNumerical = false; break; } i++; } } return isNumerical; }
From source file:net.panthema.BispanningGame.GraphString.java
static int readInt(PushbackReader pr) throws IOException { int c;// w w w . ja v a2 s . co m ByteArrayOutputStream ba = new ByteArrayOutputStream(); while ((c = pr.read()) != 0 && (Character.isDigit(c) || c == '-')) { ba.write(c); } pr.unread(c); try { return Integer.parseInt(ba.toString()); } catch (NumberFormatException e) { throw (new IOException("Error in Graph String: integer format error")); } }
From source file:au.org.ala.delta.directives.args.IdWithIdListParser.java
protected Object readId() throws ParseException { expect('#');/* w w w.j a va2 s . c o m*/ mark(); readNext(); if (Character.isDigit(_currentChar)) { reset(); return readListId(_validator); } else { reset(); return readItemDescription(); } }
From source file:br.com.bropenmaps.util.Util.java
/** * Desfaz as alteraes feitas quando um termo precisa ser modificado ao ser utilizado como parmetro em requisies HTTP (decoder para o {@link URLEncoder}). * Este mtodo transforma '+' em espao./*from w ww . ja v a2 s . c o m*/ * @param s - termo a ser modificado * @return Retorna o termo com as modificaes realizadas */ public static String unescape(String s) { if (s == null) { return s; } StringBuffer sbuf = new StringBuffer(); int l = s.length(); int ch = -1; int b, sumb = 0; for (int i = 0, more = -1; i < l; i++) { /* Get next byte b from URL segment s */ switch (ch = s.charAt(i)) { case '%': ch = s.charAt(++i); int hb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a') & 0xF; ch = s.charAt(++i); int lb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a') & 0xF; b = (hb << 4) | lb; break; case '+': b = ' '; break; default: b = ch; } /* Decode byte b as UTF-8, sumb collects incomplete chars */ if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte) sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb if (--more == 0) sbuf.append((char) sumb); // Aarg0dd char to sbuf } else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits) sbuf.append((char) b); // Store in sbuf } else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits) sumb = b & 0x1f; more = 1; // Expect 1 more byte } else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits) sumb = b & 0x0f; more = 2; // Expect 2 more bytes } else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits) sumb = b & 0x07; more = 3; // Expect 3 more bytes } else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits) sumb = b & 0x03; more = 4; // Expect 4 more bytes } else /*if ((b & 0xfe) == 0xfc)*/ { // 1111110x (yields 1 bit) sumb = b & 0x01; more = 5; // Expect 5 more bytes } /* We don't test if the UTF-8 encoding is well-formed */ } return sbuf.toString(); }
From source file:com.dgtlrepublic.anitomyj.ParserHelper.java
/** Returns the index of the first digit in the {@code string}; -1 otherwise. */ public static int indexOfFirstDigit(String string) { if (StringUtils.isEmpty(string)) return -1; for (int i = 0; i < string.length(); i++) { if (Character.isDigit(string.charAt(i))) { return i; }/*from w w w . j ava2 s . com*/ } return -1; }
From source file:com.qmetry.qaf.automation.util.StringUtil.java
public static String getRandomString(String format) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < format.length(); i++) { char c = format.charAt(i); char a = Character.isDigit(c) ? RandomStringUtils.randomNumeric(1).charAt(0) : Character.isLetter(c) ? RandomStringUtils.randomAlphabetic(c).charAt(0) : c; sb.append(a);//from w w w . j a va 2 s. co m } return sb.toString(); }
From source file:dk.netarkivet.common.utils.batch.ExternalBatchMoreClasses.java
/** * Checks whether a string only contains digits will return true * * @param s String to be checked//from w w w. j a v a2s . c o m * @return true if the given string only contains digits (or is an empty line), false otherwise */ private static boolean isStringNumeric(String s) { boolean ok = true; int l = s.length(); int i = 0; while (i < l && ok) { char c = s.charAt(i); ok = Character.isDigit(c); i++; } return ok; }