1 (* Copyright (C
) 1999-2007 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
3 * Copyright (C
) 1997-2000 NEC Research Institute
.
5 * MLton is released under a BSD
-style license
.
6 * See the file MLton
-LICENSE for details
.
9 (* The
:> is to hide the
type substring
. We must add the
where's to make char
10 * and string the same
as the toplevel types
.
12 functor SubstringFn(Arg
: STRING_ARG
)
14 where type char
= Arg
.CharVector
.MonoVectorSlice
.elem
15 where type string = Arg
.CharVector
.MonoVectorSlice
.vector
16 where type substring
= Arg
.CharVector
.MonoVectorSlice
.slice
=
19 open CharVector
.MonoVectorSlice
23 type substring
= slice
27 fun substring (s
, start
, len
) = extract (s
, start
, SOME len
)
30 fun first ss
= Option
.map #
1 (getItem ss
)
34 fun make f
= f (op = : char
* char
-> bool)
36 val isPrefix
= make isPrefix
37 val isSubstring
= make isSubvector
38 val isSuffix
= make isSuffix
39 val position
= make position
41 val compare
= collate
Char.compare
46 fun reader (T
{str
, start
, size
}): (char
, cs
) Reader
.reader
=
49 else SOME (String.sub (str
, start
+? i
), i
+ 1)
52 (f
: (char
, cs
) Reader
.reader
-> ('a
, int) Reader
.reader
)
53 (ss
: substring
): 'a option
=
54 case f (reader ss
) 0 of
56 |
SOME (a
, _
) => SOME a
60 structure Substring
= SubstringFn(StringArg
)
61 structure WideSubstring
= SubstringFn(WideStringArg
)