diff options
author | michelou <michelou@epfl.ch> | 2006-09-22 09:38:30 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2006-09-22 09:38:30 +0000 |
commit | 427c400d0ef5db083638c698280e8d16e8e1c100 (patch) | |
tree | bbcf6b1be3aa45077f29a2e7bd93aca1cdd6f10e /src | |
parent | 920e6a2e5ab9834e0a034199960201d40569e011 (diff) | |
download | scala-427c400d0ef5db083638c698280e8d16e8e1c100.tar.gz scala-427c400d0ef5db083638c698280e8d16e8e1c100.tar.bz2 scala-427c400d0ef5db083638c698280e8d16e8e1c100.zip |
removed leading/trailing tabs/blanks in scala/x...
removed leading/trailing tabs/blanks in scala/xml/*.scala
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/io/Source.scala | 90 | ||||
-rw-r--r-- | src/library/scala/util/regexp/WordExp.scala | 8 | ||||
-rw-r--r-- | src/library/scala/xml/Comment.scala | 23 | ||||
-rw-r--r-- | src/library/scala/xml/Document.scala | 76 | ||||
-rw-r--r-- | src/library/scala/xml/EntityRef.scala | 35 | ||||
-rw-r--r-- | src/library/scala/xml/MalformedAttributeException.scala | 4 | ||||
-rw-r--r-- | src/library/scala/xml/NodeBuffer.scala | 21 | ||||
-rw-r--r-- | src/library/scala/xml/XML.scala | 140 |
8 files changed, 243 insertions, 154 deletions
diff --git a/src/library/scala/io/Source.scala b/src/library/scala/io/Source.scala index d0e7faf2bd..265d163613 100644 --- a/src/library/scala/io/Source.scala +++ b/src/library/scala/io/Source.scala @@ -11,23 +11,27 @@ package scala.io -import scala.runtime.compat.StringBuilder; -import java.io.{ File, FileInputStream, PrintStream }; +import java.io.{File, FileInputStream, PrintStream} -/** convenience methods to create an iterable representation of a source - * file. +import scala.runtime.compat.StringBuilder + +/** This object provides convenience methods to create an iterable + * representation of a source file. * * @author Burak Emir * @version 1.0, 19/08/2004 */ object Source { - /** creates Source from array of bytes, with empty description + /** Creates Source from array of bytes, with empty description. + * + * @param bytes ... + * @return ... */ def fromBytes(bytes: Array[Byte]): Source = fromString(new String(bytes)) - /** creates Source from array of bytes with given encoding, with + /** Creates Source from array of bytes with given encoding, with * empty description. * * @param bytes ... @@ -37,7 +41,11 @@ object Source { def fromBytes(bytes: Array[Byte], enc: String): Source = fromString(new String(bytes, enc)) - /** creates Source from a single char */ + /** Creates Source from a single character. + * + * @param c ... + * @return ... + */ def fromChar(c: Char): Source = { val it = Iterator.single(c) new Source { @@ -45,7 +53,11 @@ object Source { val iter = it } } - /** creates Source from array of characters, with empty description + + /** creates Source from array of characters, with empty description. + * + * @param chars ... + * @return ... */ def fromChars(chars: Array[Char]): Source = { val it = Iterator.fromArray(chars) @@ -54,7 +66,11 @@ object Source { val iter = it } } - /** creates Source from string, with empty description + + /** creates Source from string, with empty description. + * + * @param s ... + * @return ... */ def fromString(s: String): Source = { val it = Iterator.fromString(s) @@ -92,8 +108,12 @@ object Source { return setFileDescriptor(file, s) } - /** creates Source from file, using given character encoding, setting its + /** Creates Source from file, using given character encoding, setting its * description to filename. + * + * @param file ... + * @param enc ... + * @return ... */ def fromFile(file: java.io.File, enc: String): Source = { val arr: Array[Byte] = new Array[Byte](file.length().asInstanceOf[Int]) @@ -104,8 +124,13 @@ object Source { return setFileDescriptor(file, s) } + /** + * @param file ... + * @param s ... + * @return ... + */ def setFileDescriptor(file: File, s: Source): Source = { - s.descr = new StringBuilder().append( "file:" ).append( file.getAbsolutePath() ).toString(); + s.descr = new StringBuilder().append( "file:" ).append(file.getAbsolutePath()).toString(); s } @@ -134,11 +159,11 @@ object Source { /** an iterable representation of source files. * calling method reset returns an identical, resetted source * - * @author buraq + * @author Burak Emir + * @version 1.0 */ abstract class Source extends Iterator[Char] { - // ------ protected values /** the actual iterator */ @@ -189,7 +214,7 @@ abstract class Source extends Iterator[Char] { ); var ch = it.next - while(it.hasNext && '\n' != ch) { + while (it.hasNext && '\n' != ch) { buf.append(ch) ch = it.next } @@ -219,32 +244,57 @@ abstract class Source extends Iterator[Char] { ch } - /** reports an error message to console */ + /** reports an error message to console. + * + * @param pos ... + * @param msg the error message to report + */ def reportError(pos: Int, msg: String): Unit = report(pos, msg, java.lang.System.out) + /** + * @param pos ... + * @param msg the error message to report + * @param out ... + */ def reportError(pos: Int, msg: String, out: PrintStream): Unit = { nerrors = nerrors + 1 report(pos, msg, java.lang.System.out) } + /** + * @param pos ... + * @param msg the error message to report + * @param out ... + */ def report(pos: Int, msg: String, out: PrintStream): Unit = { + val buf = new StringBuffer val line = Position.line(pos) val col = Position.column(pos) - Console.println(descr+":"+line+":"+col+": "+msg) - Console.println(getLine(line)) + buf.append(descr + ":"+line+":"+col+": "+msg) + buf.append(getLine(line)) var i = 1 while (i < col) { - Console.print(' ') + buf.append(' ') i = i + 1 } - Console.println('^') + buf.append('^') + out.println(buf.toString) } - /** reports a warning message to java.lang.System.out */ + /** Reports a warning message to <code>java.lang.System.out</code>. + * + * @param pos ... + * @param msg the warning message to report + */ def reportWarning(pos: Int, msg: String): Unit = reportWarning(pos, msg, java.lang.System.out) + /** + * @param pos ... + * @param msg the warning message to report + * @param out ... + */ def reportWarning(pos: Int, msg: String, out: PrintStream): Unit = { nwarnings = nwarnings + 1 report(pos, "warning! "+msg, out) diff --git a/src/library/scala/util/regexp/WordExp.scala b/src/library/scala/util/regexp/WordExp.scala index 68457a622d..e2111e3d27 100644 --- a/src/library/scala/util/regexp/WordExp.scala +++ b/src/library/scala/util/regexp/WordExp.scala @@ -11,8 +11,9 @@ package scala.util.regexp -/** regular word expressions. users have to instantiate type member - * _regexpT <: RegExp (from Base) and a type member _labelT <: Label +/** This class provides regular word expressions. Users have to instantiate + * type member <code>_regexpT <: RegExp</code< (from class <code>Base</code>) + * and a type member <code>_labelT <: Label</code>. * Here is a little example: * <pre> import scala.util.regexp._ @@ -31,6 +32,9 @@ package scala.util.regexp } val nfa = MyBerriSethi.automatonFrom(Sequ(rex),1) * </pre> + * + * @author Burak Emir + * @version 1.0 */ abstract class WordExp extends Base { diff --git a/src/library/scala/xml/Comment.scala b/src/library/scala/xml/Comment.scala index 312a3f2b3d..01a1a75544 100644 --- a/src/library/scala/xml/Comment.scala +++ b/src/library/scala/xml/Comment.scala @@ -9,9 +9,9 @@ // $Id$ -package scala.xml; +package scala.xml -import scala.runtime.compat.StringBuilder; +import scala.runtime.compat.StringBuilder /** an XML node for comments. * @@ -21,27 +21,26 @@ import scala.runtime.compat.StringBuilder; case class Comment(commentText: String) extends SpecialNode { - final override def typeTag$:Int = -3; + final override def typeTag$:Int = -3 - if( commentText.indexOf("--" ) != -1 ) - throw new IllegalArgumentException("text containts \"--\""); + if (commentText.indexOf("--") != -1) + throw new IllegalArgumentException("text containts \"--\"") /** structural equality */ override def equals(x: Any): Boolean = x match { - case Comment(x) => x.equals(commentText); - case _ => false + case Comment(x) => x.equals(commentText) + case _ => false } /** the constant "#REM" */ - def label = "#REM"; + def label = "#REM" /** hashcode for this Comment */ - override def hashCode() = commentText.hashCode(); + override def hashCode() = commentText.hashCode() - override def text = ""; + override def text = "" /** appends "<!-- text -->" to this stringbuffer */ - def toString(sb: StringBuilder) = { + def toString(sb: StringBuilder) = sb.append("<!--").append(commentText).append("-->") - } } diff --git a/src/library/scala/xml/Document.scala b/src/library/scala/xml/Document.scala index ec0b5e2a3c..8935e0bce4 100644 --- a/src/library/scala/xml/Document.scala +++ b/src/library/scala/xml/Document.scala @@ -9,79 +9,81 @@ // $Id$ -package scala.xml; - +package scala.xml /** A document information item (according to InfoSet spec). The comments * are copied from the Infoset spec, only augmented with some information * on the Scala types for definitions that might have no value. - * also plays the role of an XMLEvent for pull parsing + * also plays the role of an <code>XMLEvent</code> for pull parsing + * + * @author Burak Emir + * @version 1.0, 26/04/2005 */ class Document extends NodeSeq with pull.XMLEvent { /** An ordered list of child information items, in document - * order. The list contains exactly one element information item. The - * list also contains one processing instruction information item for - * each processing instruction outside the document element, and one - * comment information item for each comment outside the document - * element. Processing instructions and comments within the DTD are - * excluded. If there is a document type declaration, the list also - * contains a document type declaration information item. - */ - var children: Seq[Node] = _; + * order. The list contains exactly one element information item. The + * list also contains one processing instruction information item for + * each processing instruction outside the document element, and one + * comment information item for each comment outside the document + * element. Processing instructions and comments within the DTD are + * excluded. If there is a document type declaration, the list also + * contains a document type declaration information item. + */ + var children: Seq[Node] = _ /** The element information item corresponding to the document element. */ - var docElem: Node = _; + var docElem: Node = _ /** The dtd that comes with the document, if any */ - var dtd: scala.xml.dtd.DTD = _; + var docDTD: dtd.DTD = _ /** An unordered set of notation information items, one for each notation - * declared in the DTD. If any notation is multiply declared, this property - * has no value. + * declared in the DTD. If any notation is multiply declared, this property + * has no value. */ - def notations: Seq[scala.xml.dtd.NotationDecl] = - dtd.notations; + def notations: Seq[dtd.NotationDecl] = + docDTD.notations /** An unordered set of unparsed entity information items, one for each * unparsed entity declared in the DTD. */ - def unparsedEntities: Seq[scala.xml.dtd.EntityDecl] = - dtd.unparsedEntities; + def unparsedEntities: Seq[dtd.EntityDecl] = + docDTD.unparsedEntities /** The base URI of the document entity. */ - var baseURI: String = _; + var baseURI: String = _ /** The name of the character encoding scheme in which the document entity * is expressed. */ - var encoding: Option[String] = _; + var encoding: Option[String] = _ /** An indication of the standalone status of the document, either - * true or false. This property is derived from the optional standalone - * document declaration in the XML declaration at the beginning of the - * document entity, and has no value (None) if there is no standalone - * document declaration. + * true or false. This property is derived from the optional standalone + * document declaration in the XML declaration at the beginning of the + * document entity, and has no value (<code>None</code>) if there is no + * standalone document declaration. */ - var standAlone: Option[Boolean] = _; + var standAlone: Option[Boolean] = _ /** A string representing the XML version of the document. This - * property is derived from the XML declaration optionally present at - * the beginning of the document entity, and has no value (None) if there is - * no XML declaration. + * property is derived from the XML declaration optionally present at + * the beginning of the document entity, and has no value (<code>None</code>) + * if there is no XML declaration. */ - var version: Option[String] = _; + var version: Option[String] = _ /** 9. This property is not strictly speaking part of the infoset of - * the document. Rather it is an indication of whether the processor - * has read the complete DTD. Its value is a boolean. If it is false, - * then certain properties (indicated in their descriptions below) may - * be unknown. If it is true, those properties are never unknown. + * the document. Rather it is an indication of whether the processor + * has read the complete DTD. Its value is a boolean. If it is false, + * then certain properties (indicated in their descriptions below) may + * be unknown. If it is true, those properties are never unknown. */ - var allDeclarationsProcessed = false; + var allDeclarationsProcessed = false // methods for NodeSeq - def theSeq: Seq[Node] = this.docElem ; + def theSeq: Seq[Node] = this.docElem } diff --git a/src/library/scala/xml/EntityRef.scala b/src/library/scala/xml/EntityRef.scala index a3c4876068..c7ae5a536e 100644 --- a/src/library/scala/xml/EntityRef.scala +++ b/src/library/scala/xml/EntityRef.scala @@ -9,42 +9,43 @@ // $Id$ -package scala.xml; +package scala.xml import scala.runtime.compat.StringBuilder /** an XML node for entity references * - * @author buraq - * @param text the text contained in this node - **/ - + * @author Burak Emir + * @version 1.0 + * @param text the text contained in this node + */ case class EntityRef(entityName: String) extends SpecialNode { - final override def typeTag$:Int = -5; + final override def typeTag$: Int = -5 /** structural equality */ override def equals(x: Any): Boolean = x match { - case EntityRef(x) => x.equals(entityName); + case EntityRef(x) => x.equals(entityName) case _ => false } /** the constant "#ENTITY" */ - def label = "#ENTITY"; + def label = "#ENTITY" - override def hashCode() = entityName.hashCode(); + override def hashCode() = entityName.hashCode() override def text = entityName match { - case "lt" => "<"; - case "gt" => ">"; - case "amp" => "&"; - case "apos" => "'"; - case "quot" => "\""; - case _ => val sb=new StringBuilder();toString(sb).toString() + case "lt" => "<" + case "gt" => ">" + case "amp" => "&" + case "apos" => "'" + case "quot" => "\"" + case _ => val sb = new StringBuilder(); toString(sb).toString() } + /** appends "& entityName;" to this stringbuffer */ - def toString(sb:StringBuilder) = - sb.append("&").append(entityName).append(";"); + def toString(sb: StringBuilder) = + sb.append("&").append(entityName).append(";") } diff --git a/src/library/scala/xml/MalformedAttributeException.scala b/src/library/scala/xml/MalformedAttributeException.scala index 5d85c88315..0437006583 100644 --- a/src/library/scala/xml/MalformedAttributeException.scala +++ b/src/library/scala/xml/MalformedAttributeException.scala @@ -9,7 +9,7 @@ // $Id$ -package scala.xml; +package scala.xml -case class MalformedAttributeException(msg:String) extends java.lang.RuntimeException(msg); +case class MalformedAttributeException(msg: String) extends java.lang.RuntimeException(msg) diff --git a/src/library/scala/xml/NodeBuffer.scala b/src/library/scala/xml/NodeBuffer.scala index a4128e0421..151d27c9a0 100644 --- a/src/library/scala/xml/NodeBuffer.scala +++ b/src/library/scala/xml/NodeBuffer.scala @@ -9,8 +9,7 @@ // $Id$ -package scala.xml; - +package scala.xml /** * This class acts as a Buffer for nodes. If it is used as a sequence @@ -20,6 +19,9 @@ package scala.xml; * * Despite this being a sequence, don't use it as key in a hashtable. * Calling the hashcode function will result in a runtime error. + * + * @author Burak Emir + * @version 1.0 */ class NodeBuffer extends scala.collection.mutable.ArrayBuffer[Node] { @@ -33,20 +35,23 @@ class NodeBuffer extends scala.collection.mutable.ArrayBuffer[Node] { * Append given string as a <code>scala.xml.Text</code> node to this * buffer, returns reference on this NodeBuffer for convenience. * - * @param n + * @param o ... + * @return ... */ def &+(o: Any): NodeBuffer = { o match { - case n:Node => super.+(n); + case n:Node => + super.+(n) case ns:Iterable[AnyRef] => - val it = ns.elements; - while(it.hasNext) { - this &+ it.next; + val it = ns.elements + while (it.hasNext) { + this &+ it.next //if (it.hasNext) // this &+ " "; } //case s:String => super.+(Text(o.toString())); - case d => super.+(new Atom(d)); + case d => + super.+(new Atom(d)) } this } diff --git a/src/library/scala/xml/XML.scala b/src/library/scala/xml/XML.scala index 2291fa70cc..35a384e892 100644 --- a/src/library/scala/xml/XML.scala +++ b/src/library/scala/xml/XML.scala @@ -9,84 +9,111 @@ // $Id$ -package scala.xml; +package scala.xml import Predef._ -import scala.xml.parsing.NoBindingFactoryAdapter ; -import org.xml.sax.InputSource; - -/** constants, and functions to load and save XML elements. use this when data binding is not -** desired, i.e. when XML is handled using Symbol nodes -**/ +import scala.xml.parsing.NoBindingFactoryAdapter +import org.xml.sax.InputSource + +/** The object <code>XML</code> provides constants, and functions to load + * and save XML elements. Use this when data binding is not desired, i.e. + * when XML is handled using <code>Symbol</code> nodes. + * + * @author Burak Emir + * @version 1.0, 25/04/2005 + */ object XML { val xml = "xml" val xmlns = "xmlns" val namespace = "http://www.w3.org/XML/1998/namespace" - val preserve = "preserve"; - val space = "space"; - val lang = "lang"; + val preserve = "preserve" + val space = "space" + val lang = "lang" - import java.io._ ; + import java.io._ // functions for generic xml loading, saving /** loads XML from given file, using XML parser in JDK. */ - final def loadFile(file: File): scala.xml.Elem = - new NoBindingFactoryAdapter().loadXML( new InputSource( - new FileInputStream( file ) - )); - - /** loads XML from given file descriptor, using XML parser in JDK. */ - final def loadFile(fileDesc: FileDescriptor): scala.xml.Elem = - new NoBindingFactoryAdapter().loadXML( new InputSource( - new FileInputStream( fileDesc ) - )); + final def loadFile(file: File): Elem = + new NoBindingFactoryAdapter().loadXML(new InputSource( + new FileInputStream(file) + )) + + /** loads XML from given file descriptor, using XML parser in JDK. + * + * @param fileDesc ... + * @return ... + */ + final def loadFile(fileDesc: FileDescriptor): Elem = + new NoBindingFactoryAdapter().loadXML(new InputSource( + new FileInputStream(fileDesc) + )) /** loads XML from given file, using XML parser in JDK. */ - final def loadFile(fileName: String): scala.xml.Elem = - new NoBindingFactoryAdapter().loadXML( new InputSource( - new FileInputStream( fileName ) + final def loadFile(fileName: String): Elem = + new NoBindingFactoryAdapter().loadXML(new InputSource( + new FileInputStream(fileName) )); /** loads XML from given InputStream, using XML parser in JDK. */ - final def load( is:InputStream ): scala.xml.Elem = - new NoBindingFactoryAdapter().loadXML( new InputSource( is )); + final def load( is:InputStream ): Elem = + new NoBindingFactoryAdapter().loadXML(new InputSource(is)) /** loads XML from given Reader, using XML parser in JDK. */ - final def load(reader: Reader): scala.xml.Elem = - new NoBindingFactoryAdapter().loadXML( new InputSource( reader )); + final def load(reader: Reader): Elem = + new NoBindingFactoryAdapter().loadXML(new InputSource(reader)) /** loads XML from given sysID, using XML parser in JDK. */ - final def load(sysID: String): scala.xml.Elem = - new NoBindingFactoryAdapter().loadXML( new InputSource( sysID )); + final def load(sysID: String): Elem = + new NoBindingFactoryAdapter().loadXML(new InputSource(sysID)) - /** loads XML from a given input source, using XML parser in JDK. */ - final def load(source: InputSource): scala.xml.Elem = - new NoBindingFactoryAdapter().loadXML( source ); + /** loads XML from a given input source, using XML parser in JDK. + * + * @param source ... + * @return ... + */ + final def load(source: InputSource): Elem = + new NoBindingFactoryAdapter().loadXML(source) /** loads XML from a string, using XML parser in JDK. */ - final def loadString( string:String ): scala.xml.Elem = + final def loadString(string: String): Elem = load(new StringReader(string)) - /** saves XML to filename with encoding ISO-8859-1 without xml-decl without doctype. */ + /** Saves XML to filename with encoding ISO-8859-1 without xml-decl without + * <code>doctype</code>. + * + * @param filename ... + * @param node ... + */ final def save(filename: String, node: Node): Unit = - save(filename, node, "ISO-8859-1"); - - /** saves XML to filename with given encoding, without xml-decl without doctype. */ + save(filename, node, "ISO-8859-1") + + /** saves XML to filename with given encoding, without xml-decl without + * <code>doctype</code>. + * + * @param filename ... + * @param node ... + * @param enc ... + */ final def save(filename: String, node: Node, enc: String): Unit = saveFull(filename, node, enc, false, null); - /** saves a node to a file with given filename using encoding iso-8859-1 optionally with xmldecl and doctype declaration + /** saves a node to a file with given filename using encoding iso-8859-1 + * optionally with xmldecl and doctype declaration. + * * @param filename the filename * @param node the xml node we want to write * @param xmlDecl if true, write xml declaration * @param doctype if not null, write doctype declaration */ final def saveFull(filename: String, node: Node, xmlDecl: Boolean, doctype: dtd.DocType): Unit = - saveFull(filename, node, "ISO-8859-1", xmlDecl, doctype); + saveFull(filename, node, "ISO-8859-1", xmlDecl, doctype) - /** saves a node to a file with given filename using given encoding optionally with xmldecl and doctype declaration. + /** Saves a node to a file with given filename using given encoding + * optionally with xmldecl and doctype declaration. + * * @param filename the filename * @param node the xml node we want to write * @param enc encoding to use @@ -95,34 +122,35 @@ object XML { */ final def saveFull(filename: String, node: Node, enc: String, xmlDecl: Boolean, doctype: dtd.DocType): Unit = { - var fos: FileOutputStream = null; - var w: Writer = null; + var fos: FileOutputStream = null + var w: Writer = null try { - /* using NIO classes of JDK 1.4 */ - import java.io.{FileOutputStream,Writer}; - import java.nio.channels.{Channels,FileChannel}; + // using NIO classes of JDK 1.4 + import java.io.{FileOutputStream, Writer} + import java.nio.channels.{Channels, FileChannel} - fos = new FileOutputStream( filename ) - w = Channels.newWriter( fos.getChannel(), enc ) + fos = new FileOutputStream(filename) + w = Channels.newWriter(fos.getChannel(), enc) write(w, node, enc, xmlDecl, doctype) } finally { - w.close(); - fos.close(); + w.close() + fos.close() } } - /** writes the given node using writer, optionally with xml decl and doctype. + /** Writes the given node using writer, optionally with xml decl and doctype. * It's the caller's responsibility to close the writer. + * * @param w the writer * @param node the xml node we want to write - * @param enc the string to be used in xmlDecl + * @param enc the string to be used in <code>xmlDecl</code> * @param xmlDecl if true, write xml declaration * @param doctype if not null, write doctype declaration */ final def write(w: java.io.Writer, node: Node, enc: String, xmlDecl: Boolean, doctype: dtd.DocType): Unit = { - /* 2do: optimize by giving writer parameter to toXML*/ - if(xmlDecl) w.write( "<?xml version='1.0' encoding='"+enc+"'?>\n"); - if(doctype!=null) w.write( doctype.toString()+"\n"); - w.write( Utility.toXML( node )); + /* TODO: optimize by giving writer parameter to toXML*/ + if (xmlDecl) w.write("<?xml version='1.0' encoding='" + enc + "'?>\n") + if (doctype != null) w.write( doctype.toString() + "\n") + w.write(Utility.toXML(node)) } } |