replacer

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package replacer provides a string replacement mechanism with custom replace functions and delimiters.

Index

Constants

View Source
const DefaultDelimiter = "$$"

DefaultDelimiter defines the default delimiter.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReplaceFunc

type ReplaceFunc func(string) string

ReplaceFunc is a function type that accepts a string and returns a replaced string.

type Replacer

type Replacer interface {
	AddHook(string, ReplaceFunc)              // Adds a new replace hook.
	SetDelimiter(string)                      // Sets the delimiter.
	Replace(string, map[string]string) string // Replaces substrings based on provided key-value pairs.
}

Replacer interface defines methods for setting delimiters and performing replacements.

func New

func New() Replacer

New returns a new Replacer instance with default settings.

func WithDelimiter added in v0.0.33

func WithDelimiter(delimiter string) Replacer

WithDelimiter returns a new Replacer instance with the specified delimiter.

func WithHooks

func WithHooks(hooks map[string]ReplaceFunc) Replacer

WithHooks returns a new Replacer instance with the specified hooks.

func WithHooksAndDelimiter added in v0.0.33

func WithHooksAndDelimiter(hooks map[string]ReplaceFunc, delimiter string) Replacer

WithHooksAndDelimiter returns a new Replacer instance with the specified hooks and delimiter.

Jump to

Keyboard shortcuts

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