|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.luaj.vm.LValue
org.luaj.vm.LString
public class LString
A String implementation for Lua using bytes instead of chars. This should have the following advantages: (1) We can use strings as byte buffers, as Lua does, and therefore avoid questions about how to adapt Lua APIs that use strings with binary data. (2) Half the memory usage when strings are primarily ASCII TODO: Decide if/when to copy the bytes to a new array to ensure memory does not "leak" in the form of unused portions of byte arrays. Currently, for efficiency, new LStrings and substrings never create copies.
| Field Summary | |
|---|---|
static LString[] |
LTYPENAMES
|
byte[] |
m_bytes
|
int |
m_hash
|
int |
m_length
|
int |
m_offset
|
| Fields inherited from class org.luaj.vm.LValue |
|---|
TM_INDEX, TM_METATABLE, TM_MODE, TM_NEWINDEX |
| Constructor Summary | |
|---|---|
LString(byte[] bytes)
Construct a string from the given byte array. |
|
LString(byte[] bytes,
int off,
int len)
Construct a string from the given byte array and range. |
|
LString(java.lang.String string)
Construct a Lua string from the given Java string. |
|
| Method Summary | |
|---|---|
int |
charAt(int index)
|
int |
compareTo(LString o)
|
void |
copyInto(int strOffset,
byte[] bytes,
int arrayOffset,
int len)
Copy the bytes of the string into the given byte array. |
static void |
encodeToUtf8(java.lang.String string,
byte[] bytes,
int startOffset)
Encode the given Java string as UTF-8 bytes, writing the result to bytes starting at offset. |
static boolean |
equals(byte[] a,
int i,
byte[] b,
int j,
int n)
|
static boolean |
equals(LString a,
int i,
LString b,
int j,
int n)
|
boolean |
equals(java.lang.Object o)
|
static LTable |
getMetatable()
Get the metatable for all string values. |
int |
hashCode()
|
int |
indexOf(byte b,
int start)
|
int |
indexOf(LString s,
int start)
|
int |
indexOfAny(LString accept)
Java version of strpbrk, which is a terribly named C function. |
boolean |
isNumber()
Returns true if this is or can be made into a number |
boolean |
isString()
Return true if this is a lua string, meaning it is either a LString or LNumber,since all numbers are convertible to strings in lua |
int |
lastIndexOf(LString s)
|
int |
length()
|
static int |
lengthAsUtf8(java.lang.String string)
Count the number of bytes required to encode the string as UTF-8. |
LString |
luaAsString()
Get the value as a LString |
boolean |
luaBinCmpString(int opcode,
LString rhs)
|
boolean |
luaBinCmpUnknown(int opcode,
LValue lhs)
|
LValue |
luaBinOpDouble(int opcode,
double m_value)
|
LValue |
luaBinOpInteger(int opcode,
int m_value)
|
LValue |
luaBinOpUnknown(int opcode,
LValue lhs)
|
int |
luaByte(int index)
|
void |
luaConcatTo(java.io.ByteArrayOutputStream baos)
Concatenate this value to a ByteArrayOutputStream |
LTable |
luaGetMetatable()
Valid for all types: get a metatable. |
int |
luaGetType()
Valid for all types: return the int value identifying the type of this value |
int |
luaLength()
Built-in opcode LEN, for Strings and Tables |
LValue |
luaToNumber()
Convert to a number if possible, or nil otherwise |
LValue |
luaToNumber(int base)
|
LValue |
luaUnaryMinus()
Arithmetic negative |
static LString |
newStringCopy(byte[] buf,
int off,
int len)
|
static LString |
newStringCopy(LString src)
|
static LString |
newStringNoCopy(byte[] buf,
int off,
int len)
|
LString |
substring(int beginIndex,
int endIndex)
|
java.io.ByteArrayInputStream |
toInputStream()
Produce an InputStream instance from which the bytes of this LString can be read. |
java.lang.String |
toJavaString()
Convert to Java string using UTF-8 encoding |
static LString |
valueOf(double d)
|
static LString |
valueOf(int x)
|
static LString |
valueOf(java.lang.String s)
|
void |
write(java.io.OutputStream os)
|
void |
write(java.io.OutputStream os,
int offset,
int len)
Write the specified substring of this string to the given output stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public byte[] m_bytes
public int m_offset
public final int m_length
public final int m_hash
public static final LString[] LTYPENAMES
| Constructor Detail |
|---|
public LString(java.lang.String string)
public LString(byte[] bytes)
public LString(byte[] bytes,
int off,
int len)
| Method Detail |
|---|
public java.lang.String toJavaString()
toJavaString in class LValuepublic static LString newStringCopy(LString src)
public static LString newStringCopy(byte[] buf,
int off,
int len)
public static LString newStringNoCopy(byte[] buf,
int off,
int len)
public static int lengthAsUtf8(java.lang.String string)
public static void encodeToUtf8(java.lang.String string,
byte[] bytes,
int startOffset)
public boolean isString()
LValue
isString in class LValuepublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int compareTo(LString o)
public int hashCode()
hashCode in class java.lang.Objectpublic int length()
public LString substring(int beginIndex,
int endIndex)
public int charAt(int index)
public int indexOfAny(LString accept)
public int indexOf(byte b,
int start)
public int indexOf(LString s,
int start)
public int lastIndexOf(LString s)
public static LString valueOf(double d)
public static LString valueOf(int x)
public static LString valueOf(java.lang.String s)
public void write(java.io.OutputStream os,
int offset,
int len)
throws java.io.IOException
java.io.IOException
public void write(java.io.OutputStream os)
throws java.io.IOException
java.io.IOException
public void copyInto(int strOffset,
byte[] bytes,
int arrayOffset,
int len)
public java.io.ByteArrayInputStream toInputStream()
public boolean luaBinCmpUnknown(int opcode,
LValue lhs)
luaBinCmpUnknown in class LValue
public boolean luaBinCmpString(int opcode,
LString rhs)
luaBinCmpString in class LValue
public LValue luaBinOpDouble(int opcode,
double m_value)
luaBinOpDouble in class LValue
public LValue luaBinOpInteger(int opcode,
int m_value)
luaBinOpInteger in class LValue
public LValue luaBinOpUnknown(int opcode,
LValue lhs)
luaBinOpUnknown in class LValuepublic LValue luaUnaryMinus()
LValue
luaUnaryMinus in class LValuepublic LValue luaToNumber()
LValue
luaToNumber in class LValuepublic LValue luaToNumber(int base)
public LString luaAsString()
LValue
luaAsString in class LValuepublic int luaLength()
luaLength in class LValuepublic int luaGetType()
LValue
luaGetType in class LValuepublic LTable luaGetMetatable()
LValue
luaGetMetatable in class LValuepublic static LTable getMetatable()
public static boolean equals(LString a,
int i,
LString b,
int j,
int n)
public static boolean equals(byte[] a,
int i,
byte[] b,
int j,
int n)
public int luaByte(int index)
public void luaConcatTo(java.io.ByteArrayOutputStream baos)
LValue
luaConcatTo in class LValuepublic boolean isNumber()
isNumber in class LValue
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||