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
.
11 structure Char: CHAR_EXTRA
12 structure CharVector
: EQTYPE_MONO_VECTOR_EXTRA
13 sharing type Char.char
= CharVector
.elem
14 sharing type Char.string = CharVector
.vector
17 functor StringFn(Arg
: STRING_ARG
)
19 where type char
= Arg
.CharVector
.elem
20 where type string = Arg
.CharVector
.vector
21 where type array
= Arg
.CharVector
.array
=
25 structure CharVectorSlice
= MonoVectorSlice
31 fun str c
= new (1, c
)
36 val implode
= fromList
39 fun extract (s
, start
, len
) =
40 CharVectorSlice
.vector (CharVectorSlice
.slice (s
, start
, len
))
41 fun substring (s
, start
, len
) = extract (s
, start
, SOME len
)
43 val toLower
= translate (str
o Char.toLower
)
46 fun make f
= f (op = : char
* char
-> bool)
48 val isPrefix
= make isPrefix
49 val isSubstring
= make isSubvector
50 val isSuffix
= make isSuffix
52 val compare
= collate
Char.compare
54 structure S
= StringComparisons (type t
= string
55 val compare
= compare
)
60 fun Stranslate f
= String.fromPoly
o Vector.translate f
o toPoly
62 val toString
= Stranslate
Char.toString
63 val toCString
= Stranslate
Char.toCString
68 fun loop (state
, cs
) =
69 case Char.scan reader state
of
70 NONE
=> SOME (implode (rev cs
),
71 Char.formatSequences reader state
)
72 |
SOME (c
, state
) => loop (state
, c
:: cs
)
74 fn state
=> loop (state
, [])
77 val fromString
= StringCvt.scanString scan
79 fun scanString scanChar reader
=
81 Option
.map (fn (cs
, state
) => (implode cs
, state
))
82 (Reader
.list (scanChar reader
) state
)
84 val fromCString
= StringCvt.scanString (scanString
Char.scanC
)
86 val null
= str (Char.chr
0)
87 fun nullTerm s
= s ^ null
90 structure StringArg
: STRING_ARG
=
93 structure CharVector
= CharVector
96 structure WideStringArg
: STRING_ARG
=
98 structure Char = WideChar
99 structure CharVector
= WideCharVector
102 structure String : STRING_EXTRA
= StringFn(StringArg
)
103 structure WideString
: STRING_EXTRA
= StringFn(WideStringArg
)