github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/strings/builder.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 strings
     6  
     7  // Builderは、 [Builder.Write] メソッドを使用して効率的に文字列を構築するために使用されます。
     8  // メモリのコピーを最小限に抑えます。ゼロ値はすぐに使用できます。
     9  // 非ゼロのBuilderをコピーしないでください。
    10  type Builder struct {
    11  	addr *Builder
    12  
    13  	// External users should never get direct access to this buffer, since
    14  	// the slice at some point will be converted to a string using unsafe, also
    15  	// data between len(buf) and cap(buf) might be uninitialized.
    16  	buf []byte
    17  }
    18  
    19  // Stringは、蓄積された文字列を返します。
    20  func (b *Builder) String() string
    21  
    22  // Lenは、蓄積されたバイト数を返します。b.Len() == len(b.String())です。
    23  func (b *Builder) Len() int
    24  
    25  // Capは、ビルダーの基礎となるバイトスライスの容量を返します。
    26  // 構築中の文字列に割り当てられた総スペースを含み、すでに書き込まれたバイトも含みます。
    27  func (b *Builder) Cap() int
    28  
    29  // Resetは、 [Builder] を空にリセットします。
    30  func (b *Builder) Reset()
    31  
    32  // Growは、必要に応じてbの容量を拡張し、別のnバイトのスペースを保証します。
    33  // Grow(n)の後、少なくともnバイトを別の割り当てなしでbに書き込むことができます。
    34  // nが負の場合、Growはパニックを引き起こします。
    35  func (b *Builder) Grow(n int)
    36  
    37  // Writeは、pの内容をbのバッファに追加します。
    38  // Writeは常にlen(p)、nilを返します。
    39  func (b *Builder) Write(p []byte) (int, error)
    40  
    41  // WriteByteは、バイトcをbのバッファに追加します。
    42  // 返されるエラーは常にnilです。
    43  func (b *Builder) WriteByte(c byte) error
    44  
    45  // WriteRuneは、UnicodeコードポイントrのUTF-8エンコーディングをbのバッファに追加します。
    46  // rの長さとnilエラーを返します。
    47  func (b *Builder) WriteRune(r rune) (int, error)
    48  
    49  // WriteStringは、sの内容をbのバッファに追加します。
    50  // sの長さとnilエラーを返します。
    51  func (b *Builder) WriteString(s string) (int, error)