List of usage examples for java.lang Character digit
public static int digit(int codePoint, int radix)
From source file:com.telefonica.iot.cygnus.utils.CommonUtils.java
/** * Decides if a given string is a number, given its radix. * http://stackoverflow.com/questions/5439529/determine-if-a-string-is-an-integer-in-java * @param s//w ww . ja v a2s.c om * @param radix * @return */ public static boolean isANumber(String s, int radix) { if (s.isEmpty()) { return false; } // if for (int i = 0; i < s.length(); i++) { if ((i == 0) && (s.charAt(i) == '-')) { if (s.length() == 1) { return false; } // if continue; } // if if ((i == 0) && (s.charAt(i) == '.')) { return false; } // if if ((i == s.length() - 1) && (s.charAt(i) == '.')) { return false; } // if if (s.charAt(i) == '.') { continue; } // if if (Character.digit(s.charAt(i), radix) < 0) { return false; } // if } // for return true; }
From source file:edu.mit.scratch.ScratchCloudSession.java
public static boolean isInteger(final String s, final int radix) { if (s.isEmpty()) return false; for (int i = 0; i < s.length(); i++) { if ((i == 0) && (s.charAt(i) == '-')) { if (s.length() == 1) return false; else// w w w.j a v a 2 s . c o m continue; } if (Character.digit(s.charAt(i), radix) < 0) return false; } return true; }
From source file:CodePointInputMethod.java
private void waitDigit2(char c) { if (Character.digit(c, 16) != -1) { buffer.insert(insertionPoint++, c); char codePoint = (char) getCodePoint(buffer, 2, 5); if (Character.isHighSurrogate(codePoint)) { format = SURROGATE_PAIR;/*from w w w .j a v a 2s.co m*/ buffer.append("\\u"); insertionPoint = 8; } else { format = ESCAPE; } sendComposedText(); } else { beep(); } }
From source file:com.ab.http.PersistentCookieStore.java
/** * Hex string to byte array.//www . j a v a 2 s. c o m * * @param s the s * @return the byte[] */ protected byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); } return data; }
From source file:com.github.anba.es6draft.util.TestGlobals.java
private static void optionsFromStage(EnumSet<CompatibilityOption> options, String stage) { options.addAll(Arrays.stream(CompatibilityOption.Stage.values()).filter(s -> { if (stage.length() == 1 && Character.isDigit(stage.charAt(0))) { return s.getLevel() == Character.digit(stage.charAt(0), 10); } else {/*from w w w .ja va 2s . c om*/ return s.name().equalsIgnoreCase(stage); } }).findAny().map(CompatibilityOption::Stage).orElseThrow(IllegalArgumentException::new)); }
From source file:eu.europa.esig.dss.DSSUtils.java
/** * Converts a hexadecimal character to an integer. * * @param ch/*w w w . j a v a 2s. co m*/ * A character to convert to an integer digit * @param index * The index of the character in the source * @return An integer * @throws DSSException * Thrown if ch is an illegal hex character */ protected static int toDigit(char ch, int index) throws DSSException { int digit = Character.digit(ch, 16); if (digit == -1) { throw new DSSException("Illegal hexadecimal character " + ch + " at index " + index); } return digit; }
From source file:CodePointInputMethod.java
private void waitBackSlashOrLowSurrogate(char c) { if (insertionPoint == 6) { if (c == '\\') { buffer.append(c);/*from w w w . j a v a 2 s . com*/ buffer.append('u'); insertionPoint = 8; sendComposedText(); } else if (Character.digit(c, 16) != -1) { buffer.append("\\u"); buffer.append(c); insertionPoint = 9; sendComposedText(); } else { beep(); } } else { beep(); } }
From source file:cn.com.loopj.android.http.PersistentCookieStore.java
/** * Converts hex values from strings to byte arra * * @param hexString string of hex-encoded values * @return decoded byte array// w w w. ja v a2s .c o m */ protected byte[] hexStringToByteArray(String hexString) { int len = hexString.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16)); } return data; }
From source file:pl.psnc.synat.wrdz.realm.digest.WrdzDigestAuthHandler.java
/** * Decodes hex encoded array of characters into byte array. * /*from w ww . j ava2 s.c om*/ * @param encoded * encoded array of hex symbols. * @return decoded array of bytes. */ private static byte[] hexDecode(char[] encoded) { int len = encoded.length; byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(encoded[i], 16) << 4) + Character.digit(encoded[i + 1], 16)); } return data; }
From source file:org.level28.android.moca.json.ScheduleDeserializer.java
private static int getChar(final char[] s, int index, int multiplier) throws ParseException { final char c = s[index]; if (c >= '0' && c <= '9') { return Character.digit(c, 10) * multiplier; }// w ww . j a va 2s. c o m throw new ParseException("Illegal character", index); }