fileText

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PRESERVE_REPL1 = "¤_¤_¤_¤_¤_¤"
	PRESERVE_REPL2 = "_¤_¤_¤_¤_¤_"
)

Variables

This section is empty.

Functions

func BuildRegexp

func BuildRegexp(search string, caseSensitive, POSIXcharClass, POSIXstrictMode,
	regExp, wildcard, useEscapeChar, wholeWord bool) (regX *regexp.Regexp, err error)

BuildRegexp: get regular expression from given pattern taking into account the parameters provided.

func IsTextFile

func IsTextFile(filename string, minSizeLimit, maxSizeLimit int64) (isText, gtLimit bool, err error)

IsTextFileSimple: Check for text file ... thresholdLineEnd work well with 0.6 and thresholdOverChars with 5

func ReplaceInFile

func ReplaceInFile(filename, search, replace string, doBackup ...bool) (found bool, err error)

replaceInFile: allow using regexp in argument.

func WriteTextFile

func WriteTextFile(filename, data string, appendIfExist ...bool) error

Write string to file low lvl format with append possibility.

Types

type LinesInfos

type LinesInfos struct {
	FoundLinesIdx  []lineIdxInf // Indexes by lines of all found patterns
	UntouchedLines []int        // Line number that will not be changed.

	WordsPosIdx [][]int // Indexes of all found patterns
	Count       int
	Eol         string // EOL used in current file.
	// contains filtered or unexported fields
}

LinesInfos: This structure hold some methods to get indexes referenced by lines from a list of indexes that was found using regexp' functions.

func LinesInfosBuild

func LinesInfosBuild(textByte *[]byte, patternPos [][]int) (li LinesInfos)

LinesInfosBuild: Create a structure to hold indexes and positions of them by line number. "patternPos" must contain the results of a previous call to "FindAllStringIndex".

type SearchAndReplace

type SearchAndReplace struct {
	Filename string

	TextBytes []byte

	ToSearch,
	TextBytesMd5,
	ReplaceWith string

	ToSearchRegexp *regexp.Regexp

	CaseSensitive,
	UseEscapeChar,
	UseEscapeCharToRepl,
	PosixCharClass,
	PosixStrictMode,
	Regex,
	Wildcard,
	WholeWord,
	DoReplace,
	DoBackup bool

	Pos LinesInfos

	Occurrences,
	OccReplaced int
	// Callback used in searching section (not replacing)
	OnEachLine func(idx, lineStart, lineEnd int)
	// contains filtered or unexported fields
}

SearchAndReplace: is a structure that hold some methods to provide an efficient way to search, replace given pattern in text. There is a lot of options to perform personalized research.

func SearchAndReplaceNew

func SearchAndReplaceNew(filename string, textBytes []byte, toSearch, replaceWith string) (s *SearchAndReplace)

SearchAndReplaceNew: Cre at new "SearchAndReplace" structure with short defaul parameters, for the case of single speed search.

func (*SearchAndReplace) HasBeenDisplayed

func (s *SearchAndReplace) HasBeenDisplayed(set ...bool) bool

HasBeenDisplayed: return/set variable content

func (*SearchAndReplace) Init

func (s *SearchAndReplace) Init(textBytes []byte, toSearch, replaceWith string, caseSensitive, posixCharClass,
	posixStrictMode, regex, wildcard, escapeChar, escapeCharToRepl, wholeWord, doReplace bool) (err error)

Init: do a complete initialization a "SearchAndReplace" structure with given parameters.

func (*SearchAndReplace) IsReadyToReplace

func (s *SearchAndReplace) IsReadyToReplace() bool

ReadyToReplace: return variable content

func (*SearchAndReplace) ReplaceInFile

func (s *SearchAndReplace) ReplaceInFile() error

ReplaceInFile: After searching completed, this method perform in file replacement.

func (*SearchAndReplace) Reset

func (s *SearchAndReplace) Reset()

ReadyToReplace: return variable content

func (*SearchAndReplace) SearchAndReplace

func (s *SearchAndReplace) SearchAndReplace() (err error)

Search in plain text, use "Init" to fill needed information about search preferences before using ...

type SearchAndReplaceFiles

type SearchAndReplaceFiles struct {
	FileName      string
	SearchAndRepl SearchAndReplace
	NotTextFile   bool
	Occurrences   int
}

SearchAndReplaceFiles: is a structure that hold some methods to provide an efficient way to search, replace given pattern in text files. There is a lot of options to perform personalized research.

func SearchAndReplaceInFiles

func SearchAndReplaceInFiles(filenames []string, toSearch, replaceWith string, minSizeLimit, maxSizeLimit int64, caseSensitive,
	posixCharClass, posixStrictMode, regex, wildcard, useEscapeChar, useEscapeCharToRepl, wholeWord, doReplace, acceptBinary,
	removeEmptyResult bool) (founds []SearchAndReplaceFiles, occurFound int, err error)

SearchAndReplaceInMultipleFiles: Search in multiples text files. return a slice type []SearchAndReplaceInFiles that contain all information about found patterns, indexes, lines position, file type, size and occurances count.

Jump to

Keyboard shortcuts

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