Closed
Conversation
Contributor
Author
|
Consider merging similar proposal from the Python repository. |
Contributor
Author
|
Consider studying this discussion which might be relevant. |
Contributor
Author
|
If we were to add string manipulation functions, would that be good to at least specify a first reasonable batch, instead of one function at a time? I’m think about:
I specifically do not think we would need a However, this contradicts one of the tenets of JMESPath which is to drive changes from real-world scenarios. |
Contributor
Author
|
Closed in favor of corresponding discussion |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
String Manipulation (GorillaStack)
Abstract
This document proposes expanding the list of available string manipulation
functions in the spec.
Motivation
The specification only contains basic string search and manipulation functions,
such as starts_with() and contains(), which are insufficient for other use
cases, such as replacing parts of strings, splitting strings, using regular expressions
for searching or manipulation of strings, or other common string manipulations
found in the common libraries of mainstream languages such as Python or JavaScript.
Specification
The following functions will be added to the specification:
split
Given string
$subject, split will split on occurrences string$split_str, up to and including$max times (if specified).
The result is an array containing each partial string between occurrences of
$split_str. If thestring contains no occurrences of $split_str, an array containing just the original
$subjectstring will be returned.
$maxis a optional parameter. When specified as an integer greater than zero, it will split thestring up to
($max - 1)times, with the last string in the array containing the remainingcontents of
$subjectunmodified.If not specified or it is less than zero, the string will be split on every occurrence of
$split_str.When
$maxis equal to zero, it will behave as if the string is not split at all, and returnan array containing one element, the original string.
Examples
split('average|-|min|-|max|-|mean|-|mode|-|median', '|-|')["average", "min", "max", "mean", "mode", "median"]split('average|-|min|-|max|-|mean|-|mode|-|median', '|-|', 3)["average", "min", "max|-|mean|-|mode|-|median"]split('average|-|min|-|max|-|mean|-|mode|-|median', '-')["average|", "|min|", "|max|", "|mean|", "|mode|", "|median"]split('average|-|min|-|max|-|mean|-|mode|-|median', '|-|', 0)["average|-|min|-|max|-|mean|-|mode|-|median"]split('every character', '')["e", "v", "e", "r", "y", " ", "c", "h", "a", "r", "a", "c", "t", "e", "r"]Impact
There should be no impact to existing users, as these are new functions.