! 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
: 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 ;
} 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 )
] [ 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 ;