StringCvt
structureThe StringCvt structure provides types and functions for handling the conversion between strings and values of various basic types.
signature STRING_CVT
structure StringCvt
: STRING_CVT
datatype radix = BIN | OCT | DEC | HEX
datatype realfmt
= SCI of int option
| FIX of int option
| GEN of int option
type cs
type ('a, 'b) reader = 'b -> ('a * 'b) option
val padLeft : char -> int -> string -> string
val padRight : char -> int -> string -> string
val splitl : (char -> bool) -> (char, 'a) reader ->'a -> (string * 'a)
val takel : (char -> bool) -> (char, 'a) reader ->'a -> string
val dropl : (char -> bool) -> (char, 'a) reader ->'a -> 'a
val skipWS : (char, 'a) reader -> 'a -> 'a
val scanString : ((char, cs) reader -> ('a, cs) reader) -> string -> 'a option
val scanList : ((char, char list) reader -> ('a, char list) reader) -> char list -> ('a * char list) option
datatype radix
datatype realfmt
type cs
type ('a, 'b) reader
SOME(a,b)
corresponds to a value a scanned from the stream, plus the remainder b of the stream. A return value of NONE indicates that no value of the correct type could be scanned from the stream.
padLeft c i s
padRight c i s
i - size s
copies of the character c. If size
s >= i, they just return the string s. In other words, these functions right- and left-justify s in a field i characters wide, never trimming off any part of s. Note that if i <= 0, s is returned. These functions raise Size if the size of the resulting string would be greater than String.maxSize.
splitl p f src
(pref, src')
where pref is the longest prefix (left substring) of src, as produced from src by the character reader f, all of whose characters satisfy p, and src' is the remainder of src. Thus, the first character retrievable from src' is the leftmost character not satisfying p.
splitl can be used with scanning functions such as scanString by composing it with SOME; e.g., scanString (fn g => SOME o (splitl g))
.
takel p f src
dropl p f src
takel p f s = #1(splitl p f s) dropl p f s = #2(splitl p f s)
skipWS f s
dropl Char.isSpace
.
scanString f s
scanList f c
Question:
Should this function return
'a option
likescanString
?
The scanning functions skipWS and scanString are designed for stream IO. In particular, they consume lookahead characters, so if they were applied to an imperative stream, the lookahead character would be lost.
String, Char
Last Modified January 21, 1997
Copyright © 1996 AT&T