replacer

package
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

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

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

Index

Constants

View Source
const DefaultKeyword = "$$"

DefaultKeyword defines the default keyword.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReplaceFunc

type ReplaceFunc func(key, value 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.
	Replace(string, map[string]string) string // Replaces substrings based on provided key-value pairs.
}

Replacer interface defines methods for setting keywords and performing replacements.

func New

func New(ss ...Setting) Replacer

New returns a new Replacer instance with default settings.

type Setting added in v0.0.38

type Setting = settings.Setting[replace]

Setting is the setting of replacer.

func WithHooks

func WithHooks(hooks map[string]ReplaceFunc) Setting

WithHooks returns a new Replacer instance with the specified hooks.

func WithKeyword added in v0.0.38

func WithKeyword(keyword string) Setting

WithKeyword returns a new Replacer instance with the specified keyword.

Jump to

Keyboard shortcuts

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