-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add str util: strutil.Buffer, a extended bytes.Buffer
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package strutil | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
) | ||
|
||
// Buffer wrap and extends the bytes.Buffer | ||
type Buffer struct { | ||
*bytes.Buffer | ||
} | ||
|
||
// NewEmptyBuffer instance | ||
func NewEmptyBuffer() *Buffer { | ||
return &Buffer{ | ||
Buffer: new(bytes.Buffer), | ||
} | ||
} | ||
|
||
// QuietWritef write message to buffer | ||
func (b *Buffer) QuietWritef(tpl string, vs ...interface{}) { | ||
_, _ = b.WriteString(fmt.Sprintf(tpl, vs...)) | ||
} | ||
|
||
// QuietWriteln write message to buffer with newline | ||
func (b *Buffer) QuietWriteln(s string) { | ||
_, _ = b.WriteString(s) | ||
_ = b.WriteByte('\n') | ||
} | ||
|
||
// QuietWriteString to buffer | ||
func (b *Buffer) QuietWriteString(ss ...string) { | ||
for _, s := range ss { | ||
_, _ = b.WriteString(s) | ||
} | ||
} | ||
|
||
// MustWriteString to buffer | ||
func (b *Buffer) MustWriteString(ss ...string) { | ||
for _, s := range ss { | ||
_, err := b.WriteString(s) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters