summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorRoberto Tyley <roberto.tyley@gmail.com>2012-11-27 22:51:01 +0000
committerRoberto Tyley <roberto.tyley@gmail.com>2012-11-27 22:53:04 +0000
commit1426d9cecf1b6123d0dffe44a8ab0dbf88a29707 (patch)
treee9f2f6e7e7137eecf9292f15f034d8814fae06de /src/library
parent9afc00c0408e49a111f381334cbdb7fcdaa4f340 (diff)
downloadscala-1426d9cecf1b6123d0dffe44a8ab0dbf88a29707.tar.gz
scala-1426d9cecf1b6123d0dffe44a8ab0dbf88a29707.tar.bz2
scala-1426d9cecf1b6123d0dffe44a8ab0dbf88a29707.zip
Add convenience attribute operator to NodeSeq
Compared to the current method of reading the string text of an attribute: (x \ "@bar").text ...the new operator removes the need for a pair of parenthesis and shortens the overall expression by 7 chars : x \@ "bar" Discussion on scala-internals: https://groups.google.com/d/topic/scala-internals/BZ-tfbebDqE/discussion
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/xml/NodeSeq.scala5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/library/scala/xml/NodeSeq.scala b/src/library/scala/xml/NodeSeq.scala
index decf60dad7..d2efc947b1 100644
--- a/src/library/scala/xml/NodeSeq.scala
+++ b/src/library/scala/xml/NodeSeq.scala
@@ -145,6 +145,11 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
}
}
+ /** Convenience method which returns string text of the named attribute. Use:
+ * - `that \@ "foo"` to get the string text of attribute `"foo"`;
+ */
+ def \@(attributeName: String): String = (this \ ("@" + attributeName)).text
+
override def toString(): String = theSeq.mkString
def text: String = (this map (_.text)).mkString