Help us shape the future of Go! Take the 2026 Go Developer Survey

stringsmod

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package stringsmod is the native module "strings": a Builder class that builds a long string from many pieces.

use strings;
local b = new strings::Builder();
for (local i = 0; i < 3; i++) b->add(i, ",");
println(b->str());          // 0,1,2,

Index

Constants

This section is empty.

Variables

View Source
var Builder = &native.Class{
	Name: "Builder",

	New: func(env value.Env, this *value.ObjectObj, args []value.Value) (value.Value, error) {
		a, err := native.Check("strings::Builder::Builder", args, 0, 1)
		if err != nil {
			return value.NilValue, err
		}
		b := &strings.Builder{}
		if a.Has(0) {
			s, err := a.String(0)
			if err != nil {
				return value.NilValue, err
			}
			b.WriteString(s)
		}
		this.State = b
		return value.NilValue, nil
	},
	Methods: map[string]value.NativeMethod{

		"add": func(env value.Env, this *value.ObjectObj, args []value.Value) (value.Value, error) {
			b := this.State.(*strings.Builder)
			for _, v := range args {
				b.WriteString(v.String())
			}
			return value.ObjectValue(this), nil
		},

		"len": func(env value.Env, this *value.ObjectObj, args []value.Value) (value.Value, error) {
			if _, err := native.Check("strings::Builder::len", args, 0, 0); err != nil {
				return value.NilValue, err
			}
			return value.MakeInt(int64(this.State.(*strings.Builder).Len())), nil
		},

		"str": func(env value.Env, this *value.ObjectObj, args []value.Value) (value.Value, error) {
			if _, err := native.Check("strings::Builder::str", args, 0, 0); err != nil {
				return value.NilValue, err
			}
			return value.MakeString(this.State.(*strings.Builder).String()), nil
		},

		"reset": func(env value.Env, this *value.ObjectObj, args []value.Value) (value.Value, error) {
			if _, err := native.Check("strings::Builder::reset", args, 0, 0); err != nil {
				return value.NilValue, err
			}
			this.State.(*strings.Builder).Reset()
			return value.ObjectValue(this), nil
		},
	},
	Show: func(o *value.ObjectObj) string {
		return fmt.Sprintf("strings::Builder(%d bytes)", o.State.(*strings.Builder).Len())
	},
}

Builder is the class strings::Builder.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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