parsing

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindData

func FindData(fileContent string, pattern Pattern) (start, end int, result string)

func FindDataWithAlternative

func FindDataWithAlternative(fileContent string, pattern1, pattern2 Pattern) (start, end int, result string)

func FindDataWithCode

func FindDataWithCode(fileContent, startStr, endStr string) (start, end int, result, codeBlock, language string)

FindDataWithCode searches for content delimited by startStr and endStr within fileContent. It also extracts any code block following the found content. Returns the start and end indexes of the found content, the content itself, the code block, and the code's language if specified. If the start or end strings are not found, or if the code block is not properly terminated, returns -1 for indexes and empty strings for content, code, and language.

func MatchMiddle

func MatchMiddle(fileContent string, pattern PatternMiddle, process func(part1, part2 string) string) string

func ParseCommand

func ParseCommand(command string) types.TerminalCommand

func ReplaceData

func ReplaceData[F ReplaceTypes](fileContent, startStr, endStr string, op F, opt ...ReplaceDataOptions) string

func ReplaceDataFunc

func ReplaceDataFunc(fileContent, startStr, endStr string, process func(data string) string) string

func ReplaceDataPtr added in v1.4.0

func ReplaceDataPtr[F ReplaceTypesPtr](fileContent *string, opt ReplaceDataOptionsPtr[F])

func ReplaceDataString

func ReplaceDataString(fileContent, startStr, endStr, replaceWith string) string

Types

type ParseResult

type ParseResult struct {
	NewCode            string
	Path               string
	Lang               string
	File               string
	ID                 string
	JS                 string
	Endpoint           string
	Before             []types.TerminalCommand
	Cmd                []types.TerminalCommand
	After              []types.TerminalCommand
	CodeBlockShowStart int
	CodeBlockShowEnd   int
	IsStream           bool
	IsEdit             bool
	InjectCode         bool
}

func ParseCast

func ParseCast(cast, code string) ParseResult

type Pattern

type Pattern struct {
	Start    string
	End      string
	AltStart string
	AltEnd   string
}

func NewShortPattern

func NewShortPattern(start, end string) Pattern

type PatternMiddle

type PatternMiddle struct {
	Start       string
	StartAlt    string
	Middle      string
	MiddleStart string
	MiddleEnd   string
	End         string
	EndAlt      string
}

func PatternMiddleSimple

func PatternMiddleSimple(start, middle, end string) PatternMiddle

type ReplaceDataOptions

type ReplaceDataOptions struct {
	Once             bool
	OnlyAllowOnStart bool
}

type ReplaceDataOptionsPtr added in v1.4.0

type ReplaceDataOptionsPtr[F ReplaceTypesPtr] struct {
	StartStr         *string
	EndStr           *string
	Pattern          *string
	Op               F
	Once             bool
	OnlyAllowOnStart bool
}

ReplaceDataOptionsPtr takes pointer to the fileContent.

you either use Pattern or StartStr/EndStr

type ReplaceTypes

type ReplaceTypes interface {
	string | func(data string) string | func(data string)
}

type ReplaceTypesPtr added in v1.4.0

type ReplaceTypesPtr interface {
	string | func(data string) | func()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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