fileText

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: MIT Imports: 11 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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