public final class TokenBuilder extends Object
Tokens
.
It bears some resemblance to Java's StringBuilder
.Modifier and Type | Field and Description |
---|---|
static int |
BOLD
Bold flag.
|
static int |
HLINE
Half new line.
|
static int |
MARK
Mark flag.
|
static byte |
NLINE
New line.
|
static int |
NORM
Standard flag.
|
static int |
PRIVATE_END
Unicode, private area (end).
|
static int |
PRIVATE_START
Unicode, private area (start).
|
static int |
ULINE
Underline flag.
|
Constructor and Description |
---|
TokenBuilder()
Empty constructor.
|
TokenBuilder(byte[] token)
Constructor with initial token.
|
TokenBuilder(long capacity)
Constructor with initial array capacity.
|
Modifier and Type | Method and Description |
---|---|
TokenBuilder |
add(byte[] token)
Adds a token to the token.
|
TokenBuilder |
add(byte[] token,
int start,
int end)
Adds a subtoken.
|
TokenBuilder |
add(int cp)
Adds the specified character.
|
TokenBuilder |
add(Object object)
Adds an object to the token.
|
TokenBuilder |
add(String string)
Adds a string to the token.
|
TokenBuilder |
addAll(Object[] objects,
String separator)
Adds multiple strings to the token, separated by the specified string.
|
TokenBuilder |
addByte(byte value)
Adds a single byte to the token.
|
TokenBuilder |
addExt(Object object,
Object... extensions)
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 |
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.
|
TokenBuilder |
delete(int start,
int end)
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.
|
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 |
normalize()
Normalizes newlines.
|
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.
|
String |
toString() |
TokenBuilder |
trim()
Trims leading and trailing whitespaces.
|
TokenBuilder |
uline()
Adds an underline toggle flag.
|
public static final byte NLINE
public static final int PRIVATE_START
public static final int PRIVATE_END
public static final int HLINE
public static final int BOLD
public static final int NORM
public static final int MARK
public static final int ULINE
public TokenBuilder()
public TokenBuilder(long capacity)
capacity
- array capacitypublic 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 hline()
public TokenBuilder nline()
public TokenBuilder add(int cp)
addInt(int)
to add the string value of an integer.cp
- codepoint of the characterpublic 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 TokenBuilder delete(int start, int end)
start
- start positionend
- end positionpublic 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[] token)
token
- the token to be addedpublic TokenBuilder add(byte[] token, int start, int end)
token
- the tokenstart
- start positionend
- end positionpublic TokenBuilder add(String string)
string
- the string to be addedpublic TokenBuilder addAll(Object[] objects, String separator)
objects
- the object to be addedseparator
- separator stringpublic TokenBuilder add(Object object)
object
- the object to be addedpublic TokenBuilder addExt(Object object, Object... extensions)
%
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 extendedextensions
- optional extension stringspublic TokenBuilder trim()
public TokenBuilder normalize()
public byte[] toArray()
public byte[] next()
toArray()
and reset()
.public byte[] finish()
Copyright © 2005–2023 BaseX Team. All rights reserved.