Package org.basex.util
Class TokenBuilder
java.lang.Object
org.basex.util.TokenBuilder
This class serves as an efficient constructor for
Tokens.
It bears some resemblance to Java's StringBuilder.- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBold flag.static final intHalf new line.static final intMark flag.static final byteNew line.static final intStandard flag.static final intUnicode, private area (end).static final intUnicode, private area (start).static final intUnderline flag. -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor.TokenBuilder(byte[] token) Constructor with initial token.TokenBuilder(long capacity) Constructor with initial array capacity. -
Method Summary
Modifier and TypeMethodDescriptionadd(byte[] token) Adds a token to the token.add(byte[] token, int start, int end) Adds a subtoken.add(int cp) Adds the specified character.Adds an object to the token.Adds a string to the token.Adds multiple strings to the token, separated by the specified string.addByte(byte value) Adds a single byte to the token.Adds the string representation of an object.addInt(int value) Adds an integer value to the token.addLong(long value) Adds a number to the token.bold()Adds a bold flag.intcl(int pos) Returns the length of the codepoints stored at the specified position.intcp(int pos) Returns the codepoint stored at the specified position.delete(int start, int end) Deletes bytes from the token.byte[]finish()Returns the token as byte array, and invalidates the internal array.byteget(int pos) Returns the byte stored at the specified position.hline()Adds a half new line.booleanisEmpty()Tests if the token is empty.byte[]next()Returns the token as byte array and resets the token buffer.nline()Adds a new line.norm()Adds a norm flag.Normalizes newlines.reset()Resets the token buffer.voidset(int pos, byte value) Sets a byte at the specified position.intsize()Returns the number of bytes.voidsize(int sz) Sets the number of bytes.byte[]toArray()Returns the token as byte array.toString()trim()Trims leading and trailing whitespaces.uline()Adds an underline toggle flag.
-
Field Details
-
NLINE
public static final byte NLINENew line.- See Also:
-
PRIVATE_START
public static final int PRIVATE_STARTUnicode, private area (start).- See Also:
-
PRIVATE_END
public static final int PRIVATE_ENDUnicode, private area (end).- See Also:
-
HLINE
public static final int HLINEHalf new line.- See Also:
-
BOLD
public static final int BOLDBold flag.- See Also:
-
NORM
public static final int NORMStandard flag.- See Also:
-
MARK
public static final int MARKMark flag.- See Also:
-
ULINE
public static final int ULINEUnderline flag.- See Also:
-
-
Constructor Details
-
TokenBuilder
public TokenBuilder()Empty constructor. -
TokenBuilder
public TokenBuilder(long capacity) Constructor with initial array capacity.- Parameters:
capacity- array capacity
-
TokenBuilder
public TokenBuilder(byte[] token) Constructor with initial token.- Parameters:
token- initial token
-
-
Method Details
-
size
public int size()Returns the number of bytes.- Returns:
- number of bytes
-
size
public void size(int sz) Sets the number of bytes. Note that no bound check is performed by this method.- Parameters:
sz- number of bytes
-
isEmpty
public boolean isEmpty()Tests if the token is empty.- Returns:
- result of check
-
reset
Resets the token buffer.- Returns:
- self reference
-
bold
Adds a bold flag. This method should only be called to control text rendering in the visual front end.- Returns:
- self reference
-
uline
Adds an underline toggle flag. This method should only be called to control text rendering in the visual front end.- Returns:
- self reference
-
norm
Adds a norm flag. This method should only be called to control text rendering in the visual front end.- Returns:
- self reference
-
hline
Adds a half new line. This method should only be called to control text rendering in the visual front end.- Returns:
- self reference
-
nline
Adds a new line. This method should only be called to control text rendering in the visual front end.- Returns:
- self reference
-
add
Adds the specified character. CalladdInt(int)to add the string value of an integer.- Parameters:
cp- codepoint of the character- Returns:
- self reference
-
cp
public int cp(int pos) Returns the codepoint stored at the specified position.- Parameters:
pos- position- Returns:
- character
-
cl
public int cl(int pos) Returns the length of the codepoints stored at the specified position.- Parameters:
pos- position- Returns:
- character
-
get
public byte get(int pos) Returns the byte stored at the specified position.- Parameters:
pos- position- Returns:
- byte
-
set
public void set(int pos, byte value) Sets a byte at the specified position.- Parameters:
value- byte to be setpos- position
-
delete
Deletes bytes from the token.- Parameters:
start- start positionend- end position- Returns:
- self reference
-
addByte
Adds a single byte to the token.- Parameters:
value- the byte to be added- Returns:
- self reference
-
addInt
Adds an integer value to the token.- Parameters:
value- value to be added- Returns:
- self reference
-
addLong
Adds a number to the token.- Parameters:
value- value to be added- Returns:
- self reference
-
add
Adds a token to the token.- Parameters:
token- the token to be added- Returns:
- self reference
-
add
Adds a subtoken.- Parameters:
token- the tokenstart- start positionend- end position- Returns:
- self reference
-
add
Adds a string to the token.- Parameters:
string- the string to be added- Returns:
- self reference
-
addAll
Adds multiple strings to the token, separated by the specified string.- Parameters:
objects- the object to be addedseparator- separator string- Returns:
- self reference
-
add
Adds an object to the token.- Parameters:
object- the object to be added- Returns:
- self reference
-
addExt
Adds the string representation of an object. The specified string may contain%characters as place holders. All place holders will be replaced by the specified extensions. If a digit is specified after the place holder character, it will be interpreted as insertion position.- Parameters:
object- object to be extendedextensions- optional extension strings- Returns:
- self reference
-
trim
Trims leading and trailing whitespaces.- Returns:
- self reference
-
normalize
Normalizes newlines.- Returns:
- self reference
-
toArray
public byte[] toArray()Returns the token as byte array.- Returns:
- token
-
next
public byte[] next()Returns the token as byte array and resets the token buffer. The call of this function is identical to callingtoArray()andreset().- Returns:
- token
-
finish
public byte[] finish()Returns the token as byte array, and invalidates the internal array. Warning: the function must only be called if the builder is discarded afterwards.- Returns:
- token
-
toString
-