diff options
author | Paul Phillips <paulp@improving.org> | 2010-09-17 00:16:07 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-09-17 00:16:07 +0000 |
commit | 003bd3adee88b177dd18594f03695afe7db21261 (patch) | |
tree | 3f6d23b8cbf59c8561c27792d183371b3d95b933 /src | |
parent | 2976ede075afcce2beded4935abe413abe780fd5 (diff) | |
download | scala-003bd3adee88b177dd18594f03695afe7db21261.tar.gz scala-003bd3adee88b177dd18594f03695afe7db21261.tar.bz2 scala-003bd3adee88b177dd18594f03695afe7db21261.zip |
Modified xCharData to call handle.text on CDATA.
support in MarkupParser to use a Queue instead of a Stream. Contributed
by Jean-Laurent Huynh, reviewed by extempore. Closes #3720.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/xml/parsing/MarkupParser.scala | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/library/scala/xml/parsing/MarkupParser.scala b/src/library/scala/xml/parsing/MarkupParser.scala index 4f6b89c07b..4d9edcee66 100644 --- a/src/library/scala/xml/parsing/MarkupParser.scala +++ b/src/library/scala/xml/parsing/MarkupParser.scala @@ -54,16 +54,32 @@ trait MarkupParser extends MarkupParserCommon with TokenTests // var curInput: Source = input - def lookahead(): BufferedIterator[Char] = new BufferedIterator[Char] { - val stream = curInput.toStream - curInput = Source.fromIterable(stream) - val underlying = Source.fromIterable(stream).buffered - - def hasNext = underlying.hasNext - def next = underlying.next - def head = underlying.head + + // See ticket #3720 for motivations. + private class WithLookAhead(underlying: Source) extends Source { + private val queue = collection.mutable.Queue[Char]() + def lookahead(): BufferedIterator[Char] = { + val iter = queue.iterator ++ new Iterator[Char] { + def hasNext = underlying.hasNext + def next() = { val x = underlying.next(); queue += x; x } + } + iter.buffered + } + val iter = new Iterator[Char] { + def hasNext = underlying.hasNext || !queue.isEmpty + def next() = if (!queue.isEmpty) queue.dequeue() else underlying.next() + } } + def lookahead(): BufferedIterator[Char] = curInput match { + case curInputWLA:WithLookAhead => curInputWLA.lookahead() + case _ => + val newInput = new WithLookAhead(curInput) + curInput = newInput + newInput.lookahead() + } + + /** the handler of the markup, returns this */ private val handle: MarkupHandler = this @@ -326,7 +342,10 @@ trait MarkupParser extends MarkupParserCommon with TokenTests */ def xCharData: NodeSeq = { xToken("[CDATA[") - def mkResult(pos: Int, s: String): NodeSeq = PCData(s) + def mkResult(pos: Int, s: String): NodeSeq = { + handle.text(pos, s) + PCData(s) + } xTakeUntil(mkResult, () => pos, "]]>") } |