changeset

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEFAULT_LINE_ATTRIBUTES = []string{
	"author", "lmkr", "insertorder", "start",
}

Some of these attributes are kept for compatibility purposes. Not sure if we need all of them

View Source
var LineAttributes = []string{lineMarkerAttribute, "list"}

If one of these attributes are set to the first character of a line it is considered as a line attribute marker i.e. attributes set on this marker are applied to the whole line. The list attribute is only maintained for compatibility reasons

Functions

func ApplyToAText

func ApplyToAText(cs string, atext apool.AText, pool apool.APool) (*apool.AText, error)

func ApplyToAttribution

func ApplyToAttribution(cs string, astr string, pool apool.APool) (*string, error)

func ApplyToText

func ApplyToText(cs string, text string) (*string, error)

func ApplyZip

func ApplyZip(in1 string, in2 string, callback func(*Op, *Op) (*Op, error)) (*string, error)

func AttribsFromString

func AttribsFromString(str string, pool apool.APool) []apool.Attribute

func AttribsToString

func AttribsToString(attribs []apool.Attribute, pool *apool.APool) (*string, error)

func AttributeTester

func AttributeTester(attribPair apool.Attribute, pool *apool.APool) func(arg *string) bool

func CheckRep

func CheckRep(cs string) (*string, error)

func CloneAText

func CloneAText(atext apool.AText) apool.AText

func Compose

func Compose(cs1 string, cs2 string, pool *apool.APool) (*string, error)

func ComposeAttributes

func ComposeAttributes(attribs1 string, attribs2 string, resultIsMutation bool, pool *apool.APool) string

func DecodeAttribString

func DecodeAttribString(s string) ([]int, error)

func DeserializeOps

func DeserializeOps(ops string) (*[]Op, error)

func Follow

func Follow(c string, rebasedChangeset string, reverseInsertOrder bool, pool *apool.APool) (*string, error)

func HasAttrib

func HasAttrib(attribs *AttributeMap) bool

func Identity

func Identity(n int) string

func Inverse added in v0.0.2

func Inverse(cs string, lines []string, alines []string, pool *apool.APool) (*string, error)

func JoinAttributionLines

func JoinAttributionLines(theAlines []string) string

func MakeAText

func MakeAText(str string, attribs *string) apool.AText

func MakeAttribution

func MakeAttribution(text string) string

func MakeSplice

func MakeSplice(orig string, start int, ndel int, ins string, attribs *string, pool *apool.APool) (string, error)

func MoveOpsToNewPool

func MoveOpsToNewPool(cs string, oldPool *apool.APool, newPool *apool.APool) string

func MutateAttributionLines added in v0.0.2

func MutateAttributionLines(cs string, lines *[]string, pool *apool.APool) error

func MutateTextLines added in v0.0.2

func MutateTextLines(cs string, lines *[]string) error

func OldLen

func OldLen(cs string) (*int, error)

func OpsFromAText

func OpsFromAText(atext apool.AText) *[]Op

func Pack

func Pack(oldLen int, newLen int, opStr string, bank string) string

func RandomTestChangeset added in v0.0.2

func RandomTestChangeset(origText string, withAttribs bool) (string, string)

func SplitAttributionLines

func SplitAttributionLines(attrOps string, text string) ([]string, error)

func SplitTextLines added in v0.0.2

func SplitTextLines(text string) []string

func StringToAttrib

func StringToAttrib(attrib []string) (*apool.Attribute, error)

func Subattribution added in v0.0.2

func Subattribution(astr string, start int, optEnd *int) (*string, error)

Types

type AttributeManager

type AttributeManager struct {
}

type AttributeMap

type AttributeMap struct {
	// contains filtered or unexported fields
}

func FromString

func FromString(s string, pool *apool.APool) *AttributeMap

func NewAttributeMap

func NewAttributeMap(pool *apool.APool) *AttributeMap

func (*AttributeMap) Get

func (a *AttributeMap) Get(key string) *string

func (*AttributeMap) Has

func (a *AttributeMap) Has(key string) bool

func (*AttributeMap) Iter added in v0.0.2

func (a *AttributeMap) Iter() map[string]string

func (*AttributeMap) Set

func (a *AttributeMap) Set(key string, value string) *AttributeMap

func (*AttributeMap) Size

func (a *AttributeMap) Size() int

func (*AttributeMap) String

func (a *AttributeMap) String() string

func (*AttributeMap) Update

func (a *AttributeMap) Update(entries []apool.Attribute, emptyValueISDelete *bool) *AttributeMap

*

  • @param {Iterable<Attribute>} entries - [key, value] pairs to insert into this map.
  • @param {boolean} [emptyValueIsDelete] - If true and an entry's value is the empty string, the
  • key is removed from this map (if present).
  • @returns {AttributeMap} `this` (for chaining).

func (*AttributeMap) UpdateFromString

func (a *AttributeMap) UpdateFromString(key string, emptyValueIsDelete *bool) *AttributeMap

*

  • @param {AttributeString} str - The attribute string identifying the attributes to insert into
  • this map.
  • @param {boolean} [emptyValueIsDelete] - If true and an entry's value is the empty string, the
  • key is removed from this map (if present).
  • @returns {AttributeMap} `this` (for chaining).

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(oldLen int) *Builder

func (*Builder) Insert

func (b *Builder) Insert(text string, attribs KeepArgs, pool *apool.APool) *Builder

*

  • @param {string} text - Text to insert.
  • @param {(string|Attribute[])} attribs - Either [[key1,value1],[key2,value2],...] or '*0*1...'
  • (no pool needed in latter case).
  • @param {?AttributePool} pool - Attribute pool, only required if `attribs` is a list of
  • attribute key, value pairs.
  • @returns {Builder} this

func (*Builder) Keep

func (b *Builder) Keep(N int, L int, attribs KeepArgs, pool *apool.APool) *Builder

*

  • @param {number} N - Number of characters to keep.
  • @param {number} L - Number of newlines among the `N` characters. If positive, the last
  • character must be a newline.
  • @param {(string|Attribute[])} attribs - Either [[key1,value1],[key2,value2],...] or '*0*1...'
  • (no pool needed in latter case).
  • @param {?AttributePool} pool - Attribute pool, only required if `attribs` is a list of
  • attribute key, value pairs.
  • @returns {Builder} this

func (*Builder) KeepText

func (b *Builder) KeepText(text string, attribs *KeepArgs, pool *apool.APool) *Builder

*

  • @param {string} text - Text to keep.
  • @param {(string|Attribute[])} attribs - Either [[key1,value1],[key2,value2],...] or '*0*1...'
  • (no pool needed in latter case).
  • @param {?AttributePool} pool - Attribute pool, only required if `attribs` is a list of
  • attribute key, value pairs.
  • @returns {Builder} this

func (*Builder) Remove

func (b *Builder) Remove(N, L int) *Builder

func (*Builder) ToString

func (b *Builder) ToString() string

type Changeset

type Changeset struct {
	OldLen   int
	NewLen   int
	Ops      string
	CharBank string
}

func Unpack

func Unpack(cs string) (*Changeset, error)

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

func (*Iterator[T]) Next

func (it *Iterator[T]) Next() (*T, bool)

Next returns the next element in the iterator and a boolean indicating if it's the last element

type KeepArgs

type KeepArgs struct {
	// contains filtered or unexported fields
}

type MergingOpAssembler

type MergingOpAssembler struct {
	// contains filtered or unexported fields
}

func NewMergingOpAssembler

func NewMergingOpAssembler() *MergingOpAssembler

func (*MergingOpAssembler) Append

func (m *MergingOpAssembler) Append(op Op)

func (*MergingOpAssembler) Clear

func (m *MergingOpAssembler) Clear()

func (*MergingOpAssembler) EndDocument

func (m *MergingOpAssembler) EndDocument()

func (*MergingOpAssembler) String

func (m *MergingOpAssembler) String() string

type Op

type Op struct {
	OpCode  string
	Chars   int
	Lines   int
	Attribs string
}

func NewOp

func NewOp(opCode *string) Op

func OpsFromText

func OpsFromText(opcode string, text string, attribs *KeepArgs, pool *apool.APool) []Op

func SlicerZipperFunc

func SlicerZipperFunc(attOp *Op, csOp *Op, pool *apool.APool) (*Op, error)

func (*Op) String

func (op *Op) String() string

type OpAssembler

type OpAssembler struct {
	// contains filtered or unexported fields
}

func NewOpAssembler

func NewOpAssembler() OpAssembler

func (*OpAssembler) Append

func (oa *OpAssembler) Append(op Op)

func (*OpAssembler) Clear

func (oa *OpAssembler) Clear()

func (*OpAssembler) String

func (oa *OpAssembler) String() string

type PrepareForWireStruct

type PrepareForWireStruct struct {
	Translated string
	Pool       apool.APool
}

func PrepareForWire

func PrepareForWire(cs string, pool apool.APool) PrepareForWireStruct

type SmartOpAssembler

type SmartOpAssembler struct {
	// contains filtered or unexported fields
}

func NewSmartOpAssembler

func NewSmartOpAssembler() *SmartOpAssembler

func (*SmartOpAssembler) Append

func (sm *SmartOpAssembler) Append(op Op)

func (*SmartOpAssembler) Clear

func (sm *SmartOpAssembler) Clear()

func (*SmartOpAssembler) EndDocument

func (sm *SmartOpAssembler) EndDocument()

func (*SmartOpAssembler) FlushKeeps

func (sm *SmartOpAssembler) FlushKeeps()

func (*SmartOpAssembler) LengthChange

func (sm *SmartOpAssembler) LengthChange() int

func (*SmartOpAssembler) String

func (sm *SmartOpAssembler) String() string

type StringAssembler

type StringAssembler struct {
	// contains filtered or unexported fields
}

func NewStringAssembler

func NewStringAssembler() StringAssembler

func (*StringAssembler) Append

func (sa *StringAssembler) Append(s string)

func (*StringAssembler) Clear

func (sa *StringAssembler) Clear()

func (*StringAssembler) String

func (sa *StringAssembler) String() string

type StringIterator

type StringIterator struct {
	// contains filtered or unexported fields
}

func NewStringIterator

func NewStringIterator(str string) StringIterator

func (*StringIterator) AssertRemaining

func (si *StringIterator) AssertRemaining(n int) error

func (*StringIterator) Peek

func (si *StringIterator) Peek(n int) (*string, error)

func (*StringIterator) Remaining

func (si *StringIterator) Remaining() int

func (*StringIterator) Skip

func (si *StringIterator) Skip(n int) error

func (*StringIterator) Take

func (si *StringIterator) Take(n int) (*string, error)

type TextLinesMutator added in v0.0.2

type TextLinesMutator struct {
	// contains filtered or unexported fields
}

TextLinesMutator is a class to iterate and modify texts which have several lines. It is used for applying Changesets on arrays of lines.

Mutation operations have the same constraints as exports operations with respect to newlines, but not the other additional constraints (i.e. ins/del ordering, forbidden no-ops, non-mergeability, final newline). Can be used to mutate lists of strings where the last char of each string is not actually a newline, but for the purposes of N and L values, the caller should pretend it is, and for things to work right in that case, the input to the Insert method should be a single line with no newlines.

func NewTextLinesMutator added in v0.0.2

func NewTextLinesMutator(lines *[]string) *TextLinesMutator

NewTextLinesMutator creates a new TextLinesMutator with the given lines. Lines are mutated in place.

func (*TextLinesMutator) Close added in v0.0.2

func (m *TextLinesMutator) Close()

Close closes the splice.

func (*TextLinesMutator) GetLines added in v0.0.2

func (m *TextLinesMutator) GetLines() []string

GetLines returns the current state of the lines.

func (*TextLinesMutator) HasMore added in v0.0.2

func (m *TextLinesMutator) HasMore() bool

HasMore checks if curLine (the line we are in when curSplice is applied) is the last line in lines. Returns true if there are lines left.

func (*TextLinesMutator) Insert added in v0.0.2

func (m *TextLinesMutator) Insert(text string, L int) error

Insert inserts text into lines array.

func (*TextLinesMutator) Remove added in v0.0.2

func (m *TextLinesMutator) Remove(N, L int) string

Remove removes text from lines array.

func (*TextLinesMutator) RemoveLines added in v0.0.2

func (m *TextLinesMutator) RemoveLines(L int) string

RemoveLines removes whole lines from lines array.

func (*TextLinesMutator) Skip added in v0.0.2

func (m *TextLinesMutator) Skip(N, L int, includeInSplice bool)

Skip skips some characters. Can contain newlines.

func (*TextLinesMutator) SkipLines added in v0.0.2

func (m *TextLinesMutator) SkipLines(L int, includeInSplice bool)

SkipLines skips some newlines by putting them into the splice.

Jump to

Keyboard shortcuts

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