Documentation
¶
Overview ¶
Package stringbuilder provides a minimal, mutable string buffer used internally by the libphonenumber port. It is internal because it only exists to mirror the slice of java.lang.StringBuilder the port relies on and is not part of the public API.
Index ¶
- Variables
- type Builder
- func (b *Builder) ByteAt(i int) (byte, error)
- func (b *Builder) Bytes() []byte
- func (b *Builder) CharAt(i int) byte
- func (b *Builder) Delete(start, end int)
- func (b *Builder) Insert(i int, p []byte) (int, error)
- func (b *Builder) InsertString(i int, s string) (int, error)
- func (b *Builder) LastIndexOf(s string) int
- func (b *Builder) Len() int
- func (b *Builder) Reset()
- func (b *Builder) ResetWith(buf []byte) (int, error)
- func (b *Builder) ResetWithString(s string) (int, error)
- func (b *Builder) SetLength(n int)
- func (b *Builder) String() string
- func (b *Builder) Substring(start, end int) string
- func (b *Builder) Write(p []byte) (int, error)
- func (b *Builder) WriteByte(c byte) error
- func (b *Builder) WriteRune(r rune) (int, error)
- func (b *Builder) WriteString(s string) (int, error)
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidIndex = errors.New("stringbuilder: invalid index")
ErrInvalidIndex is returned by Insert/InsertString/ByteAt when the given index falls outside the buffer.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a minimal, mutable string buffer that mirrors the parts of java.lang.StringBuilder the libphonenumber port relies on — chiefly the ability to insert at an arbitrary index, which neither strings.Builder nor bytes.Buffer provide. It is backed by a plain []byte and leans on the standard library (slices.Insert, utf8.AppendRune) for the heavy lifting.
func (*Builder) ByteAt ¶
ByteAt returns the byte at index i, or ErrInvalidIndex if i is out of range.
func (*Builder) Bytes ¶
Bytes returns the underlying contents. The slice is valid until the next mutating call; callers that retain it should copy.
func (*Builder) CharAt ¶
CharAt returns the byte at index i, mirroring StringBuilder.charAt. Callers in the port only ever index ASCII content, so a byte is an exact analogue of Java's char here.
func (*Builder) Insert ¶
Insert inserts p at index i, growing the buffer as needed. It returns ErrInvalidIndex if i is negative or greater than the buffer length.
func (*Builder) InsertString ¶
InsertString inserts s at index i, growing the buffer as needed. It returns ErrInvalidIndex if i is negative or greater than the buffer length.
func (*Builder) LastIndexOf ¶
LastIndexOf returns the byte index of the last occurrence of s, or -1 if absent, mirroring StringBuilder.lastIndexOf.
func (*Builder) Reset ¶
func (b *Builder) Reset()
Reset empties the buffer while retaining its capacity.
func (*Builder) ResetWithString ¶
ResetWithString replaces the buffer's contents with s.
func (*Builder) SetLength ¶
SetLength truncates the buffer to n bytes, or pads it with NUL bytes if n is greater than the current length, mirroring StringBuilder.setLength.
func (*Builder) String ¶
String returns the contents as a string. A nil receiver returns "<nil>", which is handy when debugging.
func (*Builder) Substring ¶
Substring returns the bytes in [start, end) as a string, mirroring StringBuilder.substring(start, end).
func (*Builder) Write ¶
Write appends p to the buffer. The error is always nil; it exists to satisfy io.Writer.
func (*Builder) WriteByte ¶
WriteByte appends c to the buffer. The error is always nil; it exists to satisfy io.ByteWriter.