Skip to content

docs: document array parameter support in std.stripChars/lstripChars/rstripChars#1326

Open
He-Pin wants to merge 1 commit into
google:masterfrom
He-Pin:docs/strip-chars-array-param
Open

docs: document array parameter support in std.stripChars/lstripChars/rstripChars#1326
He-Pin wants to merge 1 commit into
google:masterfrom
He-Pin:docs/strip-chars-array-param

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Document that std.stripChars, std.lstripChars, and std.rstripChars accept an array of single-character strings as the chars parameter
  • Add examples showing array usage for each function

Motivation

The reference implementation in stdlib/std.jsonnet inherently supports arrays because it uses std.member(chars, str[0]), which works with both strings and arrays. This behavior is consistent across all major implementations (cpp-jsonnet, go-jsonnet, sjsonnet, jrsonnet) but is not documented.

When chars is an array:

  • Single-character string elements are used as characters to strip
  • Non-string elements and multi-character strings are silently ignored

Modification

Added a paragraph and example to each of the three function documentation sections in doc/ref/stdlib.html:

  • std.stripChars
  • std.lstripChars
  • std.rstripChars

Result

Users can now discover and rely on the array parameter behavior, which is already supported by all implementations.

Cross-implementation verification

Expression cpp-jsonnet go-jsonnet sjsonnet jrsonnet
std.stripChars("abcba", ["a", "c"]) "bcb" "bcb" "bcb" "bcb"
std.lstripChars("abcba", ["a", "c"]) "bcba" "bcba" "bcba" "bcba"
std.rstripChars("abcba", ["a", "c"]) "abcb" "abcb" "abcb" "abcb"

Closes #1325

@google-cla

google-cla Bot commented Jun 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@He-Pin He-Pin force-pushed the docs/strip-chars-array-param branch from bba70aa to 698bee2 Compare June 18, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document that std.stripChars/lstripChars/rstripChars accept array as chars parameter

1 participant