Class LineWrapper
java.lang.Object
org.tquadrat.foundation.javacomposer.internal.LineWrapper
- All Implemented Interfaces:
Closeable
,AutoCloseable
@ClassVersion(sourceVersion="$Id: LineWrapper.java 1105 2024-02-28 12:58:46Z tquadrat $")
@API(status=INTERNAL,
since="0.0.5")
public final class LineWrapper
extends Object
implements Closeable
Implements soft line wrapping on an
Appendable
.
To use, append characters using
append(CharSequence)
or soft-wrapping spaces using
wrappingSpace(int)
.- Author:
- Square,Inc.
- Modified by:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: LineWrapper.java 1105 2024-02-28 12:58:46Z tquadrat $
- Since:
- 0.0.5
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.javacomposer.internal.LineWrapper"
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringBuilder
Characters written since the last wrapping space that haven't yet been flushed.private boolean
The flag that indicates whether this line wrapper was already closed.private int
The number of characters since the most recent newline.private final int
The maximum line length.private final String
The indentation String.private int
-1 if we have no buffering; otherwise the number ofm_Indent
s to write after wrapping.private LineWrapper.FlushType
null
if we have no buffering; otherwise the type to pass to the next call toflush(org.tquadrat.foundation.javacomposer.internal.LineWrapper.FlushType)
.private final Appendable
The output target. -
Constructor Summary
ConstructorsConstructorDescriptionLineWrapper
(Appendable out, String indent, int columnLimit) Creates a newLineWrapper
instance. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
append
(CharSequence input) Emits the given String.final void
close()
This implementation flushes any outstanding text and forbid future writes to this line wrapper.private final void
flush
(LineWrapper.FlushType flushType) Writes the space followed by any buffered text that follows it.final void
wrappingSpace
(int indentLevel) Emits either a space or a newline character.final void
zeroWidthSpace
(int indentLevel) Emits a newline character if the line will exceed its limit, otherwise do nothing.
-
Field Details
-
m_Buffer
Characters written since the last wrapping space that haven't yet been flushed. -
m_Closed
The flag that indicates whether this line wrapper was already closed. -
m_Column
-
m_ColumnLimit
The maximum line length. -
m_Indent
The indentation String. -
m_IndentLevel
-1 if we have no buffering; otherwise the number ofm_Indent
s to write after wrapping. -
m_NextFlush
null
if we have no buffering; otherwise the type to pass to the next call toflush(org.tquadrat.foundation.javacomposer.internal.LineWrapper.FlushType)
. -
m_Out
The output target.
-
-
Constructor Details
-
LineWrapper
Creates a newLineWrapper
instance.- Parameters:
out
- The output target.indent
- The indentation string.columnLimit
- The maximum line length.
-
-
Method Details
-
append
Emits the given String. This may be buffered to permit line wraps to be inserted.- Parameters:
input
- The string to emit.- Throws:
IOException
- A problem occurred when writing to the output target.
-
close
This implementation flushes any outstanding text and forbid future writes to this line wrapper.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
flush
Writes the space followed by any buffered text that follows it.- Parameters:
flushType
- The flush type.- Throws:
IOException
- A problem occurred when writing to the output target.
-
wrappingSpace
Emits either a space or a newline character.- Parameters:
indentLevel
- The indentation level.- Throws:
IOException
- A problem occurred when writing to the output target.
-
zeroWidthSpace
Emits a newline character if the line will exceed its limit, otherwise do nothing.- Parameters:
indentLevel
- The indentation level.- Throws:
IOException
- A problem occurred when writing to the output target.
-