Import Upstream version 20180207
[hcoop/debian/mlton.git] / lib / mlton / basic / string.sig
CommitLineData
7f918cf1
CE
1(* Copyright (C) 2009,2014 Matthew Fluet.
2 * Copyright (C) 1999-2006, 2008 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 *
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
7 *)
8
9signature STRING =
10 sig
11 type t = string
12
13 (* a / b = a ^ "/" ^ b
14 * This abbreviation is useful for building pathnames, e.g.
15 * val user = "you"
16 * val bin = "/home"/user/"bin"
17 *)
18 val / : string * string -> string
19 val < : t * t -> bool
20 val <= : t * t -> bool
21 val > : t * t -> bool
22 val >= : t * t -> bool
23 val ^ : t * t -> t
24 val alphabetize: t -> t
25 val baseName: t * t -> t
26 val compare: t * t -> Relation.t
27 val concat: t list -> t
28 val concatV: t vector -> t
29 val concatWith: t list * t -> t
30 val contains: t * char -> bool
31 val deleteSurroundingWhitespace: t -> t
32 val dquote: t (* " *)
33 val dropl: t * (char -> bool) -> t
34 val dropFirst: t -> t
35 val dropLast: t -> t
36 val dropPrefix: t * int -> t
37 val dropSuffix: t * int -> t
38 val dropTrailing: t * char -> t
39 val empty: t
40 val equals: t * t -> bool
41 val escapeC: t -> t
42 val escapeSML: t -> t
43 val existsi: t * (int * char -> bool) -> bool
44 val exists: t * (char -> bool) -> bool
45 val explode: t -> char list
46 (* extract (s, i, SOME j)
47 * returns the substring of s of length j starting at i.
48 *)
49 val extract: t * int * int option -> t
50 val fields: t * (char -> bool) -> t list
51 val findSubstring: t * {substring: t} -> int option
52 val fold: t * 'a * (char * 'a -> 'a) -> 'a
53 val foldi: t * 'a * (int * char * 'a -> 'a) -> 'a
54 val foreach: t * (char -> unit) -> unit
55 val forall: t * (char -> bool) -> bool
56 val fromCString: t -> t option
57 val fromChar: char -> t
58 val fromCharArray: CharArray.array -> t
59 val fromListRev: char list -> t
60 val fromString: t -> t option
61 val hash: t -> Word.t
62 val implode: char list -> t
63 val implodeV: char vector -> t
64 val isEmpty: t -> bool
65 val hasPrefix: t * {prefix: t} -> bool
66 val hasSubstring: t * {substring: t} -> bool
67 val hasSuffix: t * {suffix: t} -> bool
68 val keepAll: t * (char -> bool) -> t
69 val last: t -> char
70 val layout: t -> Layout.t
71 val length: t -> int
72 val lparen: t (* ( *)
73 val make: int * char -> t
74 val max: t * t -> t
75 val memoize: (t -> 'a) -> t -> 'a
76 val memoizeList: (t -> 'a) * (t * 'a) list -> t -> 'a
77 val min: t * t -> t
78 val newline: t
79 val output: t * TextIO.outstream -> unit
80 val peek: t * (char -> bool) -> char option
81 val peeki: t * (int * char -> bool) -> (int * char) option
82 val posToLineCol: t -> int -> {line: int, col: int}
83 val prefix: t * int -> t
84 val removeTrailing: t * (char -> bool) -> t
85 val rev: t -> t
86 val rparen: t (* ) *)
87 val size: t -> int
88 (* splits the string into substrings broken at char,
89 * e.g. split("foo$bar$baz", #"$") = ["foo", "bar", "baz"]
90 *)
91 val split: t * char -> t list
92 val sub: t * int -> char
93 val substituteAll: t * {substring: t, replacement: t} -> t
94 val substituteFirst: t * {substring: t, replacement: t} -> t
95 (* beginning at start, with length chars *)
96 val substring1: t * {start: int, length: int} -> t
97 (* inclusive of start, exclusive of finish *)
98 val substring2: t * {start: int, finish: int} -> t
99 val substring: t * int * int -> t
100 val suffix: t * int -> t
101 val tabulate: int * (int -> char) -> t
102 val toChar: t -> char
103 val toLower: t -> t
104 val toString: t -> t
105 val toUpper: t -> t
106 val tokens: t * (char -> bool) -> t list
107 val translate: t * (char -> t) -> t
108 val unfold: int * 'a * ('a -> char * 'a) -> t
109 end
110
111
112functor TestString (S: STRING): sig end =
113struct
114
115val _ = print "TestString\n"
116
117open S
118
119val _ =
120 Assert.assert
121 ("TestString", fn () =>
122 dropl("abc", fn c => c = #"a") = "bc"
123 andalso "\\000" = escapeC "\000"
124 andalso "abc" = removeTrailing ("abc ", Char.isSpace)
125 andalso "" = removeTrailing (" ", Char.isSpace)
126 )
127
128end