1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
(* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-2000 NEC Research Institute.
*
* MLton is released under a HPND-style license.
* See the file MLton-LICENSE for details.
*)
(* The :> is to hide the type substring. We must add the where's to make char
* and string the same as the toplevel types.
*)
functor SubstringFn(Arg : STRING_ARG)
:> SUBSTRING_EXTRA
where type char = Arg.CharVector.MonoVectorSlice.elem
where type string = Arg.CharVector.MonoVectorSlice.vector
where type substring = Arg.CharVector.MonoVectorSlice.slice =
struct
open Arg
open CharVector.MonoVectorSlice
type char = elem
type string = vector
type substring = slice
val size = length
val extract = slice
fun substring (s, start, len) = extract (s, start, SOME len)
val string = vector
val getc = getItem
fun first ss = Option.map #1 (getItem ss)
val slice = subslice
val explode = toList
local
fun make f = f (op = : char * char -> bool)
in
val isPrefix = make isPrefix
val isSubstring = make isSubvector
val isSuffix = make isSuffix
val position = make position
end
val compare = collate Char.compare
(*
type cs = int
fun reader (T {str, start, size}): (char, cs) Reader.reader =
fn i => if i >= size
then NONE
else SOME (String.sub (str, start +? i), i + 1)
fun 'a scanSubstring
(f: (char, cs) Reader.reader -> ('a, int) Reader.reader)
(ss: substring): 'a option =
case f (reader ss) 0 of
NONE => NONE
| SOME (a, _) => SOME a
*)
end
structure Substring = SubstringFn(StringArg)
structure WideSubstring = SubstringFn(WideStringArg)
|