xstrings

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildErrorInfo

func BuildErrorInfo(args ...string) string

BuildErrorInfo aggregates up to five positional diagnostic variables into a unified, scannable metadata string pattern: Field -> A | Given -> B | Expected -> C | Extracted -> D | Reason -> E.

Arguments must adhere strictly to the following structural positions:

  • index 0: Field (The identifier or key path of the parameter being evaluated)
  • index 1: Given (The raw input value triggering the exception)
  • index 2: Expected (The targeted success criteria or standard contract)
  • index 3: Extracted (The isolated payload snapshot or transformed segment, optional)
  • index 4: Reason (The underlying logical breakdown explanation, optional)

Trailing unprovided positions or empty strings are safely intercepted and pruned from the final buffer.

func ContainsAny

func ContainsAny(target string, substrings ...string) bool

ContainsAny evaluates whether a given target string contains at least one of the provided substrings. It iterates sequentially over the variadic collection and terminates immediately with a true outcome upon detecting the first matching subset, minimizing unnecessary structural scanning.

func ConvertAllToStrings

func ConvertAllToStrings(args ...any) []string

ConvertAllToStrings transforms a variadic sequence of arguments of any underlying type into a structured string slice. It preserves the integrity and identity of iterable collections (slices/arrays) by formatting them as single unified visual entries matching their type signature (e.g., []Type{...}), preventing structural data leakage into independent index segments.

func FormatPairValuesToOutput

func FormatPairValuesToOutput(
	openFirst string,
	closeFirst string,
	unionPair string,
	sepPair string,
	openSecond string,
	closeSecond string,
	values []string,
	sb *strings.Builder,
) *strings.Builder

FormatPairValuesToOutput processes a collection of strings in sequential pairs, formatting and merging them into a structural visual engine. It encapsulates each part of the pair inside custom open/close boundaries, unifies the relationship via unionPair, and joins independent pairs together using the specified sepPair delimiter.

Operational Edge Case:

  • If the incoming slice contains an odd number of items (or a single element), the trailing orphan element is intercepted and treated as an individual segment, preventing layout breaks or out-of-bounds panics.

func FormatPairsArrow

func FormatPairsArrow(pairs []string, sb *strings.Builder) *strings.Builder

FormatPairsArrow formats a slice of sequential key-value string pairs into a standardized mapping string representation, writing the structured output directly to a strings.Builder. If the provided strings.Builder pointer is nil, a new instance will be automatically initialized and returned. It applies a consistent layout with single quotes around keys, an arrow separator, unquoted values, and pairs joined by pipes (e.g., 'Key' => Value | 'Key2' => Value2).

func FormatPairsColon

func FormatPairsColon(pairs []string, sb *strings.Builder) *strings.Builder

FormatPairsColon formats a slice of sequential key-value string pairs into a standardized, single-quote encapsulated metadata string, writing the structured output directly to a strings.Builder. If the provided strings.Builder pointer is nil, a new instance will be automatically initialized and returned. It applies a consistent layout with single quotes around keys and values, separated by colons, and joined by pipes (e.g., 'Key': 'Value' | 'Key2': 'Value2').

func FormatSingleValuesToOutput

func FormatSingleValuesToOutput(
	open string,
	close string,
	sep string,
	values []string,
	sb *strings.Builder,
) *strings.Builder

FormatSingleValuesToOutput aggregates a slice of strings into a standardized visual output sequence, wrapping each individual element within the specified open/close tokens and separating them via a delimiter. If the provided strings.Builder pointer is nil, the factory safely initializes a new instance before executing high-performance buffer writes. It returns the active builder to support fluent API chaining.

func IsBlacklisted

func IsBlacklisted(val any, blacklist []any) bool

IsBlacklisted evaluates whether a given target value matches any criteria defined within a structural exclusion slice. It safeguards complex types (such as structs, maps, and slices) from illegal runtime comparison panics by leveraging deep structural scanning, while normalization routines intercept cross-boundary integer representations.

func ParseStructToString

func ParseStructToString(item any) string

ParseStructToString converts any struct instance into a structured visual sequence for technical logging. It formats the output matching the pattern: <StructName>{"key":"value"}. If the struct contains no public (exported) fields, it falls back immediately to <StructName>{}. It automatically dereferences pointer arguments to extract and evaluate the underlying struct data structure.

func StringBuilder

func StringBuilder(sb *strings.Builder, strs ...string)

StringBuilder flushes a variadic sequence of raw string parameters directly into the provided strings.Builder buffer instance. It centralizes and encapsulates linear string concatenation routines, reducing human friction and protecting low-level memory writes from trailing allocations.

Types

This section is empty.

Jump to

Keyboard shortcuts

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