Class TextFormat

java.lang.Object
io.protostuff.parser.TextFormat

public final class TextFormat extends Object
Provide ascii text parsing and formatting support for proto2 instances. The implementation largely follows google/protobuf/text_format.cc.
  • Field Details

    • UTF8

      static final Charset UTF8
    • ISO_8859_1

      static final Charset ISO_8859_1
  • Constructor Details

    • TextFormat

      private TextFormat()
  • Method Details

    • escapeBytes

      static StringBuilder escapeBytes(ByteBuffer input)
      Escapes bytes in the format used in protocol buffer text format, which is the same as the format used for C string literals. All bytes that are not printable 7-bit ASCII characters are escaped, as well as backslash, single-quote, and double-quote characters. Characters for which no defined short-hand escape sequence is defined will be escaped using 3-digit octal sequences.
    • unescapeBytes

      static ByteBuffer unescapeBytes(CharSequence input)
      Un-escape a byte sequence as escaped using escapeBytes(ByteString). Two-digit hex escapes (starting with "\x") are also recognized.
    • escapeText

      static String escapeText(String input)
      Like escapeBytes(ByteString), 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.
    • unescapeText

      static String unescapeText(String input)
      Un-escape a text string as escaped using escapeText(String). Two-digit hex escapes (starting with "\x") are also recognized.
    • isOctal

      private static boolean isOctal(char c)
      Is this an octal digit?
    • isHex

      private static boolean isHex(char c)
      Is this a hex digit?
    • digitValue

      private static int digitValue(char c)
      Interpret a character as a digit (in any base up to 36) and return the numeric value. This is like Character.digit() but we don't accept non-ASCII digits.
    • parseInt32

      static int parseInt32(String text) throws NumberFormatException
      Parse a 32-bit signed integer from the text. Unlike the Java standard Integer.parseInt(), this function recognizes the prefixes "0x" and "0" to signify hexidecimal and octal numbers, respectively.
      Throws:
      NumberFormatException
    • parseUInt32

      static int parseUInt32(String text) throws NumberFormatException
      Parse a 32-bit unsigned integer from the text. Unlike the Java standard Integer.parseInt(), this function recognizes the prefixes "0x" and "0" to signify hexidecimal and octal numbers, respectively. The result is coerced to a (signed) int when returned since Java has no unsigned integer type.
      Throws:
      NumberFormatException
    • parseInt64

      static long parseInt64(String text) throws NumberFormatException
      Parse a 64-bit signed integer from the text. Unlike the Java standard Integer.parseInt(), this function recognizes the prefixes "0x" and "0" to signify hexidecimal and octal numbers, respectively.
      Throws:
      NumberFormatException
    • parseUInt64

      static long parseUInt64(String text) throws NumberFormatException
      Parse a 64-bit unsigned integer from the text. Unlike the Java standard Integer.parseInt(), this function recognizes the prefixes "0x" and "0" to signify hexidecimal and octal numbers, respectively. The result is coerced to a (signed) long when returned since Java has no unsigned long type.
      Throws:
      NumberFormatException
    • parseInteger

      private static long parseInteger(String text, boolean isSigned, boolean isLong) throws NumberFormatException
      Throws:
      NumberFormatException