FString

package
v0.2.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 2 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DefaultIndentation is the default indentation string.
	DefaultIndentation string = "   "

	// DefaultSeparator is the default separator string.
	DefaultSeparator string = ", "
)

Variables

This section is empty.

Functions

func FString

func FString(obj FStringer) string

FString is a function that returns a string representation of an object that implements the FStringer interface.

It joins the strings returned by the FString method of the object using a newline character with no indentation at the beginning.

Parameters:

  • obj: The object that implements the FStringer interface.

Returns:

  • string: A string representation of the object.

Types

type BuildOption

type BuildOption func(*Builder)

BuildOption is a type that represents a function that modifies the builder.

Parameters:

  • *Builder: The builder to modify.

func WithDelimiterLeft

func WithDelimiterLeft(delimiter *DelimiterConfig) BuildOption

WithDelimiterLeft is a function that sets the left delimiter configuration of the builder.

Parameters:

  • delimiter: The left delimiter configuration.

Returns:

  • BuildOption: A function that modifies the builder.

func WithDelimiterRight

func WithDelimiterRight(delimiter *DelimiterConfig) BuildOption

WithDelimiterRight is a function that sets the right delimiter configuration of the builder.

Parameters:

  • delimiter: The right delimiter configuration.

Returns:

  • BuildOption: A function that modifies the builder.

func WithIndentation

func WithIndentation(config *IndentConfig) BuildOption

WithIndentation 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.

Returns:

  • BuildOption: A function that modifies the builder.

func WithSeparator

func WithSeparator(config *SeparatorConfig) BuildOption

WithSeparator is a function that sets the separator configuration of the builder.

Parameters:

  • config: The separator configuration.

Returns:

  • BuildOption: A function that modifies the builder.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is a type that represents a builder for creating formatted strings.

func NewBuilder

func NewBuilder(options ...BuildOption) *Builder

NewBuilder is a function that creates a new builder with the given options.

Parameters:

  • options: The options to set on the builder.

Returns:

  • *Builder: A pointer to the new builder.

Information:

  • Options that are not specified will be set to their default values:
  • ==IndentConfig==
  • Indentation: DefaultIndentation
  • InitialLevel: 0
  • AllowVertical: false
  • ==SeparatorConfig==
  • Separator: DefaultSeparator
  • HasFinalSeparator: false
  • ==DelimiterConfig==
  • Value: ""
  • Inline: true

func (*Builder) Build

func (b *Builder) Build(values []string) string

Build is a method of the Builder type that creates a formatted string from the given values.

Parameters:

  • values: The values to format.

Returns:

  • string: The formatted string.

func (*Builder) Format

func (b *Builder) Format(values []string) []string

Format is a method of the Builder type that creates a formatted string from the given values.

Parameters:

  • values: The values to format.

Returns:

  • []string: The formatted string.

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.

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 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(int) []string
}

FStringer is an interface that defines the behavior of a type that can be converted to a string representation.

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

	// AllowVertical specifies whether vertical indentation is allowed.
	AllowVertical bool
}

IndentConfig is a type that represents the configuration for indentation.

func NewIndentConfig

func NewIndentConfig(indentation string, initialLevel int, allowVertical bool, 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.

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 Options

type Options []BuildOption

Options is a type that represents the options that can be passed to the builder.

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL