diff options
author | buraq <buraq@epfl.ch> | 2004-03-15 10:57:12 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2004-03-15 10:57:12 +0000 |
commit | 4f00279941b99694b510a244aeda2649bd166c0a (patch) | |
tree | 9d3c5f1e2c4de537ea4016cd511a8a80dfde5d28 /sources/scala | |
parent | f56e421f4f5e674d99f6940a68553f04d94ec521 (diff) | |
download | scala-4f00279941b99694b510a244aeda2649bd166c0a.tar.gz scala-4f00279941b99694b510a244aeda2649bd166c0a.tar.bz2 scala-4f00279941b99694b510a244aeda2649bd166c0a.zip |
impl
Diffstat (limited to 'sources/scala')
-rw-r--r-- | sources/scala/Similarity.scala | 3 | ||||
-rw-r--r-- | sources/scala/xml/NodeSeq.scala | 39 |
2 files changed, 35 insertions, 7 deletions
diff --git a/sources/scala/Similarity.scala b/sources/scala/Similarity.scala index cb41be7f72..68a865ed96 100644 --- a/sources/scala/Similarity.scala +++ b/sources/scala/Similarity.scala @@ -10,7 +10,6 @@ package scala; -// !!! Just a stub to make things compile. trait Similarity { - def similar(that: Similarity): boolean = false; + def similar(that: Any): boolean; } diff --git a/sources/scala/xml/NodeSeq.scala b/sources/scala/xml/NodeSeq.scala index 83757e9cd5..9865c9bac4 100644 --- a/sources/scala/xml/NodeSeq.scala +++ b/sources/scala/xml/NodeSeq.scala @@ -1,14 +1,43 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002, LAMP/EPFL ** +** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** +** $Id$ \* */ -// $Id$ +package scala.xml ; -package scala.xml; +/* a wrapper that adds some XPath navigation method */ +class NodeSeq( theSeq:Seq[Node] ) extends Seq[Node] { + def length = theSeq.length; + def elements = theSeq.elements ; + def apply( i:int ) = theSeq.apply( i ); -// !!! Just a stub to make things compile. -class NodeSeq(any: Any); + /** projection function. Similar to XPath, use this./'foo to get a list + * of all elements of this sequence that are labelled with "foo". + * Use /'_ as a wildcard. The document order is preserved. + */ + def \(that: Symbol):NodeSeq = { + that.name match { + case "_" => + val it = elements.flatMap { x:Node => x.child.elements }; + new NodeSeq( it.toList ); + case _ => + val list = elements.flatMap( y => + y.child.elements.filter{ z:Node => z.label == that.name }).toList; + new NodeSeq( list ); + } + } + + def \\( that:Symbol ):NodeSeq = { + val it = elements.flatMap { x:Node => x.child.elements }; + val list = (elements.flatMap { x:Node => x.descendant_or_self.elements }).toList; + that.name match { + case "_" => new NodeSeq( list ); + case _ => new NodeSeq( list.filter { z:Node => z.label == that.name }); + } + } + +} |