summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2005-04-25 09:55:59 +0000
committerburaq <buraq@epfl.ch>2005-04-25 09:55:59 +0000
commit2554f8b5f6c2f3494920a9ddfe69cde13ac9c755 (patch)
tree28a2661ed12f53cbbda4b21ca10f4174fd6d9b95 /sources
parent8bb23af6b64a9278303d90f27db35137b9d437f9 (diff)
downloadscala-2554f8b5f6c2f3494920a9ddfe69cde13ac9c755.tar.gz
scala-2554f8b5f6c2f3494920a9ddfe69cde13ac9c755.tar.bz2
scala-2554f8b5f6c2f3494920a9ddfe69cde13ac9c755.zip
moved from xml.Parsing.
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/xml/parsing/TokenTests.scala101
1 files changed, 101 insertions, 0 deletions
diff --git a/sources/scala/xml/parsing/TokenTests.scala b/sources/scala/xml/parsing/TokenTests.scala
new file mode 100644
index 0000000000..8d95424d05
--- /dev/null
+++ b/sources/scala/xml/parsing/TokenTests.scala
@@ -0,0 +1,101 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+** $Id$
+\* */
+package scala.xml.parsing ;
+
+/** helper functions for parsing XML fragments
+ */
+trait TokenTests {
+
+ /** (#x20 | #x9 | #xD | #xA) */
+ final def isSpace( ch:Char ):Boolean = ch match {
+ case '\u0009' | '\u000A' | '\u000D' | '\u0020' => true
+ case _ => false;
+ }
+
+ /** (#x20 | #x9 | #xD | #xA)+ */
+ final def isSpace( cs:Seq[Char] ):Boolean = {
+ val it = cs.elements;
+ it.hasNext && it.forall { isSpace };
+ }
+
+ /** NameChar ::= Letter | Digit | '.' | '-' | '_' | ':'
+ * | CombiningChar | Extender
+ *
+ * see [4] and Appendix B of XML 1.0 specification
+ */
+ def isNameChar( ch:Char ) = isNameStart( ch ) || (ch match {
+ case '.' | '-' | ':' => true;
+ case _ => java.lang.Character.getType( ch ).asInstanceOf[Byte] match {
+ case java.lang.Character.COMBINING_SPACING_MARK => true; // Mc
+ case java.lang.Character.ENCLOSING_MARK => true; // Me
+ case java.lang.Character.NON_SPACING_MARK => true; // Mn
+ case java.lang.Character.MODIFIER_LETTER => true; // Lm
+ case java.lang.Character.DECIMAL_DIGIT_NUMBER => true; // Nd
+ case _ => false;
+ }
+ });
+
+ /** NameStart ::= ( Letter | '_' )
+ * where Letter means in one of the Unicode general
+ * categories { Ll, Lu, Lo, Lt, Nl }
+ *
+ * We do not allow a name to start with ':'.
+ * see [3] and Appendix B of XML 1.0 specification
+ */
+ def isNameStart( ch:Char ) =
+ java.lang.Character.getType( ch ).asInstanceOf[Byte] match {
+ case java.lang.Character.LOWERCASE_LETTER => true;
+ case java.lang.Character.UPPERCASE_LETTER => true;
+ case java.lang.Character.OTHER_LETTER => true;
+ case java.lang.Character.TITLECASE_LETTER => true;
+ case java.lang.Character.LETTER_NUMBER => true;
+ case _ => ch match {
+ case '_' => true
+ case _ => false;
+ }
+ }
+
+ /** Name ::= ( Letter | '_' ) (NameChar)*
+ *
+ * see [5] of XML 1.0 specification
+ */
+ def isName( s:String ):boolean = {
+ if( s.length() > 0 ) {
+ val z:Seq[Char] = s;
+ val y = z.elements;
+ if( isNameStart( y.next ) ) {
+ while( y.hasNext && isNameChar( y.next ) ) {};
+ !y.hasNext
+ } else false;
+ } else false;
+ }
+
+ def isPubIDChar( c:Char ) = c match {
+ case '\u0020' | '\u000D' | '\u000A' => true;
+ case _ if
+ ('0' < c && c < '9')||('a' < c && c < 'z')||('A' < c && c < 'Z') => true;
+ case '-' | '\''| '(' | ')' | '+' | ',' | '.' | '/' | ':' | '=' |
+ '?' | ';' | '!' | '*' | '#' | '@' | '$' | '_' | '%' => true
+ case _ => false;
+ }
+
+ def checkSysID( s:String ):boolean = {
+ s.indexOf('"') == -1 || s.indexOf('\'') == -1
+ }
+
+ def checkPubID( s:String ):boolean = {
+ if( s.length() > 0 ) {
+ val z:Seq[Char] = s;
+ val y = z.elements;
+ while( y.hasNext && isPubIDChar( y.next ) ){};
+ !y.hasNext
+ } else true
+ }
+
+}