yasl
yasl copied to clipboard
Add `max_splits` argument to `str.split`
Currently, str.split
takes two arguments: the string to split, and what to split it on. This CL adds a third argument, max_splits
, that limits the number of times a string can be split.
As an example:
'a b c d'->split(' ') # ['a', 'b', 'c', 'd']
'a b c d'->split(' ', 2) # ['a', 'b', 'c d']
In the first version (which works today), we allow unlimited splits. In the second version (which is what this issue wants to add), we only split the string twice, even though there is a third space in it.
Good day, @CoffeeTableEspresso, I would like to have a shot at this. Please could more description be given?
Sure, updated the description to include an example of what I mean.
For actually making this change, you'll want to look in https://github.com/yasl-lang/yasl/blob/master/interpreter/str_methods.c
, and change the str_split
function.
Let me know if anything is unclear in the code itself, I know it's not always particularly well documented.
And, you'll need to change the entry for str_split
on line 77 of https://github.com/yasl-lang/yasl/blob/master/interpreter/builtins.c
. It should take 3 parameters instead of 2.
Ok, let me give it a shot.
Done