Caret lost its meaning
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 88
- Forks
- 50
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 2
Description
Hi!
Is there any way StringScanner could keep ^ meaningful? As it is, it denotes the current the beginning of the rest, but not whether we're at the start of a line.
In the following example, "bar" is not expected to be stripped.
$ cat /tmp/foo.rb
require 'strscan'
def strip(str)
res = +''
s = StringScanner.new(str)
while !s.eos?
res <<
if s.scan(/foo/)
''
elsif s.scan(/^bar/)
''
else
s.scan(/./)
s.matched
end
end
res
end
p strip('foobarbaz')
$ ruby /tmp/foo.rb
"baz"
If there's no way for StringScanner to "fix" the ^ anchor, the documentation should warn about that.
Cheers!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in /tmp/foo.rb and the StringScanner entry point used by require 'strscan'. Determine whether the ^ anchor can preserve line-start semantics during scanning; done means "bar" is not stripped from "foobarbaz", or the StringScanner documentation clearly warns about the current behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100