From 39fbdc73ae618f1e2cd5e03c7949e7b669ff0fef Mon Sep 17 00:00:00 2001 From: michelou Date: Mon, 11 Jun 2007 12:22:17 +0000 Subject: minor changes --- .../scala/xml/parsing/ExternalSources.scala | 76 ++++++++++++---------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/src/library/scala/xml/parsing/ExternalSources.scala b/src/library/scala/xml/parsing/ExternalSources.scala index c9893beaa6..cbfee413e6 100644 --- a/src/library/scala/xml/parsing/ExternalSources.scala +++ b/src/library/scala/xml/parsing/ExternalSources.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -9,70 +9,74 @@ // $Id$ -package scala.xml.parsing; +package scala.xml.parsing -import compat.StringBuilder -import scala.io.Source; -import java.net.URL; +import java.net.URL +import scala.io.Source + +/** + * @author Burak Emir + * @version 1.0 + */ trait ExternalSources { self: ExternalSources with MarkupParser with MarkupHandler => - private def externalSourceFromURL(url:URL): Source = { - import java.io.{BufferedReader, InputStreamReader}; + private def externalSourceFromURL(url: URL): Source = { + import java.io.{BufferedReader, InputStreamReader} val in = new BufferedReader( new InputStreamReader( - url.openStream())); + url.openStream())) //@todo: replace this hack with proper Source implementation - val str = new StringBuilder(); - var inputLine:String = null; + val str = new StringBuilder() + var inputLine: String = null //while (inputLine = in.readLine()) != null) { while ({inputLine = in.readLine(); inputLine} ne null) { - // Console.println(inputLine); // DEBUG - str.append(inputLine); - str.append('\n'); // readable output + // Console.println(inputLine) // DEBUG + str.append(inputLine) + str.append('\n') // readable output } - in.close(); + in.close() class MyClass extends Source { def newIter = new Iterator[Char] { - var i = -1; - private val len = str.length-1; - def hasNext = i < len; - def next = { - i = i + 1; - str.charAt(i); - } + var i = -1 + private val len = str.length-1 + def hasNext = i < len + def next = { i += 1; str.charAt(i) } } - val iter = newIter; + val iter = newIter - def reset: Source = new MyClass; + def reset: Source = new MyClass - /*override var*/ descr = url.toExternalForm(); + /*override var*/ descr = url.toExternalForm() } - return new MyClass; + new MyClass } + /** ... + * + * @param systemId ... + * @return ... + */ def externalSource(systemId: String): Source = { - //Console.println("in external source("+systemId+")"); - if(systemId.startsWith("http:")) { - return externalSourceFromURL(new URL(systemId)); - } + if (systemId startsWith "http:") + return externalSourceFromURL(new URL(systemId)) - var fileStr = input.descr; + var fileStr = input.descr - if(input.descr.startsWith("file:")) { - fileStr = input.descr.substring(5, input.descr.length); + if (input.descr startsWith "file:") { + fileStr = input.descr.substring(5, input.descr.length) } else - fileStr = fileStr.substring(0, - fileStr.lastIndexOf(java.io.File.separator)+1); - Source.fromFile(fileStr + systemId); + fileStr = fileStr.substring(0, + fileStr.lastIndexOf(java.io.File.separator)+1) + Source.fromFile(fileStr + systemId) } } -- cgit v1.2.3