FString

package
v0.2.40 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 1 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(form *Formatter, values []string) string

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

func (b *Builder) Build() *Formatter

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

func (form *Formatter) Apply(values []string) []string

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

func (form *Formatter) ApplyString(values []string) string

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

Jump to

Keyboard shortcuts

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