/** * Like {@link #escapeBytes(Buffer)}, but escapes a text string. * Non-ASCII characters are first encoded as UTF-8, then each byte is escaped * individually as a 3-digit octal escape. Yes, it's weird. */ static String escapeText(String input) { return escapeBytes(new UTF8Buffer(input)); }
/** * Parse a 64-bit signed integer from the text. Unlike the Java standard * {@code Integer.parseInt()}, this function recognizes the prefixes "0x" * and "0" to signify hexidecimal and octal numbers, respectively. */ static long parseInt64(String text) throws NumberFormatException { return parseInteger(text, true, true); }
int v; if( field.getType() == FieldDescriptor.UINT32_TYPE ) { v = TextFormat.parseUInt32(defaultOption.getValue()); } else { v = TextFormat.parseInt32(defaultOption.getValue()); long v; if( field.getType() == FieldDescriptor.UINT64_TYPE ) { v = TextFormat.parseUInt64(defaultOption.getValue()); } else { v = TextFormat.parseInt64(defaultOption.getValue());
++i; c = input.charAt(i); if (isOctal(c)) { int code = digitValue(c); if (i + 1 < input.length() && isOctal(input.charAt(i + 1))) { ++i; code = code * 8 + digitValue(input.charAt(i)); if (i + 1 < input.length() && isOctal(input.charAt(i + 1))) { ++i; code = code * 8 + digitValue(input.charAt(i)); if (i + 1 < input.length() && isHex(input.charAt(i + 1))) { ++i; code = digitValue(input.charAt(i)); } else { throw new InvalidEscapeSequence( "Invalid escape sequence: '\\x' with no digits"); if (i + 1 < input.length() && isHex(input.charAt(i + 1))) { ++i; code = code * 16 + digitValue(input.charAt(i));
/** * Un-escape a text string as escaped using {@link #escapeText(String)}. * Two-digit hex escapes (starting with "\x") are also recognized. */ static String unescapeText(String input) throws InvalidEscapeSequence { return new UTF8Buffer(unescapeBytes(input)).toString(); }
/** * If the next token is a 32-bit signed integer, consume it and return its * value. Otherwise, throw a {@link ParseException}. */ public int consumeInt32() throws ParseException { try { int result = parseInt32(currentToken); nextToken(); return result; } catch (NumberFormatException e) { throw integerParseException(e); } }
/** * If the next token is a 64-bit signed integer, consume it and return its * value. Otherwise, throw a {@link ParseException}. */ public long consumeInt64() throws ParseException { try { long result = parseInt64(currentToken); nextToken(); return result; } catch (NumberFormatException e) { throw integerParseException(e); } }
/** * If the next token is a 32-bit unsigned integer, consume it and return its * value. Otherwise, throw a {@link ParseException}. */ public int consumeUInt32() throws ParseException { try { int result = parseUInt32(currentToken); nextToken(); return result; } catch (NumberFormatException e) { throw integerParseException(e); } }
/** * If the next token is a 64-bit unsigned integer, consume it and return its * value. Otherwise, throw a {@link ParseException}. */ public long consumeUInt64() throws ParseException { try { long result = parseUInt64(currentToken); nextToken(); return result; } catch (NumberFormatException e) { throw integerParseException(e); } }
int v; if( field.getType() == FieldDescriptor.UINT32_TYPE ) { v = TextFormat.parseUInt32(defaultOption.getValue()); } else { v = TextFormat.parseInt32(defaultOption.getValue()); long v; if( field.getType() == FieldDescriptor.UINT64_TYPE ) { v = TextFormat.parseUInt64(defaultOption.getValue()); } else { v = TextFormat.parseInt64(defaultOption.getValue());
++i; c = input.charAt(i); if (isOctal(c)) { int code = digitValue(c); if (i + 1 < input.length() && isOctal(input.charAt(i + 1))) { ++i; code = code * 8 + digitValue(input.charAt(i)); if (i + 1 < input.length() && isOctal(input.charAt(i + 1))) { ++i; code = code * 8 + digitValue(input.charAt(i)); if (i + 1 < input.length() && isHex(input.charAt(i + 1))) { ++i; code = digitValue(input.charAt(i)); } else { throw new InvalidEscapeSequence( "Invalid escape sequence: '\\x' with no digits"); if (i + 1 < input.length() && isHex(input.charAt(i + 1))) { ++i; code = code * 16 + digitValue(input.charAt(i));
/** * Un-escape a text string as escaped using {@link #escapeText(String)}. * Two-digit hex escapes (starting with "\x") are also recognized. */ static String unescapeText(String input) throws InvalidEscapeSequence { return new UTF8Buffer(unescapeBytes(input)).toString(); }
/** * If the next token is a 32-bit signed integer, consume it and return its * value. Otherwise, throw a {@link ParseException}. */ public int consumeInt32() throws ParseException { try { int result = parseInt32(currentToken); nextToken(); return result; } catch (NumberFormatException e) { throw integerParseException(e); } }
/** * If the next token is a 64-bit signed integer, consume it and return its * value. Otherwise, throw a {@link ParseException}. */ public long consumeInt64() throws ParseException { try { long result = parseInt64(currentToken); nextToken(); return result; } catch (NumberFormatException e) { throw integerParseException(e); } }
/** * If the next token is a 32-bit unsigned integer, consume it and return its * value. Otherwise, throw a {@link ParseException}. */ public int consumeUInt32() throws ParseException { try { int result = parseUInt32(currentToken); nextToken(); return result; } catch (NumberFormatException e) { throw integerParseException(e); } }
/** * If the next token is a 64-bit unsigned integer, consume it and return its * value. Otherwise, throw a {@link ParseException}. */ public long consumeUInt64() throws ParseException { try { long result = parseUInt64(currentToken); nextToken(); return result; } catch (NumberFormatException e) { throw integerParseException(e); } }
int v; if( field.getType() == FieldDescriptor.UINT32_TYPE ) { v = TextFormat.parseUInt32(defaultOption.getValue()); } else { v = TextFormat.parseInt32(defaultOption.getValue()); long v; if( field.getType() == FieldDescriptor.UINT64_TYPE ) { v = TextFormat.parseUInt64(defaultOption.getValue()); } else { v = TextFormat.parseInt64(defaultOption.getValue());
++i; c = input.charAt(i); if (isOctal(c)) { int code = digitValue(c); if (i + 1 < input.length() && isOctal(input.charAt(i + 1))) { ++i; code = code * 8 + digitValue(input.charAt(i)); if (i + 1 < input.length() && isOctal(input.charAt(i + 1))) { ++i; code = code * 8 + digitValue(input.charAt(i)); if (i + 1 < input.length() && isHex(input.charAt(i + 1))) { ++i; code = digitValue(input.charAt(i)); } else { throw new InvalidEscapeSequence( "Invalid escape sequence: '\\x' with no digits"); if (i + 1 < input.length() && isHex(input.charAt(i + 1))) { ++i; code = code * 16 + digitValue(input.charAt(i));
/** * Parse a 64-bit unsigned integer from the text. Unlike the Java standard * {@code Integer.parseInt()}, this function recognizes the prefixes "0x" * and "0" to signify hexidecimal and octal numbers, respectively. The * result is coerced to a (signed) {@code long} when returned since Java has * no unsigned long type. */ static long parseUInt64(String text) throws NumberFormatException { return parseInteger(text, false, true); }
/** * Un-escape a text string as escaped using {@link #escapeText(String)}. * Two-digit hex escapes (starting with "\x") are also recognized. */ static String unescapeText(String input) throws InvalidEscapeSequence { return new UTF8Buffer(unescapeBytes(input)).toString(); }