diff options
author | Burak Emir <emir@epfl.ch> | 2005-11-25 09:19:00 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2005-11-25 09:19:00 +0000 |
commit | 4b4aa8e21f9431dd288eb7ff125d0a9d2b097efb (patch) | |
tree | b02934aa50099224356ae75bb0dd7412697d26b5 | |
parent | 1d6a8505afb732f72bbba09c753721384e2b02a4 (diff) | |
download | scala-4b4aa8e21f9431dd288eb7ff125d0a9d2b097efb.tar.gz scala-4b4aa8e21f9431dd288eb7ff125d0a9d2b097efb.tar.bz2 scala-4b4aa8e21f9431dd288eb7ff125d0a9d2b097efb.zip |
verif at valu
-rw-r--r-- | sources/scala/xml/Utility.scala | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sources/scala/xml/Utility.scala b/sources/scala/xml/Utility.scala index bf09a68448..ed3ef7a737 100644 --- a/sources/scala/xml/Utility.scala +++ b/sources/scala/xml/Utility.scala @@ -202,4 +202,39 @@ object Utility extends AnyRef with parsing.TokenTests { sb.append('"') } + def getName(s: String, index: Int): String = { + var i = index; + val sb = new StringBuffer(); + if(i < s.length()) { + var c = s.charAt(i); + if(isNameStart(s.charAt(i))) + while(i < s.length() && { c = s.charAt(i); isNameChar(c)}) { + sb.append(c); + i = i + 1; + } + sb.toString(); + } else null + } + + /** returns null if the value is a correct attribute value, error message if it isn't */ + def checkAttributeValue(value: String): String = { + var i = 0; + while(i < value.length()) { + value.charAt(i) match { + case '<' => + return "< not allowed in attribute value"; + case '&' => + val n = getName(value, i+1); + if(n== null) + return "malformed entity reference in attribute value ["+value+"]"; + i = i + n.length() + 1; + if(i >= value.length() || value.charAt(i) != ';') + return "malformed entity reference in attribute value ["+value+"]"; + case _ => + } + i = i + 1; + } + return null; + } + } |