go_StringBuilder

package module
v0.0.0-...-99376cd Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 3 Imported by: 0

README

Golang String Builder

引入依赖

go get -u github.com/golang-infrastructure/go-StringBuilder 

说明

Golang中的strings.Builder并不是真正的Builder模式,连续拼接要换行就很草, 这个库就是修改了一下内置的strings.Builder的签名并加了几个Append方法,用得更爽一些。

Example

builder := string_builder.New()
s := builder.AppendString("test").AppendString(" a is: ").AppendInt(100).String()
fmt.Println(s) // test a is: 100

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StringBuilder

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

StringBuilder A Builder is used to efficiently build a string using Write methods. It minimizes memory copying. The zero value is ready to use. Do not copy a non-zero Builder.

func New

func New(initCap ...int) *StringBuilder

func (*StringBuilder) Append

func (b *StringBuilder) Append(p []byte) *StringBuilder

func (*StringBuilder) AppendByte

func (b *StringBuilder) AppendByte(c byte) *StringBuilder

func (*StringBuilder) AppendInt

func (b *StringBuilder) AppendInt(n int) *StringBuilder

func (*StringBuilder) AppendRune

func (b *StringBuilder) AppendRune(r rune) *StringBuilder

func (*StringBuilder) AppendString

func (b *StringBuilder) AppendString(s string) *StringBuilder

func (*StringBuilder) Cap

func (b *StringBuilder) Cap() int

Cap returns the capacity of the builder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written.

func (*StringBuilder) Grow

func (b *StringBuilder) Grow(n int) *StringBuilder

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func (*StringBuilder) Len

func (b *StringBuilder) Len() int

Len returns the number of accumulated bytes; b.Len() == len(b.String()).

func (*StringBuilder) Reset

func (b *StringBuilder) Reset() *StringBuilder

Reset resets the Builder to be empty.

func (*StringBuilder) String

func (b *StringBuilder) String() string

String returns the accumulated string.

func (*StringBuilder) Write

func (b *StringBuilder) Write(p []byte) (int, error)

Write appends the contents of p to b's buffer. Write always returns len(p), nil.

func (*StringBuilder) WriteByte

func (b *StringBuilder) WriteByte(c byte) error

WriteByte appends the byte c to b's buffer. The returned error is always nil.

func (*StringBuilder) WriteRune

func (b *StringBuilder) WriteRune(r rune) (int, error)

WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. It returns the length of r and a nil error.

func (*StringBuilder) WriteString

func (b *StringBuilder) WriteString(s string) (int, error)

WriteString appends the contents of s to b's buffer. It returns the length of s and a nil error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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