Documentation ¶
Overview ¶
Package censoring provides utilities for filtering strings.
Package censoring provides utilities for filtering strings.
Index ¶
Constants ¶
const (
DefaultCensorLabel string = "[***]"
)
DefaultCensorLabel is a constant that defines the default label used to replace unacceptable strings when they are filtered. Its default value is "[***]".
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 provides a fluent interface for constructing a censoring operation.
func (*Builder) Apply ¶
Apply is a method of the Builder type that applies a given function to the non-censored string representation of the Builder. However, because this allows you to perform operations on the non-censored string, regardless of the current censor level, it is important to use it with caution and only when necessary.
Parameters:
- f: The function to be applied to the non-censored string.
func (*Builder) IsCensored ¶
func (b *Builder) IsCensored() CensorValue
IsCensored is a method of the Builder type that returns a CensorValue indicating whether the Builder is censored.
Returns:
- CensorValue: Censored if the Builder is censored, and NotCensored otherwise.
type BuilderOption ¶
type BuilderOption func(*Builder)
BuilderOption is a function type that modifies the properties of a Builder.
func WithFilters ¶
func WithFilters(filters ...slext.PredicateFilter[string]) BuilderOption
WithFilters returns a BuilderOption that sets the filters of a Builder.
Parameters:
- filters: The filters to be set.
Returns:
- BuilderOption: A function that modifies the filters of a Builder.
func WithLabel ¶
func WithLabel(label string) BuilderOption
WithLabel returns a BuilderOption that sets the label of a Builder. Empty strings will be ignored and the label will not be set.
Parameters:
- label: The label to be set.
Returns:
- BuilderOption: A function that modifies the label of a Builder.
func WithMode ¶
func WithMode(mode CensorValue) BuilderOption
WithMode returns a BuilderOption that sets the censorship mode of a Builder.
Parameters:
- mode: The mode to be set.
Returns:
- BuilderOption: A function that modifies the censorship mode of a Builder.
func WithValues ¶
func WithValues(values ...any) BuilderOption
WithValues returns a BuilderOption that sets the values of a Builder.
Parameters:
- values: The values to be set.
Returns:
- BuilderOption: A function that modifies the values of a Builder.
Important:
- Values can be of any type and are converted to strings before being set. If a value is a Builder, its output string is used as the value.
type CensorValue ¶
type CensorValue bool
CensorValue is a type that represents whether a string has been censored or not. It is used in conjunction with the FilterFunc type to determine the censoring status of a string.
const ( // Censored represents a string that has been censored Censored CensorValue = true // NotCensored represents a string that has not been censored NotCensored CensorValue = false )
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a type that encapsulates the context for a censoring operation.
func NewContext ¶
func NewContext() *Context
NewContext creates a new Context with default values. The default censorLabel is DefaultCensorLabel and the context is censored.
Returns:
- Context: A new Context with default values.
func (*Context) Make ¶
func (ctx *Context) Make(options ...BuilderOption) *Builder
Make is a method of Context that creates a new Builder with the given BuilderOptions.
Parameters:
- options: The BuilderOptions to be applied to the Builder.
Returns:
- *Builder: The new Builder with the given options.
Important:
- The BuilderOptions are applied in the order they are provided. By default, the Builder's label is set to DefaultCensorLabel and separator is set to a space character.
func (*Context) WithLabel ¶
WithLabel sets the censorLabel of the Context to the given label. Empty strings will be replaced with DefaultCensorLabel.
Parameters:
- label: The label to be set.
Returns:
- *Context: A pointer to the Context itself.
func (*Context) WithMode ¶
func (ctx *Context) WithMode(mode CensorValue) *Context
WithMode sets the notCensored value of the Context to the given mode.
Parameters:
- mode: The mode to be set.
Returns:
- *Context: A pointer to the Context itself.