Skip to content
This repository has been archived by the owner on Oct 16, 2022. It is now read-only.

Inconsistency between sub and gsub #11

Open
prfss opened this issue Dec 27, 2016 · 2 comments
Open

Inconsistency between sub and gsub #11

prfss opened this issue Dec 27, 2016 · 2 comments

Comments

@prfss
Copy link

prfss commented Dec 27, 2016

I'm not sure if this is a bug.

Passing an empty string as the third argument, sub returns the replacement string.

λ> sub [re|^$|] "replacement" ""
"replacement"
λ> sub [re|.*|] "replacement" ""
"replacement"

But gsub returns an empty string for the same input.

λ> gsub [re|^$|] "replacement" ""
""
λ> gsub [re|.*|] "replacement" ""
""
@valpackett
Copy link
Owner

That does look strange indeed… any idea why it could happen?

@prfss
Copy link
Author

prfss commented Dec 27, 2016

Please forgive my poor English...

The immediate cause is the gusb0.loop's first guard (offset >= l). offset and l are both 0.
However, without the guard gsub0 loops forever because any string has empty substring at its right end that matches the regex.

I think that the root of the problem is that gsub0 cannot determine whether the empty string is consumed or not from the value of offset.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants