1 (* Copyright (C
) 1999-2006 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 val byteToChar
= Primitive
.Char8
.idFromWord8
13 val bytesToString
= Primitive
.String8
.idFromWord8Vector
o Word8Vector
.toPoly
15 val charToByte
= Primitive
.Char8
.idToWord8
17 fun packString (a
: Word8Array
.array
, i
: int, s
: substring
): unit
=
19 (Substring
.size s
, fn j
=>
20 Word8Array
.update (a
, i
+ j
, charToByte (Substring
.sub (s
, j
))))
22 val stringToBytes
= Word8Vector
.fromPoly
o Primitive
.String8
.idToWord8Vector
25 fun make (length
, sub
) s
=
26 String.tabulate (length s
, fn i
=> byteToChar (sub (s
, i
)))
28 val unpackString
= make (Word8ArraySlice
.length
, Word8ArraySlice
.sub
)
29 val unpackStringVec
= make (Word8VectorSlice
.length
, Word8VectorSlice
.sub
)