diff options
author | Burak Emir <emir@epfl.ch> | 2007-02-27 16:37:44 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2007-02-27 16:37:44 +0000 |
commit | 5a435856c79a217146b9a31b997c11ab36d0b050 (patch) | |
tree | 6f54c573691ffe9563dc61460516cc3e539a62dd /src | |
parent | 3faf31102bb00404ef63bd0a4f693813a020aa9e (diff) | |
download | scala-5a435856c79a217146b9a31b997c11ab36d0b050.tar.gz scala-5a435856c79a217146b9a31b997c11ab36d0b050.tar.bz2 scala-5a435856c79a217146b9a31b997c11ab36d0b050.zip |
made Elem serializable again, added Utility.sor...
made Elem serializable again, added Utility.sort method for attribute
sorting
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/xml/Elem.scala | 2 | ||||
-rw-r--r-- | src/library/scala/xml/Utility.scala | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/library/scala/xml/Elem.scala b/src/library/scala/xml/Elem.scala index 027a1120b0..37c2f3e6a4 100644 --- a/src/library/scala/xml/Elem.scala +++ b/src/library/scala/xml/Elem.scala @@ -32,7 +32,7 @@ object Elem { * @param child the children of this node */ // "val" is redundant for non-overriding arguments -/*case*/ class Elem(override val prefix: String, +@serializable class Elem(override val prefix: String, val label: String, override val attributes: MetaData, override val scope: NamespaceBinding, diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala index c0be4bc280..c0b28b89ae 100644 --- a/src/library/scala/xml/Utility.scala +++ b/src/library/scala/xml/Utility.scala @@ -40,6 +40,20 @@ object Utility extends AnyRef with parsing.TokenTests { case _ => x } + /** returns a sorted attribute list */ + def sort(md: MetaData): MetaData = if((md eq Null) || (md.next eq Null)) md else { + val key = md.key + val smaller = sort(md.filter { m => m.key < key }) + val greater = sort(md.filter { m => m.key > key }) + smaller.append( Null ).append(md.copy ( greater )) + } + + /** returns the node with its attribute list sorted alphabetically (prefixes are ignored) */ + def sort(n:Node): Node = n match { + case Elem(pre,lab,md,scp,child@_*) => + Elem(pre,lab,sort(md),scp, (child map sort):_*) + case _ => n + } /** @deprecated a string might also be Atom(s) - define your own conversion */ |