public class SimpleCodeWriter extends CodeWriter
Modifier and Type | Class and Description |
---|---|
protected class |
SimpleCodeWriter.State |
Modifier and Type | Field and Description |
---|---|
protected boolean |
breakAll |
protected int |
lmargin |
protected java.util.Stack<SimpleCodeWriter.State> |
lmargins |
protected java.io.PrintWriter |
output |
protected int |
pos |
protected int |
rmargin |
protected int |
width |
Constructor and Description |
---|
SimpleCodeWriter(java.io.OutputStream o,
int width_) |
SimpleCodeWriter(java.io.PrintWriter o,
int width_) |
SimpleCodeWriter(java.io.Writer o,
int width_) |
Modifier and Type | Method and Description |
---|---|
void |
allowBreak(int n,
int level,
java.lang.String alt,
int altlen)
Insert a break (an optional newline).
|
void |
begin(int n)
Start a new block with a relative indentation of
n
characters. |
void |
close()
Flush all formatted text, reset formatter state, and
close the underlying writer.
|
void |
end()
Terminate the most recent outstanding
begin . |
boolean |
flush()
Flush all formatted text to the underlying writer.
|
boolean |
flush(boolean format)
Like
flush , but passing format=false
causes output to be generated in the fastest way possible, with
all breaks broken. |
void |
newline()
Force a newline.
|
void |
newline(int n,
int level)
newline with a specified indentation and level.
|
java.lang.String |
toString()
toString is not really supported by this implementation.
|
void |
unifiedBreak(int n,
int level,
java.lang.String alt,
int altlen)
Insert a unified break.
|
void |
write(java.lang.String s)
Print the string
s verbatim on the output stream. |
void |
write(java.lang.String s,
int length)
Print the string
s on the output stream. |
allowBreak, allowBreak, newline, unifiedBreak
protected java.io.PrintWriter output
protected int width
protected int rmargin
protected int lmargin
protected boolean breakAll
protected java.util.Stack<SimpleCodeWriter.State> lmargins
protected int pos
public SimpleCodeWriter(java.io.OutputStream o, int width_)
public SimpleCodeWriter(java.io.PrintWriter o, int width_)
public SimpleCodeWriter(java.io.Writer o, int width_)
public void write(java.lang.String s)
CodeWriter
s
verbatim on the output stream.write
in class CodeWriter
s
- the string to print.public void write(java.lang.String s, int length)
CodeWriter
s
on the output stream. Pretend that it
has width length
even if it has a different number of
characters. This is useful when the string contains escape sequences,
HTML character entity references, etc.write
in class CodeWriter
public void begin(int n)
CodeWriter
n
characters.begin
in class CodeWriter
public void end()
CodeWriter
begin
.end
in class CodeWriter
public void allowBreak(int n, int level, java.lang.String alt, int altlen)
CodeWriter
allowBreak
in class CodeWriter
n
- indentation relative to the current block if the newline is
inserted. Requires: n >= 0level
- the level of the break. Requires: level >= 0alt
- if no newline is inserted, the string alt
is
output instead. Requires: alt != nullaltlen
- the length of 'alt' in characterspublic void unifiedBreak(int n, int level, java.lang.String alt, int altlen)
CodeWriter
allowBreak
, but unified breaks should also break if any break of
the same level in the same block is broken, whereas ordinary breaks do
not necessarily break in this case. That is, unified breaks act as if
they were slightly lower level than other breaks of the same level
(including other unified breaks!).unifiedBreak
in class CodeWriter
n
- the relative indentationlevel
- the level of the breakalt
- the alternative textaltlen
- the length in characters that 'alt' will be treated as taking up.CodeWriter.allowBreak(int, int, java.lang.String, int)
public void newline()
CodeWriter
newline
in class CodeWriter
public void newline(int n, int level)
CodeWriter
newline
in class CodeWriter
public boolean flush() throws java.io.IOException
CodeWriter
flush
in class CodeWriter
java.io.IOException
public boolean flush(boolean format) throws java.io.IOException
CodeWriter
flush
, but passing format=false
causes output to be generated in the fastest way possible, with
all breaks broken.flush
in class CodeWriter
format
- whether to pretty-print the outputjava.io.IOException
public void close() throws java.io.IOException
CodeWriter
close
in interface java.lang.AutoCloseable
close
in class CodeWriter
java.io.IOException
public java.lang.String toString()
toString
in class CodeWriter