]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/xml/name/name.factor
factor: trim using lists
[factor.git] / basis / xml / name / name.factor
index dd83e892baa9c215046d44bab9e0e47eb1fd2a30..ab47ac7d415ef5777e9963cf6db5d2e3a9e9c305 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005, 2009 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel namespaces accessors xml.tokenize xml.data assocs
-xml.errors xml.char-classes combinators.short-circuit splitting
-fry xml.state sequences combinators ascii math make ;
+USING: accessors ascii assocs combinators
+combinators.short-circuit kernel make math namespaces sequences
+xml.char-classes xml.data xml.errors xml.state xml.tokenize ;
 IN: xml.name
 
 ! XML namespace processing: ns = namespace
@@ -25,7 +25,7 @@ SYMBOL: ns-stack
 
 : add-ns ( name -- )
     dup space>> dup ns-stack get assoc-stack
-    [ nip ] [ nonexist-ns ] if* >>url drop ;
+    [ ] [ nonexist-ns ] ?if >>url drop ;
 
 : push-ns ( hash -- )
     ns-stack get push ;
@@ -53,10 +53,15 @@ SYMBOL: ns-stack
         } 2&&
     ] if-empty ;
 
+<PRIVATE
+
+: valid-name-start? ( str -- ? )
+    [ f ] [ version-1.0? swap first name-start? ] if-empty ;
+
 : maybe-name ( space main -- name/f )
     2dup {
-        [ drop valid-name? ]
-        [ nip valid-name? ]
+        [ drop valid-name-start? ]
+        [ nip valid-name-start? ]
     } 2&& [ f <name> ] [ 2drop f ] if ;
 
 : prefixed-name ( str -- name/f )
@@ -68,10 +73,9 @@ SYMBOL: ns-stack
     ] [ drop f ] if* ;
 
 : interpret-name ( str -- name )
-    dup prefixed-name [ ] [
-        dup valid-name?
-        [ <simple-name> ] [ bad-name ] if
-    ] ?if ;
+    dup prefixed-name [ ] [ <simple-name> ] ?if ;
+
+PRIVATE>
 
 : take-name ( -- string )
     version-1.0? '[ _ swap name-char? not ] take-until ;