home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / StringCvt.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  3.1 KB  |  74 lines  |  [TEXT/Moml]

  1. (* StringCvt -- SML Basis Library *)
  2.  
  3. datatype radix = BIN | OCT | DEC | HEX;
  4.  
  5. datatype realfmt = 
  6.     SCI of int option   (* scientific,  arg = # dec. digits, dflt=6 *)
  7.   | FIX of int option   (* fixed-point, arg = # dec. digits, dflt=6 *)
  8.   | GEN of int option   (* auto choice of the above,                *)
  9.                         (* arg = # significant digits, dflt=12      *)
  10.  
  11. type cs                 (* character source state *)
  12.  
  13. type ('a, 'b) reader = 'b -> ('a * 'b) option
  14.  
  15. val scanString : ((char, cs) reader -> ('a, cs) reader) -> string -> 'a option
  16.  
  17. val splitl     : (char -> bool) -> (char, 'a) reader -> 'a -> string * 'a
  18. val takel      : (char -> bool) -> (char, 'a) reader -> 'a -> string 
  19. val dropl      : (char -> bool) -> (char, 'a) reader -> 'a -> 'a 
  20. val skipWS     : (char, 'a) reader -> 'a -> 'a 
  21.  
  22. val padLeft    : char -> int -> string -> string
  23. val padRight   : char -> int -> string -> string
  24.  
  25.  
  26. (* This structure presents tools for scanning strings and values from
  27.    functional character streams, and for formatting ML characters and
  28.    strings containing escape sequences.
  29.  
  30.    A character source reader 
  31.         getc : (char, cs) reader 
  32.    is used for obtaining characters from a functional character source
  33.    src of type cs, one at a time. It should hold that
  34.  
  35.         getc src = SOME(c, src')        if the next character in src 
  36.                                         is c, and src' is the rest of src;
  37.                  = NONE                 if src contains no characters
  38.  
  39.    A character source scanner takes a character source reader getc as
  40.    argument and uses it to scan a data value from the character
  41.    source.
  42.  
  43.    [scanString scan s] turns the string s into a character source and
  44.    applies the scanner `scan' to that source.
  45.  
  46.    [splitl p getc src] returns (pref, suff) where pref is the
  47.    longest prefix (left substring) of src all of whose characters
  48.    satisfy p, and suff is the remainder of src.  That is, the first
  49.    character retrievable from suff, if any, is the leftmost character
  50.    not satisfying p.  Does not skip leading whitespace.
  51.  
  52.    [takel p getc src] returns the longest prefix (left substring) of
  53.    src all of whose characters satisfy predicate p.  That is, if the
  54.    left-most character does not satisfy p, the result is the empty
  55.    string.  Does not skip leading whitespace.  It holds that
  56.         takel p getc src = #1 (splitl p getc src)
  57.  
  58.    [dropl p getc src] drops the longest prefix (left substring) of
  59.    src all of whose characters satisfy predicate p.  If all characters
  60.    do, it returns the empty source.  It holds that
  61.         dropl p getc src = #2 (splitl p getc src)
  62.  
  63.    [skipWS getc src] drops any leading whitespace from src.
  64.    Equivalent to dropl Char.isSpace.
  65.  
  66.    [padLeft c n s] returns the string s if size s >= n, otherwise pads
  67.    s with (n - size s) copies of the character c on the left.  
  68.    In other words, right-justifies s in a field n characters wide.
  69.  
  70.    [padRight c n s] returns the string s if size s >= n, otherwise pads
  71.    s with (n - size s) copies of the character c on the right.
  72.    In other words, left-justifies s in a field n characters wide.
  73. *)
  74.