Following on from https://groups.google.com/d/msg/scala-language/scz8c2rCWe0/ikAXBg_01kwJ ...
The findAllIn method of scala.util.matching.Regex [1] returns a MatchIterator [2] whose implementation is backed by a java.util.regex.Matcher [3, 4]. The latter is documented as throwing an IllegalStateException if queried before a match has been attempted. This behaviour carries through the MatchIterator, but is not documented:
// 2.11.0-M7 REPLscala> val hello = "hello world"hello: String = hello world
// declaring mi here prevents the REPL from calling toString on itscala> println({ val mi = " ".r.findAllIn(hello); mi.start })java.lang.IllegalStateException: No match availableat java.util.regex.Matcher.start(Matcher.java:342)at scala.util.matching.Regex$MatchIterator.start(Regex.scala:661)... 32 elided
scala> println({ val mi = " ".r.findAllIn(hello); mi.hasNext; mi.start })5
Is this a bug, incomplete documentation or Just Something You Have To Know?
A cursory search didn't turn up anything in JIRA. SI-2460 is related, but doesn't address this case directly.
Thanks!
ap
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Alas, I have a long story of love and hate towards Scala's Regex. It gives a glimpse of paradise but fails to follow through. If I had settled on a good API, I'd have made a replacement library by now.
scala> js.iterator.remove
java.lang.IllegalStateException
at java.util.ArrayList$Itr.remove(ArrayList.java:804)
... 32 elided
a special scala.collection.Iterator that returns the matched strings, but can also be converted into a normal iterator that returns objects of type scala.util.matching.Regex.Match that can be queried for data such as the text that precedes the match, subgroups, etc.
--
- Throws:
- IllegalStateException - if neither
next
norprevious
have been called, orremove
oradd
have been called after the last call tonext
orprevious
"Regular Exasperations"
--