public final class TokenBuilder extends Object
Tokens
.
It bears some resemblance to Java's StringBuilder
.Modifier and Type | Field and Description |
---|---|
static byte |
BOLD
Bold flag.
|
static byte |
HLINE
Half new line.
|
static byte |
MARK
Mark flag.
|
static byte |
NLINE
New line.
|
static byte |
NORM
Standard flag.
|
static byte |
ULINE
Underline flag.
|
Constructor and Description |
---|
TokenBuilder()
Empty constructor.
|
TokenBuilder(byte[] token)
Constructor, specifying an initial token.
|
TokenBuilder(int capacity)
Constructor, specifying an initial internal array size.
|
TokenBuilder(String string)
Constructor, specifying an initial string.
|
Modifier and Type | Method and Description |
---|---|
TokenBuilder |
add(byte[] value)
Adds a byte array to the token.
|
TokenBuilder |
add(byte[] value,
int start,
int end)
Adds part of a byte array to the token.
|
TokenBuilder |
add(int cp)
Adds the specified UTF8 codepoint.
|
TokenBuilder |
add(String string)
Adds a string to the token.
|
TokenBuilder |
addByte(byte value)
Adds a single byte to the token.
|
TokenBuilder |
addExt(Object object,
Object... ext)
Adds the string representation of an object.
|
TokenBuilder |
addInt(int value)
Adds an integer value to the token.
|
TokenBuilder |
addLong(long value)
Adds a number to the token.
|
TokenBuilder |
addSep(Object[] objects,
String sep)
Adds multiple strings to the token, separated by the specified string.
|
TokenBuilder |
bold()
Adds a bold flag.
|
int |
cl(int pos)
Returns the length of the codepoints stored at the specified position.
|
int |
cp(int pos)
Returns the codepoint stored at the specified position.
|
void |
delete(int pos,
int length)
Deletes bytes from the token.
|
byte[] |
finish()
Returns the token as byte array, and invalidates the internal array.
|
byte |
get(int pos)
Returns the byte stored at the specified position.
|
TokenBuilder |
hline()
Adds a half new line.
|
TokenBuilder |
insert(int pos,
int cp)
Inserts the specified UTF8 character.
|
boolean |
isEmpty()
Tests if the token is empty.
|
byte[] |
next()
Returns the token as byte array and resets the token buffer.
|
TokenBuilder |
nline()
Adds a new line.
|
TokenBuilder |
norm()
Adds a norm flag.
|
TokenBuilder |
reset()
Resets the token buffer.
|
void |
set(int pos,
byte value)
Sets a byte at the specified position.
|
int |
size()
Returns the number of bytes.
|
void |
size(int sz)
Sets the number of bytes.
|
byte[] |
toArray()
Returns the token as byte array.
|
static byte[] |
token(Object object)
Returns a token representation of the specified object.
|
String |
toString() |
TokenBuilder |
trim()
Trims leading and trailing whitespaces.
|
TokenBuilder |
uline()
Adds an underline toggle flag.
|
public static final byte HLINE
public static final byte BOLD
public static final byte NORM
public static final byte MARK
public static final byte ULINE
public static final byte NLINE
public TokenBuilder()
public TokenBuilder(int capacity)
capacity
- initial array capacitypublic TokenBuilder(String string)
string
- initial stringpublic TokenBuilder(byte[] token)
token
- initial tokenpublic int size()
public void size(int sz)
sz
- number of bytespublic boolean isEmpty()
public TokenBuilder reset()
public TokenBuilder bold()
public TokenBuilder uline()
public TokenBuilder norm()
public TokenBuilder nline()
public TokenBuilder hline()
public TokenBuilder add(int cp)
cp
- the codepoint to be addedpublic TokenBuilder insert(int pos, int cp)
pos
- insertion positioncp
- the character to be addedpublic int cp(int pos)
pos
- positionpublic int cl(int pos)
pos
- positionpublic byte get(int pos)
pos
- positionpublic void set(int pos, byte value)
value
- byte to be setpos
- positionpublic void delete(int pos, int length)
pos
- positionlength
- number of bytes to be removedpublic TokenBuilder addByte(byte value)
value
- the byte to be addedpublic TokenBuilder addInt(int value)
value
- value to be addedpublic TokenBuilder addLong(long value)
value
- value to be addedpublic TokenBuilder add(byte[] value)
value
- the byte array to be addedpublic TokenBuilder add(byte[] value, int start, int end)
value
- the byte array to be addedstart
- start positionend
- end positionpublic TokenBuilder add(String string)
string
- the string to be addedpublic TokenBuilder addSep(Object[] objects, String sep)
objects
- the object to be addedsep
- separator stringpublic TokenBuilder addExt(Object object, Object... ext)
"%"
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.object
- object to be extendedext
- optional extensionspublic static byte[] token(Object object)
null
references are replaced by the string "null
".Throwable
are converted to a string representation via
Util.message(java.lang.Throwable)
.Class
are converted via Util.className(Class)
.Object.toString()
is called.object
- objectpublic TokenBuilder trim()
public byte[] toArray()
public byte[] next()
toArray()
and reset()
.public byte[] finish()
Copyright © 2005–2015 BaseX Team. All rights reserved.