summaryrefslogtreecommitdiff
path: root/sources/scala/xml/Utility.scala
diff options
context:
space:
mode:
Diffstat (limited to 'sources/scala/xml/Utility.scala')
-rw-r--r--sources/scala/xml/Utility.scala21
1 files changed, 21 insertions, 0 deletions
diff --git a/sources/scala/xml/Utility.scala b/sources/scala/xml/Utility.scala
index 2737e75d58..29314774e4 100644
--- a/sources/scala/xml/Utility.scala
+++ b/sources/scala/xml/Utility.scala
@@ -190,6 +190,27 @@ object Utility extends AnyRef with parsing.TokenTests {
sb.append(ch).append(s).append(ch)
}
+
+ /**
+ * Appends "s" if s does not contain ", 's'
+ * otherwise, and replaces < and &
+ *
+ * @param s
+ * @param sb
+ */
+ def appendAttributeValue(s: String, sb: StringBuffer) = {
+ val ch = if (s.indexOf('"') == -1) '"' else '\'';
+ sb.append(ch);
+ val ss: Seq[Char] = s;
+ val it = ss.elements;
+ while(it.hasNext) it.next match {
+ case '<' => sb.append("&lt;");
+ case '&' => sb.append("&amp;");
+ case x => sb.append(x);
+ }
+ sb.append(ch)
+ }
+
/**
* Appends &quot;s&quot; and escapes and &quot; i s with \&quot;
*