On this page:
3.1 Text Representations
3.1.1 Contracts and Predicates
text/ c
text?
string-literal?
bytes-literal?
keyword-literal?
3.1.2 Text Conversions and Concatenation
text->string
text->bytes
text->symbol
text->keyword
text->string-literal
text->bytes-literal
text->identifier
text->keyword-literal
3.1.3 Text Comparisons
text=?
text<?
text<=?
text>?
text>=?
3.2 Regular Expressions
regexp-sequence
regexp-or
regexp-maybe
regexp-star
regexp-plus
regexp-save
regexp-multi
3.3 XML and CSS
css/ c
css?
xexpr/ c
write-css
write-xexpr
create-stylesheet
create-webpage
Version: 5.2.0.4

3 Textual Data

3.1 Text Representations

 (require (planet cce/scheme:7:8/text))

This module provides tools for manipulating and converting textual data.

3.1.1 Contracts and Predicates

text/c : flat-contract?
(text? v)  boolean?
  v : any/c
This contract and predicate recognize text values: strings, byte strings, symbols, and keywords, as well as syntax objects containing them.

Examples:

> (text? "text")

#t

> (text? #"text")

#t

> (text? 'text)

#t

> (text? '#:text)

#t

> (text? #'"text")

#t

> (text? #'#"text")

#t

> (text? #'text)

#t

> (text? #'#:text)

#t

> (text? '(not text))

#f

(string-literal? v)  boolean?
  v : any/c
(bytes-literal? v)  boolean?
  v : any/c
(keyword-literal? v)  boolean?
  v : any/c
These predicates recognize specific text types stored in syntax objects.

Examples:

> (string-literal? #'"literal")

#t

> (string-literal? "not literal")

#f

> (bytes-literal? #'#"literal")

#t

> (bytes-literal? #"not literal")

#f

> (keyword-literal? #'#:literal)

#t

> (keyword-literal? '#:not-literal)

#f

3.1.2 Text Conversions and Concatenation

(text->string [#:before before    
  #:between between    
  #:after after]    
  text ...)  string?
  before : text/c = ""
  between : text/c = ""
  after : text/c = ""
  text : text/c
(text->bytes [#:before before    
  #:between between    
  #:after after]    
  text ...)  bytes?
  before : text/c = ""
  between : text/c = ""
  after : text/c = ""
  text : text/c
(text->symbol [#:before before    
  #:between between    
  #:after after]    
  text ...)  symbol?
  before : text/c = ""
  between : text/c = ""
  after : text/c = ""
  text : text/c
(text->keyword [#:before before    
  #:between between    
  #:after after]    
  text ...)  keyword?
  before : text/c = ""
  between : text/c = ""
  after : text/c = ""
  text : text/c
These functions convert text values to specific types. They concatenate each text argument, adding before and after to the front and back of the result and between between each argument.

Examples:

> (text->string #"concat" #'enate)

"concatenate"

> (text->bytes #:between "-" 'concat #'#:enate)

#"concat-enate"

> (text->symbol #:before "(" #:after ")" '#:concat #'"enate")

'|(concatenate)|

> (text->keyword #:before #'< #:between #'- #:after #'> "concat" #'#"enate")

'#:<concat-enate>

(text->string-literal [#:before before    
  #:between between    
  #:after after    
  #:stx stx]    
  text ...)  string-literal?
  before : text/c = ""
  between : text/c = ""
  after : text/c = ""
  stx : (or/c syntax? false/c) = #f
  text : text/c
(text->bytes-literal [#:before before    
  #:between between    
  #:after after    
  #:stx stx]    
  text ...)  bytes-literal?
  before : text/c = ""
  between : text/c = ""
  after : text/c = ""
  stx : (or/c syntax? false/c) = #f
  text : text/c
(text->identifier [#:before before    
  #:between between    
  #:after after    
  #:stx stx]    
  text ...)  identifier?
  before : text/c = ""
  between : text/c = ""
  after : text/c = ""
  stx : (or/c syntax? false/c) = #f
  text : text/c
(text->keyword-literal [#:before before    
  #:between between    
  #:after after    
  #:stx stx]    
  text ...)  keyword-literal?
  before : text/c = ""
  between : text/c = ""
  after : text/c = ""
  stx : (or/c syntax? false/c) = #f
  text : text/c
These functions convert text values to specific syntax object types, deriving syntax object properties from the stx argument. They concatenate each text argument, adding before and after to the front and back of the result and between between each argument.

Examples:

> (text->string-literal #"concat" #'enate)

#<syntax "concatenate">

> (text->bytes-literal #:between "-" 'concat #'#:enate)

#<syntax #"concat-enate">

> (text->identifier #:before "(" #:after ")"
                     #:stx #'props
                    '#:concat #'"enate")

#<syntax:4:0 |(concatenate)|>

> (text->keyword-literal #:before #'< #:between #'- #:after #'>
                         #:stx #'props
                         "concat" #'#"enate")

#<syntax:5:0 #:<concat-enate>>

3.1.3 Text Comparisons

(text=? one two)  boolean?
  one : text/c
  two : text/c
(text<? one two)  boolean?
  one : text/c
  two : text/c
(text<=? one two)  boolean?
  one : text/c
  two : text/c
(text>? one two)  boolean?
  one : text/c
  two : text/c
(text>=? one two)  boolean?
  one : text/c
  two : text/c
These predicates compare the character content of two text values. They are equivalent to:

(text=? one two) = (string=? (text->string one) (text->string two))
(text<? one two) = (string<? (text->string one) (text->string two))
(text<=? one two) = (string<=? (text->string one) (text->string two))
(text>? one two) = (string>? (text->string one) (text->string two))
(text>=? one two) = (string>=? (text->string one) (text->string two))

Examples:

> (text=? #"x" #'y)

#f

> (text<? #"x" #'y)

#t

> (text<=? #"x" #'y)

#t

> (text>? #"x" #'y)

#f

> (text>=? #"x" #'y)

#f

3.2 Regular Expressions

 (require (planet cce/scheme:7:8/regexp))

This module provides tools for building strings which can be compiled to regular expressions. In particular, the constructors wrap their arguments in appropriate delimeters to prevent misparsing after concatenation.

(regexp-sequence [#:start start    
  #:between between    
  #:end end]    
  re ...)  string?
  start : string? = ""
  between : string? = ""
  end : string? = ""
  re : string?
Produces a regular expression string that matches start, followed by each re interleaved with between, followed by end.

Examples:

(define re
  (pregexp
   (regexp-sequence "[0-9]+" "[0-9]+" "[0-9]+"
                    #:start (regexp-quote "(")
                    #:between (regexp-quote ",")
                    #:end (regexp-quote ")"))))
> (regexp-match-exact? re "(1,10,100)")

#t

> (regexp-match-exact? re "(1,10)")

#f

> (regexp-match-exact? re " ( 1 , 10 , 100 ) ")

#f

(regexp-or re ...+)  string?
  re : string?
Produces a regular expression string that matches any of the given res.

Examples:

(define re (pregexp (regexp-or "[0-9]+" "[a-z]")))
> (regexp-match-exact? re "123")

#t

> (regexp-match-exact? re "c")

#t

> (regexp-match-exact? re "12c")

#f

(regexp-maybe re ...+)  string?
  re : string?
Produces a regular expression string that matches either the empty string, or the concatenation of all the given res.

Examples:

(define re (pregexp (regexp-maybe "[0-9]+" "[.]" "[0-9]+")))
> (regexp-match-exact? re "123.456")

#t

> (regexp-match-exact? re "")

#t

> (regexp-match-exact? re "123")

#f

(regexp-star re ...+)  string?
  re : string?
Produces a regular expression string that matches zero or more consecutive occurrences of the concatenation of the given res.

Examples:

(define re (pregexp (regexp-star "a" "b" "c")))
> (regexp-match-exact? re "")

#t

> (regexp-match-exact? re "abc")

#t

> (regexp-match-exact? re "abcabcabc")

#t

> (regexp-match-exact? re "a")

#f

(regexp-plus re ...+)  string?
  re : string?
Produces a regular expression string that matches one or more consecutive occurrences of the concatenation of the given res.

Examples:

(define re (pregexp (regexp-plus "a" "b" "c")))
> (regexp-match-exact? re "")

#f

> (regexp-match-exact? re "abc")

#t

> (regexp-match-exact? re "abcabcabc")

#t

> (regexp-match-exact? re "a")

#f

(regexp-save re ...+)  string?
  re : string?
Produces a regular expression string that matches the concatenation of the given res and saves the result.

Examples:

(define re
  (pregexp (regexp-sequence (regexp-save "[0-9]+") "\\1")))
> (regexp-match-exact? re "11")

#t

> (regexp-match-exact? re "123123")

#t

> (regexp-match-exact? re "123456")

#f

(regexp-multi re ...+)  string?
  re : string?
Produces a regular expression string that matches the concatenation of the given res in multiple-line mode.

Examples:

(define re (pregexp (regexp-multi "^abc$")))
> (regexp-match? re "abc")

#t

> (regexp-match? re "xyz\nabc\ndef")

#t

3.3 XML and CSS

 (require (planet cce/scheme:7:8/web))

This module provides tools for programmatic creation of static web pages. It is based on the XML collection; see documentation for xexpr?.

css/c : flat-contract?
(css? v)  boolean?
  v : any/c
This contract and predicate pair recognizes CSS-expressions, which are described by the following grammar:

  css = (list style ...)
     
  style-def = (cons selector (list property ...))
     
  property = (list name value)
     
  selector = text
     
  name = text
     
  value = text

Here, text is any of the Text Representations described above.

This flat contract corresponds to xexpr?. It is reprovided from xml. In versions of PLT Scheme before the implementation of xexpr/c, this module provides its own definition.

(write-css css [out])  void?
  css : css/c
  out : output-port? = (current-output-port)
(write-xexpr css [out])  void?
  css : css/c
  out : output-port? = (current-output-port)
These functions write CSS-expressions and X-expressions, respectively, to output ports, by their canonical text representations.

(create-stylesheet file css)  void?
  file : path-string?
  css : css/c
(create-webpage file xexpr)  void?
  file : path-string?
  xexpr : xexpr/c
These functions write style sheets (represented as CSS-expressions) or webpages (represented as X-expressions) to files.