Documentation ¶
Overview ¶
Package edi allows edit files.
There are a great number of functions related. It avoids to have to use an external command to get the same result, with the advantage of that it can create automatically a backup before of editing.
Index ¶
- func Append(filename string, b []byte) error
- func AppendString(filename string, s string) error
- func Backup(filename string) error
- func Comment(filename string, reLine string) error
- func CommentM(filename string, reLine []string) error
- func CommentOut(filename string, reLine string) error
- func CommentOutM(filename string, reLine []string) error
- func Delete(filename string, begin, end int64) error
- func Replace(filename string, r []Replacer) error
- func ReplaceAtLine(filename string, r []ReplacerAtLine) error
- func ReplaceAtLineN(filename string, r []ReplacerAtLine, n int) error
- func ReplaceN(filename string, r []Replacer, n int) error
- func SetCommonOpts(opts *Options)
- type Editor
- func (ed *Editor) Append(b []byte) error
- func (ed *Editor) AppendString(s string) error
- func (ed *Editor) Close() error
- func (ed *Editor) Comment(reLine []string) error
- func (ed *Editor) CommentOut(reLine []string) error
- func (ed *Editor) Delete(begin, end int64) error
- func (ed *Editor) Replace(r []Replacer) error
- func (ed *Editor) ReplaceAtLine(r []ReplacerAtLine) error
- func (ed *Editor) ReplaceAtLineN(r []ReplacerAtLine, n int) error
- func (ed *Editor) ReplaceN(r []Replacer, n int) error
- type Finder
- type ModeFind
- type Options
- type Replacer
- type ReplacerAtLine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendString ¶
AppendString is like Append, but writes the contents of string s rather than an array of bytes.
func Backup ¶
Backup creates a backup of the named file.
The schema used for the new name is: {name}\+[1-9]~
name: The original file name. + : Character used to separate the file name from rest. number: A number from 1 to 9, using rotation. ~ : To indicate that it is a backup, just like it is used in Unix systems.
func Comment ¶
Comment inserts the comment character in lines that mach the regular expression in reLine, at the named file.
func CommentM ¶
CommentM inserts the comment character in lines that mach any regular expression in reLine, at the named file.
func CommentOut ¶
CommentOut removes the comment character of lines that mach the regular expression in reLine, at the named file.
func CommentOutM ¶
CommentOutM removes the comment character of lines that mach any regular expression in reLine, at the named file.
func ReplaceAtLine ¶
func ReplaceAtLine(filename string, r []ReplacerAtLine) error
ReplaceAtLine replaces all regular expressions mathed in r for the named file, if the line is matched at the first.
func ReplaceAtLineN ¶
func ReplaceAtLineN(filename string, r []ReplacerAtLine, n int) error
ReplaceAtLineN replaces a number of regular expressions mathed in r for the named file, if the line is matched at the first.
func SetCommonOpts ¶
func SetCommonOpts(opts *Options)
SetCommonOpts sets the options to use by the package-level functions.
Types ¶
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor represents the file to edit.
func NewEditor ¶
NewEdit prepares a file to edit. There is to use 'Close()' at finish.
Whether `opts` is null, then uses options by default.
func (*Editor) Append ¶
Append writes len(b) bytes at the end of the File. It returns an error, if any.
func (*Editor) AppendString ¶
AppendString is like Append, but writes the contents of string s rather than an array of bytes.
func (*Editor) Comment ¶
Comment inserts the comment character in lines that mach any regular expression in reLine.
func (*Editor) CommentOut ¶
CommentOut removes the comment character of lines that mach any regular expression in reLine.
func (*Editor) ReplaceAtLine ¶
func (ed *Editor) ReplaceAtLine(r []ReplacerAtLine) error
ReplaceAtLine replaces all regular expressions mathed in r, if the line is matched at the first.
func (*Editor) ReplaceAtLineN ¶
func (ed *Editor) ReplaceAtLineN(r []ReplacerAtLine, n int) error
ReplaceAtLineN replaces regular expressions mathed in r, if the line is matched at the first. The count determines the number to match:
n > 0: at most n matches n == 0: the result is none n < 0: all matches
type Finder ¶
type Finder struct {
// contains filtered or unexported fields
}
Finder represents the file where find a string.
func NewFinderFromFile ¶ added in v1.1.1
NewFinder prepares the 'Finder' via the `filename`.
type ModeFind ¶
type ModeFind uint
A ModeFind value is a set of flags (or 0) to control behavior at find into a file.
type Options ¶
type Options struct { // Character for comment. Comment []byte // Do backup before of edit. Backup bool Log *log.Logger }
Options are options to edit a text file.
type Replacer ¶
type Replacer struct {
Search, Replace string
}
Replacer represents the text to be replaced.
type ReplacerAtLine ¶
type ReplacerAtLine struct {
Line, Search, Replace string
}
ReplacerAtLine represents the text to be replaced into a line.