github.com/enetx/g@v1.0.80/string_builder.go (about)

     1  package g
     2  
     3  import "strings"
     4  
     5  // Builder represents a string builder.
     6  type Builder struct{ builder *strings.Builder }
     7  
     8  // NewBuilder creates a new instance of Builder.
     9  func NewBuilder() *Builder { return &Builder{new(strings.Builder)} }
    10  
    11  // Write appends a string to the current state of the builder.
    12  func (b *Builder) Write(str String) *Builder {
    13  	b.builder.WriteString(str.Std())
    14  	return b
    15  }
    16  
    17  // WriteBytes appends a byte slice to the current state of the builder.
    18  func (b *Builder) WriteBytes(bs Bytes) *Builder {
    19  	b.builder.Write(bs)
    20  	return b
    21  }
    22  
    23  // WriteByte appends a byte to the current state of the builder.
    24  func (b *Builder) WriteByte(c byte) *Builder {
    25  	b.builder.WriteByte(c)
    26  	return b
    27  }
    28  
    29  // WriteRune appends a rune to the current state of the builder.
    30  func (b *Builder) WriteRune(r rune) *Builder {
    31  	b.builder.WriteRune(r)
    32  	return b
    33  }
    34  
    35  // Grow increases the capacity of the builder by n bytes.
    36  func (b *Builder) Grow(n Int) { b.builder.Grow(n.Std()) }
    37  
    38  // Cap returns the current capacity of the builder.
    39  func (b *Builder) Cap() Int { return Int(b.builder.Cap()) }
    40  
    41  // Len returns the current length of the string in the builder.
    42  func (b *Builder) Len() Int { return Int(b.builder.Len()) }
    43  
    44  // Reset clears the content of the Builder, resetting it to an empty state.
    45  func (b *Builder) Reset() { b.builder.Reset() }
    46  
    47  // String returns the content of the builder as a string.
    48  func (b *Builder) String() String { return String(b.builder.String()) }