#lang racket/base
(require "SSAX-code.ss")
(provide RES-NAME->SXML
reverse-collect-str
reverse-collect-str-drop-ws)
(define (RES-NAME->SXML res-name)
(string->symbol
(string-append
(symbol->string (car res-name))
":"
(symbol->string (cdr res-name)))))
(define (reverse-collect-str fragments)
(if (null? fragments) '() (let loop ((fragments fragments) (result '()) (strs '()))
(cond
((null? fragments)
(if (null? strs) result
(cons (apply string-append strs) result)))
((string? (car fragments))
(loop (cdr fragments) result (cons (car fragments) strs)))
(else
(loop (cdr fragments)
(cons
(car fragments)
(if (null? strs) result
(cons (apply string-append strs) result)))
'()))))))
(define (reverse-collect-str-drop-ws fragments)
(cond
((null? fragments) '()) ((and (string? (car fragments)) (null? (cdr fragments)) (string-whitespace? (car fragments))) '())
(else
(let loop ((fragments fragments) (result '()) (strs '())
(all-whitespace? #t))
(cond
((null? fragments)
(if all-whitespace? result (cons (apply string-append strs) result)))
((string? (car fragments))
(loop (cdr fragments) result (cons (car fragments) strs)
(and all-whitespace?
(string-whitespace? (car fragments)))))
(else
(loop (cdr fragments)
(cons
(car fragments)
(if all-whitespace? result
(cons (apply string-append strs) result)))
'() #t)))))))