StringCvt structure

August 11, 2026 ยท View on GitHub

Up to index

The StringCvt structure provides types and utilities to support formatted string scanning and conversion, including numeric radix specifiers and reader types.

Specified by the Standard ML Basis Library.

Synopsis

datatype radix = BIN | OCT | DEC | HEX
type ('a, 'b) reader = 'b -> ('a * 'b) option
datatype realfmt
  = SCI of int option
  | FIX of int option
  | GEN of int option
  | EXACT

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, 'b) reader -> ('a, 'b) reader) -> string -> 'a option

datatype radix

specifies the numeric base: binary (2), octal (8), decimal (10), or hexadecimal (16).

type ('a, 'b) reader

is the type of a scanning function that reads one value of type 'a from a stream of type 'b, returning the value and the remaining stream, or NONE at end of input.

datatype realfmt

specifies the format for converting real numbers to strings.

padLeft

padLeft c i s padLeft c i s returns s padded on the left with c characters so that the result has length at least i. If s is already at least i characters long, it is returned unchanged.

padRight

padRight c i s padRight c i s returns s padded on the right with c characters so that the result has length at least i. If s is already at least i characters long, it is returned unchanged.

splitl

splitl f rdr src splitl f rdr src reads from src the longest prefix of characters satisfying f, and returns that prefix together with the rest of src.

takel

takel f rdr src takel f rdr src returns the longest prefix of src whose characters satisfy f. It is the first component of splitl f rdr src.

dropl

dropl f rdr src dropl f rdr src drops the longest prefix of src whose characters satisfy f. It is the second component of splitl f rdr src.

skipWS

skipWS rdr src skipWS rdr src drops any leading whitespace from src.

scanString

scanString f s scanString f s scans the string s using the scanner f, and returns SOME a if f reads a value a from a prefix of s, NONE otherwise. f is given a reader over the characters of s; the type of the stream that it reads from is not specified.