Package io.protostuff.parser
Class TextFormat
- java.lang.Object
-
- io.protostuff.parser.TextFormat
-
public final class TextFormat extends java.lang.ObjectProvide ascii text parsing and formatting support for proto2 instances. The implementation largely follows google/protobuf/text_format.cc.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classTextFormat.InvalidEscapeSequenceExceptionThrown byunescapeBytes(java.lang.CharSequence)andunescapeText(java.lang.String)when an invalid escape sequence is seen.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.nio.charset.CharsetISO_8859_1(package private) static java.nio.charset.CharsetUTF8
-
Constructor Summary
Constructors Modifier Constructor Description privateTextFormat()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static intdigitValue(char c)Interpret a character as a digit (in any base up to 36) and return the numeric value.(package private) static java.lang.StringBuilderescapeBytes(java.nio.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.(package private) static java.lang.StringescapeText(java.lang.String input)Like#escapeBytes(ByteString), but escapes a text string.private static booleanisHex(char c)Is this a hex digit?private static booleanisOctal(char c)Is this an octal digit?(package private) static intparseInt32(java.lang.String text)Parse a 32-bit signed integer from the text.(package private) static longparseInt64(java.lang.String text)Parse a 64-bit signed integer from the text.private static longparseInteger(java.lang.String text, boolean isSigned, boolean isLong)(package private) static intparseUInt32(java.lang.String text)Parse a 32-bit unsigned integer from the text.(package private) static longparseUInt64(java.lang.String text)Parse a 64-bit unsigned integer from the text.(package private) static java.nio.ByteBufferunescapeBytes(java.lang.CharSequence input)Un-escape a byte sequence as escaped using#escapeBytes(ByteString).(package private) static java.lang.StringunescapeText(java.lang.String input)Un-escape a text string as escaped usingescapeText(String).
-
-
-
Method Detail
-
escapeBytes
static java.lang.StringBuilder escapeBytes(java.nio.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 java.nio.ByteBuffer unescapeBytes(java.lang.CharSequence input)
Un-escape a byte sequence as escaped using#escapeBytes(ByteString). Two-digit hex escapes (starting with "\x") are also recognized.
-
escapeText
static java.lang.String escapeText(java.lang.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 java.lang.String unescapeText(java.lang.String input)
Un-escape a text string as escaped usingescapeText(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 likeCharacter.digit()but we don't accept non-ASCII digits.
-
parseInt32
static int parseInt32(java.lang.String text) throws java.lang.NumberFormatExceptionParse a 32-bit signed integer from the text. Unlike the Java standardInteger.parseInt(), this function recognizes the prefixes "0x" and "0" to signify hexidecimal and octal numbers, respectively.- Throws:
java.lang.NumberFormatException
-
parseUInt32
static int parseUInt32(java.lang.String text) throws java.lang.NumberFormatExceptionParse a 32-bit unsigned integer from the text. Unlike the Java standardInteger.parseInt(), this function recognizes the prefixes "0x" and "0" to signify hexidecimal and octal numbers, respectively. The result is coerced to a (signed)intwhen returned since Java has no unsigned integer type.- Throws:
java.lang.NumberFormatException
-
parseInt64
static long parseInt64(java.lang.String text) throws java.lang.NumberFormatExceptionParse a 64-bit signed integer from the text. Unlike the Java standardInteger.parseInt(), this function recognizes the prefixes "0x" and "0" to signify hexidecimal and octal numbers, respectively.- Throws:
java.lang.NumberFormatException
-
parseUInt64
static long parseUInt64(java.lang.String text) throws java.lang.NumberFormatExceptionParse a 64-bit unsigned integer from the text. Unlike the Java standardInteger.parseInt(), this function recognizes the prefixes "0x" and "0" to signify hexidecimal and octal numbers, respectively. The result is coerced to a (signed)longwhen returned since Java has no unsigned long type.- Throws:
java.lang.NumberFormatException
-
parseInteger
private static long parseInteger(java.lang.String text, boolean isSigned, boolean isLong) throws java.lang.NumberFormatException- Throws:
java.lang.NumberFormatException
-
-