Documentation ¶
Index ¶
- Constants
- type Builder
- type DelimiterConfig
- type FString
- type FStringer
- type Formatter
- type IndentConfig
- type SeparatorConfig
- type Traversor
- func (trav *Traversor) AddLines(lines ...string)
- func (trav *Traversor) AppendString(str string)
- func (trav *Traversor) AppendStrings(separator string, strs ...string)
- func (trav *Traversor) Apply()
- func (trav *Traversor) EmptyLine()
- func (trav *Traversor) GetIndent() string
- func (trav *Traversor) IncreaseIndent(by int) *Traversor
Constants ¶
const ( // DefaultIndentation is the default indentation string. DefaultIndentation string = " " // DefaultSeparator is the default separator string. DefaultSeparator string = ", " )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a type that represents a builder for creating formatted strings.
func (*Builder) Build ¶
Build is a method of the Builder type that creates a formatter with the configuration of the builder.
Returns:
- *Formatter: A pointer to the newly created formatter.
Information:
- Options that are not specified will be set to their default values:
- ==IndentConfig==
- Nil (no indentation is used by default)
- ==SeparatorConfig==
- Separator: DefaultSeparator
- HasFinalSeparator: false
- ==DelimiterConfig (Left and Right)==
- Nil (no delimiters are used by default)
func (*Builder) SetDelimiterLeft ¶ added in v0.2.37
func (b *Builder) SetDelimiterLeft(delimiter *DelimiterConfig)
SetDelimiterLeft is a function that sets the left delimiter configuration of the builder.
Parameters:
- delimiter: The left delimiter configuration.
func (*Builder) SetDelimiterRight ¶ added in v0.2.37
func (b *Builder) SetDelimiterRight(delimiter *DelimiterConfig)
SetDelimiterRight is a function that sets the right delimiter configuration of the builder.
Parameters:
- delimiter: The right delimiter configuration.
func (*Builder) SetIndentation ¶ added in v0.2.37
func (b *Builder) SetIndentation(config *IndentConfig)
SetIndentation is a function that sets the indentation configuration of the builder.
Ignore this function if you don't want to indent at all. If you want the rules of vertical indentation to be applied, without any indentation, use "" as the indentation string.
Parameters:
- config: The indentation configuration.
func (*Builder) SetSeparator ¶ added in v0.2.37
func (b *Builder) SetSeparator(config *SeparatorConfig)
SetSeparator is a function that sets the separator configuration of the builder.
Parameters:
- config: The separator configuration.
type DelimiterConfig ¶
type DelimiterConfig struct { // Value is the string that is used as a delimiter. Value string // Inline specifies whether the delimiter should be inline. Inline bool }
DelimiterConfig is a type that represents the configuration for delimiters.
func NewDelimiterConfig ¶
func NewDelimiterConfig(value string, inline 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) String ¶
func (c *DelimiterConfig) String() string
String is a method of fmt.Stringer interface.
Returns:
- string: A string representation of the delimiter configuration.
type FString ¶
type FString struct {
// contains filtered or unexported fields
}
FString is a type that represents a formatted string.
func NewFString ¶ added in v0.2.41
func NewFString() *FString
NewFString creates a new formatted string.
Returns:
- *FString: A pointer to the newly created formatted string.
func (*FString) GetLines ¶ added in v0.2.43
func (fs *FString) GetLines() []*cb.MultiLineText
func (*FString) String ¶ added in v0.2.41
String returns the string representation of the traversor.
Returns:
- string: The string representation of the traversor.
func (*FString) Traversor ¶ added in v0.2.41
func (fs *FString) Traversor(indent *IndentConfig) *Traversor
Traversor creates a traversor for the formatted string.
Parameters:
- indent: The indentation configuration of the traversor.
Returns:
- *Traversor: A pointer to the newly created traversor.
Behaviors:
- If the indentation configuration is nil, the default indentation configuration is used.
type FStringer ¶
type FStringer interface { // FString returns a string representation of the object. // // Parameters: // - int: The current indentation level. // // Returns: // - []string: A slice of strings that represent the object. FString(trav *Traversor) []string }
FStringer is an interface that defines the behavior of a type that can be converted to a string representation.
type Formatter ¶ added in v0.2.37
type Formatter struct {
// contains filtered or unexported fields
}
Formatter is a type that represents a builder for creating formatted strings.
var ( // ArrayDefault is the default options for an array. // [1, 2, 3] ArrayDefault *Formatter = func() *Formatter { var builder Builder builder.SetDelimiterLeft(NewDelimiterConfig("[", false)) builder.SetDelimiterRight(NewDelimiterConfig("]", false)) builder.SetSeparator(NewSeparator(DefaultSeparator, false)) return builder.Build() }() )
func (*Formatter) Apply ¶ added in v0.2.37
Apply is a method of the Formatter type that creates a formatted string from the given values.
Parameters:
- values: The values to format.
Returns:
- []string: The formatted string.
func (*Formatter) ApplyString ¶ added in v0.2.37
ApplyString is a method of the Formatter type that works like Apply but returns a single string.
Parameters:
- values: The values to format.
Returns:
- string: The formatted string.
type IndentConfig ¶
type IndentConfig struct { // IgnoreFirst specifies whether the first line should be indented. IgnoreFirst bool // Indentation is the string that is used for indentation. Indentation string // InitialLevel is the initial indentation level. InitialLevel int }
IndentConfig is a type that represents the configuration for indentation.
func NewIndentConfig ¶
func NewIndentConfig(indentation string, initialLevel int, ignoreFirst bool) *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.
- allowVertical: Whether vertical indentation is allowed.
- ignoreFirst: Whether the first line should be indented.
Returns:
- *IndentConfig: A pointer to the new indentation configuration.
Default values:
==IndentConfig== - Indentation: DefaultIndentation - InitialLevel: 0 - IgnoreFirst: true
func (*IndentConfig) Increase ¶ added in v0.2.41
func (config *IndentConfig) Increase(by int) *IndentConfig
Increase is a method that increases the indentation level of the configuration.
Parameters:
- by: The amount by which to increase the indentation level.
Returns:
- *IndentConfig: A pointer to the new indentation configuration.
Behaviors:
- If by is negative, it is converted to a positive value.
func (*IndentConfig) String ¶
func (c *IndentConfig) String() string
String is a method of fmt.Stringer interface.
Returns:
- string: A string representation of the indentation configuration.
type SeparatorConfig ¶
type SeparatorConfig struct { // Separator is the string that is used as a separator. Separator string // HasFinalSeparator specifies whether the last element should have a separator. HasFinalSeparator bool }
SeparatorConfig is a type that represents the configuration for separators.
func NewSeparator ¶
func NewSeparator(separator string, hasFinalSeparator 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) String ¶
func (c *SeparatorConfig) String() string
String is a method of fmt.Stringer interface.
Returns:
- string: A string representation of the separator configuration.
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) AddLines ¶ added in v0.2.41
AddLines adds lines to the traversor.
Parameters:
- lines: The lines to add.
Behaviors:
- If the half line is not empty, then the first line is added to the half line, the new half line is added to the buffer (half line is reset), and the rest of the lines are added to the buffer.
- If the half line is empty, then the lines are added to the buffer. However, if the lines are empty, then an empty line is added to the buffer.
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.
func (*Traversor) AppendStrings ¶ added in v0.2.41
AppendStrings appends strings to the half line of the traversor with a separator between each string.
Parameters:
- separator: The separator between each string.
- strs: The strings to append.
Behaviors:
- If there are no strings, then nothing is appended.
func (*Traversor) Apply ¶ added in v0.2.41
func (trav *Traversor) Apply()
Apply adds the buffer to the lines of the traversor.
Behaviors:
- If the half line is not empty, then the half line is added to the buffer (half line is reset) and the buffer is added to the lines of the traversor.
- Each line in the buffer is indented by the indentation configuration.
func (*Traversor) EmptyLine ¶ added in v0.2.41
func (trav *Traversor) EmptyLine()
EmptyLine adds an empty line to the traversor.
Behaviors:
- If the half line is not empty, then the half line is added to the buffer (half line is reset) and an empty line is added to the buffer.
func (*Traversor) GetIndent ¶ added in v0.2.41
GetIndent returns the indentation string of the traversor.
Returns:
- string: The indentation string of the traversor.
func (*Traversor) IncreaseIndent ¶ added in v0.2.41
IncreaseIndent increases the indentation level of the traversor.
Parameters:
- by: The amount by which to increase the indentation level.
Returns:
- *Traversor: A pointer to the new traversor.
Behaviors:
- If by is negative, it is converted to a positive value.
- If the traversor does not have an indentation configuration, the traversor is returned as is.