public final class LuaFormat extends Object
Modifier and Type | Field and Description |
---|---|
static char |
CHAR_BELL
The '\a' character.
|
static char |
CHAR_VERTICAL_TAB
The '\v' character.
|
static ByteString |
FALSE
The byte string representation of false.
|
static ByteString |
INF
The byte string representation of infinity.
|
static ByteString |
NAN
The byte string representation of NaN.
|
static ByteString |
NIL
The byte string representation of nil.
|
static ByteString |
TRUE
The byte string representation of true.
|
static ByteString |
TYPENAME_BOOLEAN
Byte string representation of the Lua
boolean type. |
static ByteString |
TYPENAME_FUNCTION
Byte string representation of the Lua
function type. |
static ByteString |
TYPENAME_LUAOBJECT
Byte string representation of the Lua
lua object type. |
static ByteString |
TYPENAME_NIL
Byte string representation of the Lua
nil type. |
static ByteString |
TYPENAME_NUMBER
Byte string representation of the Lua
number type. |
static ByteString |
TYPENAME_STRING
Byte string representation of the Lua
string type. |
static ByteString |
TYPENAME_TABLE
Byte string representation of the Lua
table type. |
static ByteString |
TYPENAME_THREAD
Byte string representation of the Lua
thread type. |
static ByteString |
TYPENAME_USERDATA
Byte string representation of the Lua
userdata type. |
Modifier and Type | Method and Description |
---|---|
static String |
escape(ByteString byteString)
Returns a string
esc formed from the byte string s such that
when esc is read by a Lua lexer as a string literal, it evaluates to
a byte string equal to s . |
static String |
escape(CharSequence s)
Returns a string
esc formed from the character sequence s such that
when esc is read by a Lua lexer as a string literal, it evaluates to a string equal
to s . |
static boolean |
isKeyword(String s)
Returns
true iff the string s is a keyword in Lua. |
static boolean |
isValidName(String s)
Returns
true iff the string s is a valid Lua name. |
static double |
parseFloat(String s)
Parses the string
s as a float according to the Lua lexer rules. |
static long |
parseInteger(String s)
Parses the string
s as an integer according to the Lua lexer rules. |
static ByteString |
toByteString(boolean b)
Returns the Lua format byte string representation of the boolean value
b
as a byte string. |
static ByteString |
toByteString(double f)
Returns the Lua format byte string representation of the float value
f . |
static ByteString |
toByteString(long l)
Returns the Lua format byte string representation of the integer value
l . |
static String |
toString(boolean b)
Returns the Lua format string representation of the boolean value
b . |
static String |
toString(double f)
Returns the Lua format string representation of the float value
f . |
static String |
toString(long l)
Returns the Lua format string representation of the integer value
l . |
static Double |
tryParseFloat(String s)
Parses
s as a float following the Lua lexer rules. |
static Long |
tryParseInteger(String s)
Parses
s as an integer following the Lua lexer rules. |
static Number |
tryParseNumeral(String s)
Parses
s as a number following the Lua lexer rules. |
public static final ByteString NIL
public static final ByteString TRUE
public static final ByteString FALSE
public static final ByteString INF
public static final ByteString NAN
public static final ByteString TYPENAME_NIL
nil
type.public static final ByteString TYPENAME_BOOLEAN
boolean
type.public static final ByteString TYPENAME_NUMBER
number
type.public static final ByteString TYPENAME_STRING
string
type.public static final ByteString TYPENAME_TABLE
table
type.public static final ByteString TYPENAME_FUNCTION
function
type.public static final ByteString TYPENAME_USERDATA
userdata
type.public static final ByteString TYPENAME_THREAD
thread
type.public static final ByteString TYPENAME_LUAOBJECT
lua object
type.public static final char CHAR_BELL
public static final char CHAR_VERTICAL_TAB
public static String toString(boolean b)
b
.
Note: this method returns a java.lang.String
. In order to
obtain a byte string, use toByteString(boolean)
rather than
wrapping the result of this method using ByteString.of(String)
.
b
- the boolean valueb
public static ByteString toByteString(boolean b)
b
as a byte string.b
- the boolean valueb
public static String toString(long l)
l
.
Note: this method returns a java.lang.String
. In order to
obtain a byte string, use toByteString(long)
rather than
wrapping the result of this method using ByteString.of(String)
.
l
- the integer valuel
public static ByteString toByteString(long l)
l
.l
- the integer valuel
public static String toString(double f)
f
.
Note: this method returns a java.lang.String
. In order to
obtain a byte string, use toByteString(long)
rather than
wrapping the result of this method using ByteString.of(String)
.
f
- the float valuef
public static ByteString toByteString(double f)
f
.f
- the float valuef
public static long parseInteger(String s) throws NumberFormatException
s
as an integer according to the Lua lexer rules.
When s
is not an integer numeral, throws a NumberFormatException
.
This method ignores leading and trailing whitespace in s
.
s
- string to be parsed, must not be null
s
NullPointerException
- if s
is null
NumberFormatException
- if s
is not a valid Lua format string representing
an integer valuepublic static double parseFloat(String s) throws NumberFormatException
s
as a float according to the Lua lexer rules.
When s
is not a float numeral, throws a NumberFormatException
.
This method ignores leading and trailing whitespace in s
.
s
- the string to be parsed, must not be null
s
NullPointerException
- if s
is null
NumberFormatException
- if s
is not a valid Lua format string representing
a float valuepublic static Long tryParseInteger(String s)
s
as an integer following the Lua lexer rules. When s
is
an integer numeral, returns its value boxed as a Long
. Otherwise, returns
null
.
This is a variant of parseInteger(String)
that signals invalid input
by returning null
rather than throwing a NumberFormatException
.
s
- the string to be parsed, must not be null
s
if s
is an integer
numeral; null
otherwiseNullPointerException
- if s
is null
public static Double tryParseFloat(String s)
s
as a float following the Lua lexer rules. When s
is
a float numeral, returns its value boxed as a Double
. Otherwise, returns
null
.
This is a variant of parseFloat(String)
that signals invalid input
by returning null
rather than throwing a NumberFormatException
.
s
- the string to be parsed, must not be null
s
if s
is an float
numeral; null
otherwiseNullPointerException
- if s
is null
public static Number tryParseNumeral(String s)
s
as a number following the Lua lexer rules. When s
is
a numeral, returns its value boxed either as a Long
(for integer numerals)
or a Double
(for float numerals). Otherwise, returns null
.
Note an integer numeral is also a float numeral, but not all float numerals are
integer numerals. This method returns the "most canonical" representation of the numeric
value represented by s
: it first tries to parse s
as an integer,
attempting to parse s
as a float only when s
is not an integer numeral.
s
- the string to be parsed, must not be null
s
, or null
if s
is not a numeralpublic static String escape(CharSequence s)
esc
formed from the character sequence s
such that
when esc
is read by a Lua lexer as a string literal, it evaluates to a string equal
to s
. The resulting string is enclosed in double quotes ("
).s
- the character sequence to escape, must not be null
s
NullPointerException
- if s
is null
public static String escape(ByteString byteString)
esc
formed from the byte string s
such that
when esc
is read by a Lua lexer as a string literal, it evaluates to
a byte string equal to s
. The resulting string is enclosed in double quotes
("
).byteString
- the byte sequence sequence to escape, must not be null
s
NullPointerException
- if s
is null
public static boolean isKeyword(String s)
true
iff the string s
is a keyword in Lua.
A keyword in Lua is one of the following strings:
"and"
, "break"
, "do"
, "else"
, "elseif"
,
"end"
, "false"
, "for"
, "function"
, "goto"
,
"if"
, "in"
, "local"
, "nil"
, "not"
,
"or"
, "repeat"
, "return"
, "then"
, "true"
,
"until"
, "while"
.
s
- the string to be examined, may be null
true
if s
is a Lua keyword; false
otherwisepublic static boolean isValidName(String s)
true
iff the string s
is a valid Lua name.
According to ยง3.1 of the Lua Reference Manual,
Names (also called identifiers) in Lua can be any string of letters, digits, and underscores, not beginning with a digit and not being a reserved word.
This implementation treats letters as characters in the ranges
'a'
...'z'
and 'A'
...'Z'
, and numbers as characters in
the range '0'
...'9'
.
s
- the string to be checked for being a valid name, may be null
true
if s
is a valid name in Lua; false
otherwiseCopyright © 2016–2017. All rights reserved.