github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/edit/edit.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package edit implements buffered position-based editing of byte slices.
     6  package edit
     7  
     8  // A Buffer is a queue of edits to apply to a given byte slice.
     9  type Buffer struct {
    10  	old []byte
    11  	q   edits
    12  }
    13  
    14  // NewBuffer returns a new buffer to accumulate changes to an initial data slice.
    15  // The returned buffer maintains a reference to the data, so the caller must ensure
    16  // the data is not modified until after the Buffer is done being used.
    17  func NewBuffer(data []byte) *Buffer
    18  
    19  func (b *Buffer) Insert(pos int, new string)
    20  
    21  func (b *Buffer) Delete(start, end int)
    22  
    23  func (b *Buffer) Replace(start, end int, new string)
    24  
    25  // Bytes returns a new byte slice containing the original data
    26  // with the queued edits applied.
    27  func (b *Buffer) Bytes() []byte
    28  
    29  // String returns a string containing the original data
    30  // with the queued edits applied.
    31  func (b *Buffer) String() string