Documentation
¶
Index ¶
- Constants
- Variables
- func BackwardWord(txt []rune, pos, steps int) (wpos, nstep int)
- func ForwardWord(txt []rune, pos, steps int) (wpos, nstep int)
- func IsWordBreak(r1, r2 rune) bool
- func RuneIsWordBreak(r rune) bool
- type AdjustPosDel
- func (i AdjustPosDel) Desc() string
- func (i AdjustPosDel) Int64() int64
- func (i AdjustPosDel) MarshalText() ([]byte, error)
- func (i *AdjustPosDel) SetInt64(in int64)
- func (i *AdjustPosDel) SetString(s string) error
- func (i AdjustPosDel) String() string
- func (i *AdjustPosDel) UnmarshalText(text []byte) error
- func (i AdjustPosDel) Values() []enums.Enum
- type Edit
- func (te *Edit) AdjustPos(pos Pos, del AdjustPosDel) Pos
- func (te *Edit) AdjustPosIfAfterTime(pos Pos, t time.Time, del AdjustPosDel) Pos
- func (te *Edit) AdjustRegion(reg Region) Region
- func (te *Edit) Clone() *Edit
- func (te *Edit) Copy(cp *Edit)
- func (te *Edit) String() string
- func (te *Edit) ToBytes() []byte
- type Match
- type Pos
- type Range
- type Region
- func (tr *Region) Age() time.Duration
- func (tr *Region) Ago(t time.Time) time.Duration
- func (tr Region) Contains(ps Pos) bool
- func (tr Region) ContainsLine(ln int) bool
- func (tr *Region) FromStringURL(link string) bool
- func (tr Region) Intersect(or Region, endChar int) Region
- func (tr *Region) IsAfterTime(t time.Time) bool
- func (tr Region) IsNil() bool
- func (tr Region) MoveToLine(ln int) Region
- func (tr Region) NumLines() int
- func (tr Region) ShiftLines(ln int) Region
- func (tr *Region) Since(earlier *Region) time.Duration
- func (tr *Region) String() string
- func (tr *Region) TimeNow()
Constants ¶
const ( // IgnoreCase is passed to search functions to indicate case should be ignored IgnoreCase = true // UseCase is passed to search functions to indicate case is relevant UseCase = false )
Variables ¶
var ( // PosErr represents an error text position (-1 for both line and char) // used as a return value for cases where error positions are possible. PosErr = Pos{-1, -1} PosZero = Pos{} )
var MatchContext = 30
MatchContext is how much text to include on either side of the match.
var RegionZero = Region{}
Functions ¶
func BackwardWord ¶
BackwardWord moves position index backward by words, for given number of steps. Returns the number of steps actually moved, given the amount of text available.
func ForwardWord ¶
ForwardWord moves position index forward by words, for given number of steps. Returns the number of steps actually moved, given the amount of text available.
func IsWordBreak ¶
IsWordBreak defines what counts as a word break for the purposes of selecting words. r1 is the rune in question, r2 is the rune past r1 in the direction you are moving. Pass -1 for r2 if there is no rune past r1.
func RuneIsWordBreak ¶
RuneIsWordBreak returns true if given rune counts as a word break for the purposes of selecting words.
Types ¶
type AdjustPosDel ¶
type AdjustPosDel int32 //enums:enum
AdjustPosDel determines what to do with positions within deleted region
const ( // AdjustPosDelErr means return a PosErr when in deleted region. AdjustPosDelErr AdjustPosDel = iota // AdjustPosDelStart means return start of deleted region. AdjustPosDelStart // AdjustPosDelEnd means return end of deleted region. AdjustPosDelEnd )
these are options for what to do with positions within deleted region for the AdjustPos function
const AdjustPosDelN AdjustPosDel = 3
AdjustPosDelN is the highest valid value for type AdjustPosDel, plus one.
func AdjustPosDelValues ¶
func AdjustPosDelValues() []AdjustPosDel
AdjustPosDelValues returns all possible values for the type AdjustPosDel.
func (AdjustPosDel) Desc ¶
func (i AdjustPosDel) Desc() string
Desc returns the description of the AdjustPosDel value.
func (AdjustPosDel) Int64 ¶
func (i AdjustPosDel) Int64() int64
Int64 returns the AdjustPosDel value as an int64.
func (AdjustPosDel) MarshalText ¶
func (i AdjustPosDel) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*AdjustPosDel) SetInt64 ¶
func (i *AdjustPosDel) SetInt64(in int64)
SetInt64 sets the AdjustPosDel value from an int64.
func (*AdjustPosDel) SetString ¶
func (i *AdjustPosDel) SetString(s string) error
SetString sets the AdjustPosDel value from its string representation, and returns an error if the string is invalid.
func (AdjustPosDel) String ¶
func (i AdjustPosDel) String() string
String returns the string representation of this AdjustPosDel value.
func (*AdjustPosDel) UnmarshalText ¶
func (i *AdjustPosDel) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (AdjustPosDel) Values ¶
func (i AdjustPosDel) Values() []enums.Enum
Values returns all possible values for the type AdjustPosDel.
type Edit ¶
type Edit struct {
// Region for the edit, specifying the region to delete, or the size
// of the region to insert, corresponding to the Text.
// Also contains the Time stamp for this edit.
Region Region
// Text deleted or inserted, in rune lines. For Rect this is the
// spanning character distance per line, times number of lines.
Text [][]rune
// Group is the optional grouping number, for grouping edits in Undo for example.
Group int
// Delete indicates a deletion, otherwise an insertion.
Delete bool
// Rect is a rectangular region with upper left corner = Region.Start
// and lower right corner = Region.End.
// Otherwise it is for the full continuous region.
Rect bool
}
Edit describes an edit action to line-based text, operating on a Region of the text. Actions are only deletions and insertions (a change is a sequence of each, given normal editing processes).
func NewEditFromRunes ¶
NewEditFromRunes returns a 0-based edit from given runes.
func (*Edit) AdjustPos ¶
func (te *Edit) AdjustPos(pos Pos, del AdjustPosDel) Pos
AdjustPos adjusts the given text position as a function of the edit. If the position was within a deleted region of text, del determines what is returned.
func (*Edit) AdjustPosIfAfterTime ¶
AdjustPosIfAfterTime checks the time stamp and IfAfterTime, it adjusts the given text position as a function of the edit del determines what to do with positions within a deleted region either move to start or end of the region, or return an error.
func (*Edit) AdjustRegion ¶
AdjustRegion adjusts the given text region as a function of the edit, including checking that the timestamp on the region is after the edit time, if the region has a valid Time stamp (otherwise always does adjustment). If the starting position is within a deleted region, it is moved to the end of the deleted region, and if the ending position was within a deleted region, it is moved to the start.
type Match ¶
type Match struct {
// Region of the match. Column positions are in runes.
Region Region
// Text surrounding the match, at most MatchContext on either side
// (within a single line).
Text []rune
// TextMatch has the Range within the Text where the match is.
TextMatch Range
}
Match records one match for search within file, positions in runes.
type Pos ¶
Pos is a text position in terms of line and character index within a line, using 0-based line numbers, which are converted to 1 base for the String() representation. Char positions are always in runes, and can also be used for other units such as tokens, spans, or runs.
func (*Pos) FromString ¶
FromString decodes text position from a string representation of form: [#]LxxCxx. Used in e.g., URL links. Returns true if successful.
type Range ¶
type Range struct {
// St is the starting index of the range.
Start int
// Ed is the ending index of the range.
End int
}
Range defines a range with a start and end index, where end is typically exclusive, as in standard slice indexing and for loop conventions.
func WordAt ¶
WordAt returns the range for a word within given text starting at given position index. If the current position is a word break then go to next break after the first non-break.
type Region ¶
type Region struct {
// Start is the starting position of region.
Start Pos
// End is the ending position of region.
// Char position is _exclusive_ so the last char is the one before End.Char.
// Line position is _inclusive_, so the last line is End.Line.
End Pos
// Time when region was set: needed for updating locations in the text based
// on time stamp (using efficient non-pointer time).
Time nptime.Time
}
Region is a contiguous region within a source file with lines of rune chars, defined by start and end Pos positions. End.Char position is _exclusive_ so the last char is the one before End.Char. End.Line position is _inclusive_, so the last line is End.Line. There is a Time stamp for when the region was created as valid positions into the lines source, which is critical for tracking edits in live documents.
func NewRegion ¶
NewRegion creates a new text region using separate line and char values for start and end. Sets timestamp to now.
func NewRegionLen ¶
NewRegionLen makes a new Region from a starting point and a length along same line. Sets timestamp to now.
func NewRegionPos ¶
NewRegionPos creates a new text region using position values. Sets timestamp to now.
func (Region) ContainsLine ¶
ContainsLine returns true if line is within region
func (*Region) FromStringURL ¶
FromStringURL decodes text region from a string representation of form: [#]LxxCxx-LxxCxx. Used in e.g., URL links. returns true if successful
func (Region) Intersect ¶
Intersect returns the intersection of this region with given other region, where the other region is assumed to be the larger, constraining region, within which you are fitting the receiver region. Char level start / end are only constrained if on same Start / End line. The given endChar value is used for the end of an interior line.
func (*Region) IsAfterTime ¶
IsAfterTime reports if this region's time stamp is after given time value if region Time stamp has not been set, it always returns true
func (Region) IsNil ¶
IsNil checks if the region is empty, because the start is after or equal to the end.
func (Region) MoveToLine ¶
MoveToLine returns a new Region with the Start line set to given line.
func (Region) NumLines ¶
NumLines is the number of lines in this region, based on inclusive end line.
func (Region) ShiftLines ¶
ShiftLines returns a new Region with the start and End lines shifted by given number of lines.