Documentation ¶
Index ¶
- Constants
- Variables
- func Apply[T FStringer](p Printer, elem T) error
- func ApplyForm[T FStringer](form FormatConfig, trav *Traversor, elem T) error
- func ApplyFormMany[T FStringer](form FormatConfig, trav *Traversor, elems []T) error
- func ApplyFunc[T any](p Printer, elem T, f FStringFunc[T]) error
- func ApplyFuncMany[T any](p Printer, f FStringFunc[T], elems []T) error
- func ApplyMany[T FStringer](p Printer, elems []T) error
- func ApplyTravFunc[T any](trav *Traversor, elem T, f FStringFunc[T]) error
- func ApplyTravFuncMany[T any](trav *Traversor, f FStringFunc[T], elems []T) error
- func FStringArray(format FormatConfig, values []string) (string, error)
- func Ffprint(out io.Writer, form FormatConfig, a ...interface{}) error
- func Ffprintf(out io.Writer, form FormatConfig, format string, a ...interface{}) error
- func Ffprintln(out io.Writer, form FormatConfig, a ...interface{}) error
- func Fprint(out io.Writer, form FormatConfig, strs ...string) error
- func FprintFString[T FStringer](out io.Writer, form FormatConfig, elem T) error
- func Fprintj(out io.Writer, form FormatConfig, sep string, strs ...string) error
- func Fprintjln(out io.Writer, form FormatConfig, sep string, lines ...string) error
- func Fprintln(out io.Writer, form FormatConfig, lines ...string) error
- func Sfprint(form FormatConfig, a ...interface{}) ([][][][]string, error)
- func Sfprintf(form FormatConfig, format string, a ...interface{}) ([][][][]string, error)
- func Sfprintln(form FormatConfig, a ...interface{}) ([][][][]string, error)
- func Sprint(form FormatConfig, strs ...string) ([][][][]string, error)
- func SprintFString[T FStringer](form FormatConfig, elem T) ([][][][]string, error)
- func Sprintj(form FormatConfig, sep string, strs ...string) ([][][][]string, error)
- func Sprintjln(form FormatConfig, sep string, lines ...string) ([][][][]string, error)
- func Sprintln(form FormatConfig, lines ...string) ([][][][]string, error)
- func Stringfy(doc [][][][]string) []string
- type ConfigOption
- type Configer
- type DelimiterConfig
- type FStringFunc
- type FStringer
- type FilePrinter
- type FormatConfig
- type IndentConfig
- type Printer
- type SeparatorConfig
- type SimplePrinter
- type StdPrinter
- type Traversor
- func (trav *Traversor) AcceptLine()
- func (trav *Traversor) AcceptWord()
- func (trav *Traversor) AddJoinedLine(sep string, fields ...string) error
- func (trav *Traversor) AddLine(line string) error
- func (trav *Traversor) AddLines(lines []string) error
- func (trav *Traversor) AppendJoinedString(sep string, fields ...string) error
- func (trav *Traversor) AppendRune(r rune) error
- func (trav *Traversor) AppendString(str string) error
- func (trav *Traversor) AppendStrings(strs []string) error
- func (trav *Traversor) Clean()
- func (trav *Traversor) EmptyLine()
- func (trav *Traversor) GetConfig(options ...ConfigOption) FormatConfig
- func (trav *Traversor) Print(a ...interface{}) error
- func (trav *Traversor) Printf(format string, a ...interface{}) error
- func (trav *Traversor) Println(a ...interface{}) error
- func (trav *Traversor) Write(p []byte) (int, error)
Constants ¶
const ( // DefaultIndentation is the default indentation string. DefaultIndentation string = " " // DefaultSeparator is the default separator string. DefaultSeparator string = ", " )
const ( // ConfInd_Idx is the index for the indentation configuration. ConfInd_Idx = iota // ConfDelL_Idx is the index for the left delimiter configuration. ConfDelL_Idx // ConfDelR_Idx is the index for the right delimiter configuration. ConfDelR_Idx // ConfSep_Idx is the index for the separator configuration. ConfSep_Idx )
const ( // NBSP is the non-breaking space rune. NBSP rune = '\u00A0' )
Variables ¶
var ( // DefaultIndentationConfig is the default indentation configuration. DefaultIndentationConfig *IndentConfig = NewIndentConfig(DefaultIndentation, 0) // DefaultSeparatorConfig is the default separator configuration. DefaultSeparatorConfig *SeparatorConfig = NewSeparator(DefaultSeparator, false) )
Functions ¶
func Apply ¶ added in v0.3.6
Apply applies a format to a stringer.
Parameters:
- p: The StdPrinter to use.
- elem: The element to format.
Returns:
- error: An error if the formatting fails.
Errors:
- *ErrInvalidParameter: If the StdPrinter is nil.
- *ErrFinalization: If the finalization of the page fails.
- any error returned by the element's FString method.
Behaviors:
- If the formatter is nil, the function uses the nil formatter.
- If the element is nil, the function does nothing.
func ApplyForm ¶ added in v0.3.6
func ApplyForm[T FStringer](form FormatConfig, trav *Traversor, elem T) error
ApplyForm is a function that applies the format to an element.
Parameters:
- form: The formatter to use for formatting.
- trav: The traversor to use for formatting.
- elem: The element to format.
Returns:
- error: An error if the formatting fails.
Behaviors:
- If the traversor is nil, the function does nothing.
func ApplyFormMany ¶ added in v0.3.6
func ApplyFormMany[T FStringer](form FormatConfig, trav *Traversor, elems []T) error
ApplyFormMany is a function that applies the format to multiple elements at once.
Parameters:
- form: The formatter to use for formatting.
- trav: The traversor to use for formatting.
- elems: The elements to format.
Returns:
- error: An error if type Errors.ErrAt if the formatting fails on a specific element.
Behaviors:
- If the traversor is nil, the function does nothing.
func ApplyFunc ¶ added in v0.3.6
func ApplyFunc[T any](p Printer, elem T, f FStringFunc[T]) error
ApplyFunc applies a format function to the StdPrinter.
Parameters:
- p: The StdPrinter to use.
- elem: The element to apply the function to.
- f: The function to apply.
Returns:
- error: An error if the function fails.
Errors:
- *ErrInvalidParameter: If the StdPrinter is nil.
- any error returned by the function.
func ApplyFuncMany ¶ added in v0.3.6
func ApplyFuncMany[T any](p Printer, f FStringFunc[T], elems []T) error
ApplyFuncMany applies a format function to the StdPrinter.
Parameters:
- p: The StdPrinter to use.
- f: The function to apply.
- elems: The elements to apply the function to.
Returns:
- error: An error if the function fails.
Errors:
- *ErrInvalidParameter: If the StdPrinter is nil.
- *Errors.ErrAt: If an error occurs on a specific element.
- any error returned by the function.
func ApplyMany ¶ added in v0.3.6
ApplyMany applies a format to a stringer.
Parameters:
- p: The StdPrinter to use.
- elems: The elements to format.
Returns:
- error: An error if the formatting fails.
Errors:
- *ErrInvalidParameter: If the StdPrinter is nil.
- *ErrFinalization: If the finalization of the page fails.
- *Errors.ErrAt: If an error occurs on a specific element.
Behaviors:
- If the formatter is nil, the function uses the nil formatter.
- If an element is nil, the function skips the element.
- If all elements are nil, the function does nothing.
func ApplyTravFunc ¶ added in v0.3.6
func ApplyTravFunc[T any](trav *Traversor, elem T, f FStringFunc[T]) error
ApplyTravFunc applies a function to the printer. Useful for when you want to apply a function that does not implement the FStringer interface.
Parameters:
- trav: The traversor to use.
- elem: The element to apply the function to.
- f: The function to apply.
Returns:
- error: An error if the function fails.
Errors:
- *ErrFinalization: If the finalization of the page fails.
- any error returned by the function.
func ApplyTravFuncMany ¶ added in v0.3.6
func ApplyTravFuncMany[T any](trav *Traversor, f FStringFunc[T], elems []T) error
ApplyTravFuncMany applies a function to the printer. Useful for when you want to apply a function that does not implement the FStringer interface.
Parameters:
- trav: The traversor to use.
- f: The function to apply.
- elems: The elements to apply the function to.
Returns:
- error: An error if the function fails.
Errors:
- *ErrFinalization: If the finalization of the page fails.
- *Errors.ErrAt: If an error occurs on a specific element.
- any error returned by the function.
func FStringArray ¶ added in v0.3.8
func FStringArray(format FormatConfig, values []string) (string, error)
FStringArray generates a formatted string representation of an array-like object.
Parameters:
- format: The format to use for printing.
- values: The values to print.
Returns:
- string: The formatted string.
- error: An error if the printing fails.
func Ffprint ¶ added in v0.3.9
func Ffprint(out io.Writer, form FormatConfig, a ...interface{}) error
Ffprint prints a formatted string.
Parameters:
- out: The writer to use.
- form: The formatter to use.
- a: The elements to print.
Returns:
- error: An error if the printing fails.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func Ffprintf ¶ added in v0.3.9
func Ffprintf(out io.Writer, form FormatConfig, format string, a ...interface{}) error
Ffprintf prints a formatted string.
Parameters:
- out: The writer to use.
- form: The formatter to use.
- format: The format string.
- a: The elements to print.
Returns:
- error: An error if the printing fails.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func Ffprintln ¶ added in v0.3.9
func Ffprintln(out io.Writer, form FormatConfig, a ...interface{}) error
Ffprintln prints a formatted string with a newline.
Parameters:
- out: The writer to use.
- form: The formatter to use.
- a: The elements to print.
Returns:
- error: An error if the printing fails.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func Fprint ¶ added in v0.3.6
func Fprint(out io.Writer, form FormatConfig, strs ...string) error
Fprint prints strings.
Parameters:
- out: The writer to use.
- form: The formatter to use.
- strs: The strings to print.
Returns:
- error: An error if the printing fails.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func FprintFString ¶ added in v0.3.9
func FprintFString[T FStringer](out io.Writer, form FormatConfig, elem T) error
FprintFString prints a formatted string.
Parameters:
- out: The writer to use.
- form: The formatter to use.
- elem: The element to print.
Returns:
- error: An error if the printing fails.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func Fprintj ¶ added in v0.3.9
Fprintj prints a joined string.
Parameters:
- out: The writer to use.
- form: The formatter to use.
- sep: The separator to use.
- strs: The strings to join.
Returns:
- error: An error if the printing fails.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func Fprintjln ¶ added in v0.3.9
Fprintjln prints a joined string with a newline.
Parameters:
- out: The writer to use.
- form: The formatter to use.
- sep: The separator to use.
- lines: The lines to join.
Returns:
- error: An error if the printing fails.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func Fprintln ¶ added in v0.3.6
func Fprintln(out io.Writer, form FormatConfig, lines ...string) error
Fprintln prints a string with a newline.
Parameters:
- out: The writer to use.
- form: The formatter to use.
- lines: The lines to print.
Returns:
- error: An error if the printing fails.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func Sfprint ¶ added in v0.3.9
func Sfprint(form FormatConfig, a ...interface{}) ([][][][]string, error)
Sfprint prints a formatted string.
Parameters:
- form: The formatter to use.
- a: The elements to print.
Returns:
- [][][][]string: The pages of the formatted strings.
- error: An error if the printing fails.
func Sfprintf ¶ added in v0.3.9
func Sfprintf(form FormatConfig, format string, a ...interface{}) ([][][][]string, error)
Sfprintf prints a formatted string.
Parameters:
- form: The formatter to use.
- format: The format string.
- a: The elements to print.
Returns:
- [][][][]string: The pages of the formatted strings.
- error: An error if the printing fails.
func Sfprintln ¶ added in v0.3.9
func Sfprintln(form FormatConfig, a ...interface{}) ([][][][]string, error)
Sfprintln prints a formatted string with a newline.
Parameters:
- form: The formatter to use.
- a: The elements to print.
Returns:
- [][][][]string: The pages of the formatted strings.
- error: An error if the printing fails.
func Sprint ¶ added in v0.3.9
func Sprint(form FormatConfig, strs ...string) ([][][][]string, error)
Sprint prints strings.
Parameters:
- form: The formatter to use.
- strs: The strings to print.
Returns:
- [][][][]string: The pages of the formatted strings.
- error: An error if the printing fails.
func SprintFString ¶ added in v0.3.9
func SprintFString[T FStringer](form FormatConfig, elem T) ([][][][]string, error)
SprintFString prints a formatted string.
Parameters:
- form: The formatter to use.
- elem: The element to print.
Returns:
- [][][][]string: The pages of the formatted string.
func Sprintj ¶ added in v0.3.9
func Sprintj(form FormatConfig, sep string, strs ...string) ([][][][]string, error)
Sprintj prints a joined string.
Parameters:
- form: The formatter to use.
- sep: The separator to use.
- strs: The strings to join.
Returns:
- [][][][]string: The pages of the formatted strings.
- error: An error if the printing fails.
func Sprintjln ¶ added in v0.3.9
func Sprintjln(form FormatConfig, sep string, lines ...string) ([][][][]string, error)
Sprintjln prints a joined string with a newline.
Parameters:
- form: The formatter to use.
- sep: The separator to use.
- lines: The lines to join.
Returns:
- [][][][]string: The pages of the formatted strings.
- error: An error if the printing fails.
func Sprintln ¶ added in v0.3.9
func Sprintln(form FormatConfig, lines ...string) ([][][][]string, error)
Sprintln prints a string with a newline.
Parameters:
- form: The formatter to use.
- lines: The lines to print.
Returns:
- [][][][]string: The pages of the formatted strings.
- error: An error if the printing fails.
Types ¶
type ConfigOption ¶ added in v0.3.6
type ConfigOption func(FormatConfig)
ConfigOption is a type that represents a configuration option for a formatter.
func WithDecreasedIndent ¶ added in v0.3.6
func WithDecreasedIndent() ConfigOption
WithDecreasedIndent is a function that decreases the indentation level of the formatter by one.
Returns:
- ConfigOption: The configuration option.
Behaviors:
- If the indentation level is already 0, it is not decreased.
func WithIncreasedIndent ¶ added in v0.3.6
func WithIncreasedIndent() ConfigOption
WithIncreasedIndent is a function that increases the indentation level of the formatter by one.
Returns:
- ConfigOption: The configuration option.
func WithModifiedIndent ¶ added in v0.3.6
func WithModifiedIndent(by int) ConfigOption
WithModifiedIndent is a function that modifies the indentation level of the formatter by a specified amount relative to the current indentation level.
Parameters:
- by: The amount by which to modify the indentation level.
Returns:
- ConfigOption: The configuration option.
Behaviors:
- Negative values will decrease the indentation level while positive values will increase it. If the value is 0, then nothing is done and when the indentation level is 0, it is not decreased.
type Configer ¶ added in v0.3.6
Configer is an interface that defines the behavior of a type that can be copied.
type DelimiterConfig ¶
type DelimiterConfig struct {
// contains filtered or unexported fields
}
DelimiterConfig is a type that represents the configuration for delimiters.
func NewDelimiterConfig ¶
func NewDelimiterConfig(str string, isInline, left bool) *DelimiterConfig
NewDelimiterConfig is a function that creates a new delimiter configuration.
Parameters:
- value: The string that is used as a delimiter.
- inline: Whether the delimiter should be inline.
Returns:
- *DelimiterConfig: A pointer to the new delimiter configuration.
Default values:
- ==DelimiterConfig==
- Value: ""
- Inline: true
func (*DelimiterConfig) Copy ¶ added in v0.3.6
func (c *DelimiterConfig) Copy() uc.Copier
Copy is a method of uc.Copier interface.
Returns:
- uc.Copier: A copy of the delimiter configuration.
type FStringFunc ¶ added in v0.3.6
FStringFunc is a function that generates a formatted string representation of an object.
Parameters:
- trav: The traversor to use for printing.
- elem: The element to print.
Returns:
- error: An error if there was a problem generating the string.
type FStringer ¶
type FStringer interface { // FString returns a string representation of the object. // // Parameters: // - trav: The traversor to use for printing. // // Returns: // - error: An error if there was a problem generating the string. FString(trav *Traversor) error }
FStringer is an interface that defines the behavior of a type that can be converted to a string representation.
type FilePrinter ¶ added in v0.3.9
type FilePrinter struct {
// contains filtered or unexported fields
}
FilePrinter is a type that represents a formatted string.
func NewFilePrinter ¶ added in v0.3.9
func NewFilePrinter(out io.Writer, form FormatConfig) *FilePrinter
NewFilePrinter creates a new FilePrinter.
Parameters:
- out: The writer to use.
- form: The formatter to use.
Returns:
- *FilePrinter: The new FilePrinter.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func NewFilePrinterFromConfig ¶ added in v0.3.9
func NewFilePrinterFromConfig(out io.Writer, opts ...Configer) *FilePrinter
NewFilePrinterFromConfig creates a new FilePrinter from a configuration.
Parameters:
- out: The writer to use.
- opts: The configuration to use.
Returns:
- *FilePrinter: The new FilePrinter.
Behaviors:
- If the writer is nil, the function uses os.Stdout.
func (*FilePrinter) Clean ¶ added in v0.3.9
func (p *FilePrinter) Clean()
Cleanup implements the Cleaner interface.
func (*FilePrinter) TraversorOf ¶ added in v0.3.9
func (p *FilePrinter) TraversorOf() *Traversor
TraversorOf implements the Printer interface.
func (*FilePrinter) Update ¶ added in v0.3.9
func (p *FilePrinter) Update()
Update updates the FilePrinter by writing the buffer to the file.
type FormatConfig ¶ added in v0.3.6
type FormatConfig [4]Configer
FormatConfig is a type that represents a configuration for formatting. [Indentation] [Left Delimiter] [Right Delimiter] [Separator]
var ( // ArrayLikeFormat is the default options for an array-like object. // [1, 2, 3] ArrayLikeFormat FormatConfig = NewFormatter( NewDelimiterConfig("[", false, true), NewDelimiterConfig("]", false, false), NewSeparator(DefaultSeparator, false), ) )
var ( // DefaultFormatter is the default formatter. // // ==IndentConfig== // - DefaultIndentationConfig // // ==SeparatorConfig== // - DefaultSeparatorConfig // // ==DelimiterConfig (Left and Right)== // - Nil (no delimiters are used by default) DefaultFormatter FormatConfig = NewFormatter( DefaultIndentationConfig, DefaultSeparatorConfig, ) )
func MergeForm ¶ added in v0.3.6
func MergeForm(form1, form2 FormatConfig) FormatConfig
MergeForm is a function that merges the given formatter with the current one; prioritizing the values of the first formatter.
Parameters:
- form1: The first formatter.
- form2: The second formatter.
Returns:
- FormatConfig: A pointer to the new formatter.
func NewFormatter ¶ added in v0.3.6
func NewFormatter(options ...Configer) (form FormatConfig)
NewFormatter is a function that creates a new formatter with the given configuration.
Parameters:
- options: The configuration for the formatter.
Returns:
- form: A pointer to the new formatter.
Behaviors:
- The function panics if an invalid configuration type is given. (i.e., not IndentConfig, DelimiterConfig, or SeparatorConfig)
type IndentConfig ¶
type IndentConfig struct {
// contains filtered or unexported fields
}
IndentConfig is a type that represents the configuration for indentation.
func NewIndentConfig ¶
func NewIndentConfig(str string, initialLevel int) *IndentConfig
NewIndentConfig is a function that creates a new indentation configuration.
Parameters:
- indentation: The string that is used for indentation.
- initialLevel: The initial indentation level.
Returns:
- *IndentConfig: A pointer to the new indentation configuration.
Default values:
==IndentConfig== - Indentation: DefaultIndentation - InitialLevel: 0
Behaviors:
- If initialLevel is negative, it is set to 0.
func (*IndentConfig) Copy ¶ added in v0.3.6
func (c *IndentConfig) Copy() uc.Copier
Copy is a method of uc.Copier interface.
Returns:
- uc.Copier: A copy of the indentation configuration.
func (*IndentConfig) GetIndentStr ¶ added in v0.3.6
func (c *IndentConfig) GetIndentStr() string
GetIndentStr is a method that returns the indentation string.
Returns:
- string: The indentation string.
func (*IndentConfig) GetIndentation ¶ added in v0.3.6
func (c *IndentConfig) GetIndentation() string
GetIndentation is a method that returns the applied indentation.
Returns:
- string: The applied indentation.
type Printer ¶ added in v0.3.6
type Printer interface { // TraversorOf returns a traversor for the printer. // // Returns: // - *Traversor: The traversor for the printer. TraversorOf() *Traversor uc.Cleaner }
Printer is an interface that defines the behavior of a printer.
type SeparatorConfig ¶
type SeparatorConfig struct {
// contains filtered or unexported fields
}
SeparatorConfig is a type that represents the configuration for separators.
func NewSeparator ¶
func NewSeparator(sep string, includeFinal bool) *SeparatorConfig
NewSeparator is a function that creates a new separator configuration.
Parameters:
- separator: The string that is used as a separator.
- hasFinalSeparator: Whether the last element should have a separator.
Returns:
- *SeparatorConfig: A pointer to the new separator configuration.
Default values:
==SeparatorConfig== - Separator: DefaultSeparator - HasFinalSeparator: false
func (*SeparatorConfig) Copy ¶ added in v0.3.6
func (c *SeparatorConfig) Copy() uc.Copier
Copy is a method of uc.Copier interface.
Returns:
- uc.Copier: A copy of the separator configuration.
type SimplePrinter ¶ added in v0.3.5
type SimplePrinter[T comparable] struct { // contains filtered or unexported fields }
SimplePrinter is a simple printer that prints a value with a name.
func NewSimplePrinter ¶ added in v0.3.5
func NewSimplePrinter[T comparable](name string, value T, fn func(T) (string, error)) *SimplePrinter[T]
NewSimplePrinter creates a new SimplePrinter with the provided name and value.
Parameters:
- name: The name of the value.
- value: The value to print.
- fn: The function to use to convert the value to a string.
Returns:
- *SimplePrinter: The new SimplePrinter.
Behaviors:
- If the function is nil, the function uses uc.StringOf to convert the value to a string.
func (*SimplePrinter[T]) FString ¶ added in v0.3.5
func (sp *SimplePrinter[T]) FString(trav *Traversor) error
FString generates a formatted string representation of a SimplePrinter.
Format:
<name>: <value>
Parameters:
- trav: The traversor to use for printing.
Returns:
- error: An error if the printing fails.
type StdPrinter ¶ added in v0.3.9
type StdPrinter struct {
// contains filtered or unexported fields
}
StdPrinter is a type that represents a formatted string.
func NewStdPrinter ¶ added in v0.3.9
func NewStdPrinter(form FormatConfig) *StdPrinter
NewStdPrinter creates a new StdPrinter.
Parameters:
- form: The formatter to use.
Returns:
- *StdPrinter: The new StdPrinter.
func NewStdPrinterFromConfig ¶ added in v0.3.9
func NewStdPrinterFromConfig(opts ...Configer) *StdPrinter
NewStdPrinterFromConfig creates a new StdPrinter from a configuration.
Parameters:
- opts: The configuration to use.
Returns:
- *StdPrinter: The new StdPrinter.
Behaviors:
- If the configuration is nil, the function uses the default configuration.
- Panics if an invalid configuration type is given (i.e., not IndentConfig, DelimiterConfig, or SeparatorConfig).
func (*StdPrinter) Clean ¶ added in v0.3.9
func (p *StdPrinter) Clean()
Cleanup implements the Cleaner interface.
func (*StdPrinter) GetPages ¶ added in v0.3.9
func (p *StdPrinter) GetPages() [][][][]string
GetPages returns the pages of the StdPrinter.
Returns:
- [][][][]string: The pages of the StdPrinter.
func (*StdPrinter) TraversorOf ¶ added in v0.3.9
func (p *StdPrinter) TraversorOf() *Traversor
TraversorOf implements the Printer interface.
type Traversor ¶ added in v0.2.41
type Traversor struct {
// contains filtered or unexported fields
}
Traversor is a type that represents a traversor for a formatted string.
func (*Traversor) AcceptLine ¶ added in v0.3.6
func (trav *Traversor) AcceptLine()
AcceptLine is a function that accepts the current line of the traversor.
Behaviors:
- This also accepts the current word if any.
func (*Traversor) AcceptWord ¶ added in v0.3.6
func (trav *Traversor) AcceptWord()
AcceptWord is a function that, if there is any in-progress word, then said word is added to the source.
func (*Traversor) AddJoinedLine ¶ added in v0.3.5
AddJoinedLine adds a joined line to the traversor. This is a more efficient way to do the same as AddLine(strings.Join(fields, sep)).
Parameters:
- sep: The separator to use.
- fields: The fields to join.
Returns:
- error: An error of type *Errors.ErrInvalidRuneAt if there is an invalid rune in the line.
Behaviors:
- If fields is empty, then nothing is done.
func (*Traversor) AddLine ¶ added in v0.3.5
AddLine adds a line to the traversor. If there is any in-progress line, then the line is appended to the line before accepting it. Otherwise, a new line with the line is added to the source.
Parameters:
- line: The line to add.
Returns:
- error: An error of type *Errors.ErrAt if there is an error adding the line.
Behaviors:
- If line is empty, then an empty line is added to the source.
func (*Traversor) AddLines ¶ added in v0.2.41
AddLines adds multiple lines to the traversor in a more efficient way than adding each line individually.
Parameters:
- lines: The lines to add.
Returns:
- error: An error of type *Errors.ErrAt if there is an error adding a line.
Behaviors:
- If there are no lines, then nothing is done.
func (*Traversor) AppendJoinedString ¶ added in v0.3.5
AppendJoinedString appends a joined string to the half-line of the traversor.
Parameters:
- sep: The separator to use.
- fields: The fields to join.
Returns:
- error: An error of type *Errors.ErrInvalidRuneAt if there is an invalid rune in the string.
Behaviors:
- This is equivalent to calling AppendString(strings.Join(fields, sep)).
func (*Traversor) AppendRune ¶ added in v0.3.5
AppendRune appends a rune to the half-line of the traversor.
Parameters:
- r: The rune to append.
Returns:
- error: An error if the rune could not be appended.
Errors:
- *Errors.ErrInvalidRune: If the rune is invalid.
Behaviors:
- If the half-line is nil, then a new half-line is created.
func (*Traversor) AppendString ¶ added in v0.2.41
AppendString appends a string to the half-line of the traversor.
Parameters:
- str: The string to append.
Returns:
- error: An error of type *Errors.ErrInvalidRuneAt if there is an invalid rune in the string.
Behaviors:
- IF str is empty: nothing is done.
func (*Traversor) AppendStrings ¶ added in v0.2.41
AppendStrings appends multiple strings to the half-line of the traversor.
Parameters:
- strs: The strings to append.
Returns:
- error: An error of type *Errors.ErrAt if there is an error appending a string.
Behaviors:
- This is equivalent to calling AppendString for each string in strs but more efficient.
func (*Traversor) Clean ¶ added in v0.3.9
func (trav *Traversor) Clean()
Cleanup implements the Cleaner interface.
func (*Traversor) EmptyLine ¶ added in v0.2.41
func (trav *Traversor) EmptyLine()
EmptyLine adds an empty line to the traversor. This is a more efficient way to do the same as AddLine("") or AddLines([]string{""}).
Behaviors:
- If the half-line is not empty, then the half-line is added to the source (half-line is reset) and an empty line is added to the source.
func (*Traversor) GetConfig ¶ added in v0.3.6
func (trav *Traversor) GetConfig(options ...ConfigOption) FormatConfig
GetConfig is a method that returns a copy of the configuration of the traversor.
Parameters:
- options: The options to apply to the configuration.
Returns:
- FormatConfig: A copy of the configuration of the traversor.
func (*Traversor) Print ¶ added in v0.3.6
Print is a function that writes to the traversor using the fmt.Fprint function.
Parameters:
- a: The arguments to write.
func (*Traversor) Printf ¶ added in v0.3.6
Printf is a function that writes to the traversor using the fmt.Fprintf function.
Parameters:
- format: The format string.
- a: The arguments to write.