The Scan structure provides C-style conversions from string
representations.
Synopsis
signature SCAN
structure Scan : SCAN
Interface
datatype fmt_item
= ATOM of Atom.atom
| LINT of LargeInt.int
| INT of Int.int
| LWORD of LargeWord.word
| WORD of Word.word
| WORD8 of Word8.word
| BOOL of bool
| CHR of char
| STR of string
| REAL of Real.real
| LREAL of LargeReal.real
| LEFT of (int * fmt_item)
| RIGHT of (int * fmt_item)
exception BadFormat
val sscanf : string -> string -> fmt_item list option
val scanf : string -> (char, 'a) StringCvt.reader
-> (fmt_item list, 'a) StringCvt.reader
Description
datatype fmt_item-
This datatype, which is the same type as
Format.fmt_item, is used as a union type to represent the results of scanning input.LINT n-
wraps a large integer value
nto convert (the conversion specifier must be one of “d”, “o”, “x”, or “X”). INT n-
wraps a default integer value
nto convert (the conversion specifier must be one of “d”, “o”, “x”, or “X”). BOOL b-
wraps a Boolean value
bto convert (the conversion specifier must be “b”). CHR c-
wraps a character value (the conversion specifier must be “c”).
STR s-
wraps a string value
sto convert (the conversion specifier must be “s”). The conversion is the identity; e.g.,STR "\n"will produce a newline in the result string. REAL r-
wraps a default real value
rto convert (the conversion specifier must be one of “e”, “E”, “f”, “F”, “g”, or “G”). ATOM atm-
this constructor will never be returned by
scanforsscanf. LWORD w-
this constructor will never be returned by
scanforsscanf. WORD w-
this constructor will never be returned by
scanforsscanf. WORD8 w-
this constructor will never be returned by
scanforsscanf. LREAL r-
this constructor will never be returned by
scanforsscanf. LEFT _-
this constructor will never be returned by
scanforsscanf. RIGHT _-
this constructor will never be returned by
scanforsscanf.
exception BadFormat-
This exception is raised when either
sscanforscanfis applied to an ill-formed format string.
val sscanf : string → string → fmt_item list option-
sscanf fmt sscans the stringsusing the format specifierfmt. If successful,SOME itemsis returned, where each item in theitemslist corresponds to a specified item infmt. If the input cannot be scanned according tofmt, thenNONEis returned. If the format string is ill formed, then theBadFormatexception will be raised whensscanf fmtis evaluated.
val scanf : string → (char, 'a) StringCvt.reader → (fmt_item list, 'a) StringCvt.reader-
sscanf fmt getcreturns a reader that scan a character stream using the format specifierfmt. If the format string is ill formed, then theBadFormatexception will be raised whenscanf fmtis evaluated.
Format Strings
The sscanf and `scanf functions take a format string as their first
argument. The format string is composed of zero or more
directives, which are either ordinary characters (excluding %)
or conversion specifiers. The result of applying one of the scan functions
to an input will be a list of fmt_item corresponding
to the conversion specifiers in the format string. All conversions are
introduced by the % character. The format string may also contain
other characters. White space (such as blanks, tabs, or newlines) in the format
string match any amount of white space, including none, in the input. Everything
else matches only itself. Scanning stops when an input character does not match
such a format character. Scanning also stops when an input conversion cannot be
made (see below).
To be written