Version: 5.1
28 Text Representations
(require unstable/text) |
This library is unstable;
compatibility will not be maintained.
See Unstable for more information.
This module provides tools for manipulating and converting textual data.
28.1 Contracts and Predicates
| ||
|
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 |
| ||
| ||
|
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 |
28.2 Text Conversions and Concatenation
| |||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||
|
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> |
| |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
|
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"> | |||
| |||
#<syntax:4:0 |(concatenate)|> | |||
| |||
#<syntax:5:0 #:<concat-enate>> |
28.3 Text Comparisons
| |||
| |||
| |||
| |||
|
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 |