Skip to content

go/constant: add StringLen function #79042

@griesemer

Description

@griesemer

The proposal is to add the following function to the go/constant package:

// StringLen returns the length of x if x is a [String].
// If x is [Unknown], the result is 0.
// In all other cases, the function panics.
func StringLen(x Value) int64

This allows the determination of the length of a String value w/o having to call StringVal.
(StringVal causes the construction and thus allocation of a new single string if the actual string value was created via addition of many substrings.)

Metadata

Metadata

Assignees

Labels

LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposalProposal-Accepted

Projects

Status

Todo

Status

Accepted

Relationships

None yet

Development

No branches or pull requests

Issue actions