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

Allow the position range (in str_sub()) to be 0 <= pos <= str->length #151

Open
xSavitar opened this issue Jun 28, 2021 · 0 comments
Open
Labels
TODO It hasn't implemented yet.

Comments

@xSavitar
Copy link
Contributor

xSavitar commented Jun 28, 2021

Followup

Sorry I've missed it in the last review, We should allow the position range to be 0 <= pos <= str->length
when the pos == 0 the user can still get a substring of length zero.

if (pos < 0 || str->length < pos) RET_ERR(...);

The position should be added to the length check, if the length of the substring starting at the pos exceeded the string length it would be an error. (see below)

if (str->length < pos + len) RET_ERR(...);
pos = 5
len = 7
                 v- str->length
"f o o b a r b a z"
           ^-----------^
           pos         pos+len

TODO:
I'm not expecting it from this pr but it's worth mentioning.
Make the length argument as optional to let the users allow get substring starting from pos to the reset of the string.

@ThakeeNathees ThakeeNathees added the TODO It hasn't implemented yet. label Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO It hasn't implemented yet.
Projects
None yet
Development

No branches or pull requests

2 participants