Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string sub --end #6765

Merged
merged 2 commits into from Mar 22, 2020
Merged

Add string sub --end #6765

merged 2 commits into from Mar 22, 2020

Conversation

gechr
Copy link
Contributor

@gechr gechr commented Mar 18, 2020

Closes #5974

Add a new e/--end option to allow specifying the end of the substring. Supports positive/negative indices, using Python's string slicing as a reference behaviour. Made --length mutually exclusive with --end as specifying both doesn't really make sense.

See docs/tests for examples.

@krobelus
Copy link
Member

Looks good as far as I'm concerned. I wonder if it makes sense to support the combination of --length and --end (not all three), even though it's weird. It could save the user a tiny bit of arithmetic in very rare cases.

@gechr
Copy link
Contributor Author

gechr commented Mar 22, 2020

@krobelus Happy to make --length and --end work together, but would you expect the output of:

$ string sub --end -1 --length 2 0123456789

to be 01 or 78? That is, should it take characters from the left or right of the string if --end is specified?

@krobelus krobelus merged commit a343611 into fish-shell:master Mar 22, 2020
@krobelus
Copy link
Member

I'd expect 78 here, but now I see that it is super ambiguous, so let's leave it off for now.
Merged, thanks!

@krobelus krobelus added this to the fish 3.2.0 milestone Mar 22, 2020
@gechr gechr deleted the gc-string-sub-end branch March 22, 2020 14:55
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add string sub --end
2 participants