racket/collects/unstable/string.rkt
2011-11-30 17:54:28 -05:00

47 lines
1.5 KiB
Racket

#lang racket/base
(require racket/contract/base
racket/serialize)
(define (read/string str)
(define r (read (open-input-string str)))
(cond [(eof-object? r) (raise-type-error 'read/string "nonempty string" str)]
[else r]))
;; Eli: Same comments as `read/bytes'.
(define (write/string v)
(define str (open-output-string))
(write v str)
(get-output-string str))
;; Eli: Same comments as `write/string', and worse -- this is the same as
;; (format "~s" v)
; lowercase-symbol! : (or/c string bytes) -> symbol
(define (lowercase-symbol! s)
(string->symbol
(string-downcase
(if (bytes? s)
(bytes->string/utf-8 s)
s))))
;; Eli: This doesn't make any sense at all. Why is the `!' in the name? Why
;; does it accept bytes? Why does a function in a "string" library accept
;; bytes? How can I guess that this creates a new symbol from that name?
;; (Which makes me think that this is (compose string->symbol string-downcase
;; symbol->string))
(provide/contract
[lowercase-symbol! ((or/c string? bytes?) . -> . symbol?)]
[read/string (string? . -> . serializable?)]
[write/string (serializable? . -> . string?)])
;; added by stamourv
(define (regexp-filter r log)
(for/list ([l (in-list log)] #:when (regexp-match r l))
l))
(provide/contract
[regexp-filter ((or/c string? bytes? regexp? byte-regexp?)
(listof (or/c string? bytes? path? input-port?))
. -> . (listof (or/c string? bytes? path? input-port?)))])