struct Buffer
pub struct Buffer {
pub data string
pub off int
}Purpose
Structure encapsulating data, off.
Public fields
datastring- data
offint- offset
#bytesWork with byte data stored in strings, including search, replacement and Buffer I/O. Individual APIs distinguish byte operations from Unicode character operations.
struct Bufferpub struct Buffer {
pub data string
pub off int
}Structure encapsulating data, off.
data stringoff intbufferpub fn buffer() BufferExecute buffer.
No arguments are required.
Buffer — a value of this type
buffer_frompub fn buffer_from(s string) BufferBuffer from.
s stringBuffer — a value of this type
($&Buffer) writepub fn (b $&Buffer) write(data &string) intOperation on $&Buffer: write data and return the byte count.
b $&BufferBuffer instance used by this call (exclusive borrow).data &stringint — bytes written
($&Buffer) write_bytepub fn (b $&Buffer) write_byte(c int) intOperation on $&Buffer: write one byte. Throws on failure; handle the error or propagate it to the caller.
b $&BufferBuffer instance used by this call (exclusive borrow).c intint — bytes written
($&Buffer) read_npub fn (b $&Buffer) read_n(n int) stringOperation on $&Buffer: read at most n bytes; may return shorter or empty at end.
b $&BufferBuffer instance used by this call (exclusive borrow).n intstring — result string
(&Buffer) lengthpub fn (b &Buffer) length() intOperation on &Buffer: return the current length.
b &BufferBuffer instance used by this call (borrow).int — a value of this type
(&Buffer) textpub fn (b &Buffer) text() stringOperation on &Buffer: return the current text.
b &BufferBuffer instance used by this call (borrow).string — result string
(&Buffer) bytespub fn (b &Buffer) bytes() stringOperation on &Buffer: return the buffered bytes.
b &BufferBuffer instance used by this call (borrow).string — result string
($&Buffer) resetpub fn (b $&Buffer) reset()Operation on $&Buffer: clear internal state so the value can be reused.
b $&BufferBuffer instance used by this call (exclusive borrow).This call does not return a value.
($&Buffer) truncatepub fn (b $&Buffer) truncate(n int) intExecute truncate on $&Buffer. Throws on failure; handle the error or propagate it to the caller.
b $&BufferBuffer instance used by this call (exclusive borrow).n intint — a value of this type
view_ofpub fn view_of(s &string) strings.ByteViewCreate a borrowed read-only ByteView over the string.
s &stringstrings.ByteView — a value of this type
view_slicepub fn view_slice(s &string, off int, n int) strings.ByteViewView slice.
s &stringoff intn intstrings.ByteView — a value of this type
equalpub fn equal(a &string, b &string) boolReport whether the two values are equal.
a &stringb &stringbool — true or false
comparepub fn compare(a &string, b &string) intLexicographic compare: -1, 0, or 1.
a &stringb &stringint — negative if less, zero if equal, positive if greater
has_prefixpub fn has_prefix(s &string, prefix string) boolReport whether the value has the given prefix.
s &stringprefix stringbool — true or false
has_suffixpub fn has_suffix(s &string, suffix string) boolReport whether the value has the given suffix.
s &stringsuffix stringbool — true or false
index_bytepub fn index_byte(s &string, c int) intIndex of the first byte c; -1 if missing.
s &stringc intint — index; see the description for its range and special values
last_index_bytepub fn last_index_byte(s &string, c int) intIndex of the last byte c; -1 if missing.
s &stringc intint — index; see the description for its range and special values
last_indexpub fn last_index(s &string, sub string) intIndex of the last occurrence; -1 if missing.
s &stringsub stringint — index; see the description for its range and special values
countpub fn count(s &string, sub string) intCount non-overlapping occurrences.
s &stringsub stringint — a value of this type
replacepub fn replace(s &string, old string, new string, n int) stringReplace a substring, limited by n.
s &stringold stringnew stringn intstring — result string
replace_allpub fn replace_all(s &string, old string, new string) stringReplace every occurrence of the substring.
s &stringold stringnew stringstring — result string
containspub fn contains(s &string, sub string) boolReport whether the input contains the given piece.
s &stringsub stringbool — true or false
indexpub fn index(s &string, sub string) intIndex of the first occurrence; -1 if missing.
s &stringsub stringint — index; see the description for its range and special values
trim_leftpub fn trim_left(s &string, cutset string) stringStrip leading bytes that appear in the cutset.
s &stringcutset stringstring — result string
trim_rightpub fn trim_right(s &string, cutset string) stringStrip trailing bytes that appear in the cutset.
s &stringcutset stringstring — result string
trimpub fn trim(s &string, cutset string) stringStrip leading and trailing bytes that appear in the cutset.
s &stringcutset stringstring — result string
trim_spacepub fn trim_space(s &string) stringStrip leading and trailing ASCII whitespace.
s &stringstring — result string
trim_prefixpub fn trim_prefix(s &string, pre string) stringRemove prefix if present; otherwise return the input.
s &stringpre stringstring — result string
trim_suffixpub fn trim_suffix(s &string, suf string) stringRemove suffix if present; otherwise return the input.
s &stringsuf stringstring — result string
joinpub fn join(parts []string, sep string) stringJoin pieces with a separator.
parts []stringsep stringstring — result string
splitpub fn split(s &string, sep string) []stringSplit on the separator.
s &stringsep string[]string — slice result
fieldspub fn fields(s &string) []stringSplit on whitespace runs and drop the whitespace.
s &string[]string — slice result
index_funcpub fn index_func(s &string, f fn(int) bool) intText callbacks receive runes, aligned with strings. MapBytes remains byte-based.
s &stringf fn(int) boolfn(int) bool; pass the function value for this operation to invoke.int — index; see the description for its range and special values
last_index_funcpub fn last_index_func(s &string, f fn(int) bool) intLast index where the callback is true; -1 if missing.
s &stringf fn(int) boolfn(int) bool; pass the function value for this operation to invoke.int — index; see the description for its range and special values
map_bytespub fn map_bytes(s &string, f fn(int) int) stringMap each byte through f and rebuild the string.
s &stringf fn(int) intfn(int) int; pass the function value for this operation to invoke.string — result string
fields_funcpub fn fields_func(s &string, f fn(int) bool) []stringSplit on bytes for which the callback is true.
s &stringf fn(int) boolfn(int) bool; pass the function value for this operation to invoke.[]string — slice result
clonepub fn clone(s &string) stringCopy into a new independent string.
s &stringstring — result string
contains_funcpub fn contains_func(s &string, f fn(int) bool) boolReport whether any byte satisfies the callback.
s &stringf fn(int) boolfn(int) bool; pass the function value for this operation to invoke.bool — true or false
index_anypub fn index_any(s &string, chars string) intIndex of the first byte that appears in the cutset; -1 if missing.
s &stringchars stringint — index; see the description for its range and special values
last_index_anypub fn last_index_any(s &string, chars string) intLast index of any cutset byte; -1 if missing.
s &stringchars stringint — index; see the description for its range and special values
contains_anypub fn contains_any(s &string, chars string) boolReport whether any byte from the cutset occurs.
s &stringchars stringbool — true or false
index_runepub fn index_rune(s &string, r int) intIndex of the first rune; -1 if missing.
s &stringr intint — index; see the description for its range and special values
contains_runepub fn contains_rune(s &string, r int) boolReport whether the rune occurs.
s &stringr intbool — true or false
split_npub fn split_n(s &string, sep string, n int) []stringSplit on the separator, at most n parts.
s &stringsep stringn int[]string — slice result
split_afterpub fn split_after(s &string, sep string) []stringSplit after the separator, keeping it on each piece.
s &stringsep string[]string — slice result
split_after_npub fn split_after_n(s &string, sep string, n int) []stringSplit after the separator, at most n parts.
s &stringsep stringn int[]string — slice result
trim_left_funcpub fn trim_left_func(s &string, f fn(int) bool) stringTrim leading bytes using the callback.
s &stringf fn(int) boolfn(int) bool; pass the function value for this operation to invoke.string — result string
trim_right_funcpub fn trim_right_func(s &string, f fn(int) bool) stringTrim trailing bytes using the callback.
s &stringf fn(int) boolfn(int) bool; pass the function value for this operation to invoke.string — result string
trim_funcpub fn trim_func(s &string, f fn(int) bool) stringTrim bytes on both ends using the callback.
s &stringf fn(int) boolfn(int) bool; pass the function value for this operation to invoke.string — result string
to_valid_utf8pub fn to_valid_utf8(s &string, replacement string) stringReplace invalid UTF-8 sequences with replacement.
s &stringreplacement stringstring — result string
repeatpub fn repeat(s &string, n int) stringRepeat the content n times; n<=0 yields empty.
s &stringn intstring — result string
equal_foldpub fn equal_fold(a &string, b &string) boolASCII case-insensitive equality.
a &stringb &stringbool — true or false
to_lowerpub fn to_lower(s &string) stringMap ASCII letters to lowercase.
s &stringstring — result string
to_upperpub fn to_upper(s &string) stringMap ASCII letters to uppercase.
s &stringstring — result string
($&Buffer) growpub fn (b $&Buffer) grow(n int)Operation on $&Buffer: ensure room for at least n more bytes.
b $&BufferBuffer instance used by this call (exclusive borrow).n intThis call does not return a value.
($&Buffer) write_stringpub fn (b $&Buffer) write_string(s &string) intOperation on $&Buffer: write a string and return the byte count.
b $&BufferBuffer instance used by this call (exclusive borrow).s &stringint — bytes written
($&Buffer) write_runepub fn (b $&Buffer) write_rune(r int) intOperation on $&Buffer: write a rune as UTF-8. Throws on failure; handle the error or propagate it to the caller.
b $&BufferBuffer instance used by this call (exclusive borrow).r intint — bytes written
($&Buffer) read_bytepub fn (b $&Buffer) read_byte() intOperation on $&Buffer: read one byte; throws on failure. Throws on failure; handle the error or propagate it to the caller.
b $&BufferBuffer instance used by this call (exclusive borrow).int — a value of this type
($&Buffer) unread_bytepub fn (b $&Buffer) unread_byte() intOperation on $&Buffer: unread the last byte. Throws on failure; handle the error or propagate it to the caller.
b $&BufferBuffer instance used by this call (exclusive borrow).int — a value of this type
($&Buffer) read_runepub fn (b $&Buffer) read_rune() RuneReadOperation on $&Buffer: read one UTF-8 rune. Throws on failure; handle the error or propagate it to the caller.
b $&BufferBuffer instance used by this call (exclusive borrow).RuneRead — a value of this type
($&Buffer) unread_runepub fn (b $&Buffer) unread_rune() intOperation on $&Buffer: unread the last rune. Throws on failure; handle the error or propagate it to the caller.
b $&BufferBuffer instance used by this call (exclusive borrow).int — a value of this type
(&Buffer) cappub fn (b &Buffer) cap() intOperation on &Buffer: return the capacity.
b &BufferBuffer instance used by this call (borrow).int — a value of this type
($&Buffer) nextpub fn (b $&Buffer) next(n int) stringOperation on $&Buffer: take the next item, or end according to this type.
b $&BufferBuffer instance used by this call (exclusive borrow).n intstring — result string
struct Cutpub struct Cut {
pub before string
pub after string
pub found bool
}Structure encapsulating before, after, found.
before stringafter stringfound boolcutpub fn cut(s &string, sep string) CutCut into before/after at the first sep.
s &stringsep stringCut — a value of this type
cut_prefixpub fn cut_prefix(s &string, pre string) CutCut off a prefix when present.
s &stringpre stringCut — a value of this type
cut_suffixpub fn cut_suffix(s &string, suf string) CutCut off a suffix when present.
s &stringsuf stringCut — a value of this type
($&Buffer) read_bytespub fn (b $&Buffer) read_bytes(delim int) stringOperation on $&Buffer: read through delim (inclusive).
b $&BufferBuffer instance used by this call (exclusive borrow).delim intstring — result string
($&Reader) read_resultpub fn (r $&Reader) read_result(n int) io.ReadResultOperation on $&Reader: read result.
r $&ReaderReader instance used by this call (exclusive borrow).n intio.ReadResult — a value of this type
($&Buffer) read_resultpub fn (b $&Buffer) read_result(n int) io.ReadResultOperation on $&Buffer: read result.
b $&BufferBuffer instance used by this call (exclusive borrow).n intio.ReadResult — a value of this type
($&Buffer) write_resultpub fn (b $&Buffer) write_result(data string) io.WriteResultOperation on $&Buffer: write result.
b $&BufferBuffer instance used by this call (exclusive borrow).data stringio.WriteResult — a value of this type
struct Readerpub struct Reader {
}Bytes Streaming reader and decoder.
This type has no public fields.
struct RuneReadpub struct RuneRead {
pub ch int
pub size int
}Structure encapsulating ch, size.
ch intsize intnew_readerpub fn new_reader(s string) ReaderConstruct reader.
s stringReader — a value of this type
(&Reader) sizepub fn (r &Reader) size() intOperation on &Reader: return the size.
r &ReaderReader instance used by this call (borrow).int — a value of this type
(&Reader) lengthpub fn (r &Reader) length() intOperation on &Reader: return the current length.
r &ReaderReader instance used by this call (borrow).int — a value of this type
($&Reader) resetpub fn (r $&Reader) reset(s string)Operation on $&Reader: clear internal state so the value can be reused.
r $&ReaderReader instance used by this call (exclusive borrow).s stringThis call does not return a value.
($&Reader) read_npub fn (r $&Reader) read_n(n int) stringOperation on $&Reader: read at most n bytes; may return shorter or empty at end.
r $&ReaderReader instance used by this call (exclusive borrow).n intstring — result string
($&Reader) read_bytepub fn (r $&Reader) read_byte() intOperation on $&Reader: read one byte; throws on failure. Throws on failure; handle the error or propagate it to the caller.
r $&ReaderReader instance used by this call (exclusive borrow).int — a value of this type
($&Reader) unread_bytepub fn (r $&Reader) unread_byte() intOperation on $&Reader: unread the last byte. Throws on failure; handle the error or propagate it to the caller.
r $&ReaderReader instance used by this call (exclusive borrow).int — a value of this type
($&Reader) read_runepub fn (r $&Reader) read_rune() RuneReadOperation on $&Reader: read one UTF-8 rune. Throws on failure; handle the error or propagate it to the caller.
r $&ReaderReader instance used by this call (exclusive borrow).RuneRead — a value of this type
($&Reader) unread_runepub fn (r $&Reader) unread_rune() intOperation on $&Reader: unread the last rune. Throws on failure; handle the error or propagate it to the caller.
r $&ReaderReader instance used by this call (exclusive borrow).int — a value of this type
($&Reader) seekpub fn (r $&Reader) seek(offset int, whence int) intOperation on $&Reader: move the read position. whence 0/1/2 = absolute / relative / from end. Throws on failure; handle the error or propagate it to the caller.
r $&ReaderReader instance used by this call (exclusive borrow).offset intwhence intint — a value of this type
($&Reader) read_atpub fn (r $&Reader) read_at(n int, off int) stringOperation on $&Reader: read at most n bytes starting at offset off. Throws on failure; handle the error or propagate it to the caller.
r $&ReaderReader instance used by this call (exclusive borrow).n intoff intstring — result string