source: project/release/4/sxpath/trunk/chicken/common.scm @ 27178

Last change on this file since 27178 was 27178, checked in by sjamaan, 9 years ago

sxpath: Refactor library structure by putting low-level xpath parser into its own module. This will allow ddo-sxpath and sxml-modifications to re-use it

File size: 1.7 KB
Line 
1;;;
2;;; Common cruft required to make sxml-tools happy
3;;;
4;;; These are procedures that are expected, but not provided, by sxml-tools
5;;;
6
7(require-library srfi-1 srfi-13 data-structures)
8(import (only srfi-13 string-prefix? string-prefix-ci? string-index-right
9              string-contains string-concatenate string-concatenate/shared)
10        (only srfi-1 filter)
11        (prefix (only data-structures string-split) chicken:))
12
13;; Defined in xpath-parser, but used elsewhere...  Maybe export it from txpath-parser?
14(define sxml:whitespace '(#\space #\return #\newline #\tab))
15
16(define (substring? pattern str) (string-contains str pattern))
17(define string-rindex string-index-right)
18
19(define nl (string #\newline))
20(define -- sub1)
21(define inc add1)
22
23; like cout << arguments << args
24; where argument can be any Scheme object. If it's a procedure
25; (without args) it's executed rather than printed (like newline)
26(define (cout . args)
27  (for-each (lambda (x)
28              (if (procedure? x) (x) (display x)))
29            args))
30
31(define (cerr . args)
32  (for-each (lambda (x)
33              (if (procedure? x) (x (current-error-port)) (display x (current-error-port))))
34            args))
35
36;; This is a simplified version of the "string-split" procedure provided
37;; by SSAX/lib/util.scm (which is 57 lines long!); this one is enough for
38;; txpath and xpath-context
39(define (string-split str separators . rest)
40  (if (not (null? rest))
41      (error (string-append "String-split called with more arguments. "
42                            "This shouldn't happen and is a bug in the "
43                            "chicken-specific code of the sxpath egg."))
44      (chicken:string-split str (list->string separators))))
Note: See TracBrowser for help on using the repository browser.