Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh |
2 | * Jagannathan, and Stephen Weeks. | |
3 | * Copyright (C) 1997-2000 NEC Research Institute. | |
4 | * | |
5 | * MLton is released under a BSD-style license. | |
6 | * See the file MLton-LICENSE for details. | |
7 | *) | |
8 | ||
9 | structure Byte: BYTE = | |
10 | struct | |
11 | val byteToChar = Primitive.Char8.idFromWord8 | |
12 | ||
13 | val bytesToString = Primitive.String8.idFromWord8Vector o Word8Vector.toPoly | |
14 | ||
15 | val charToByte = Primitive.Char8.idToWord8 | |
16 | ||
17 | fun packString (a: Word8Array.array, i: int, s: substring): unit = | |
18 | Natural.foreach | |
19 | (Substring.size s, fn j => | |
20 | Word8Array.update (a, i + j, charToByte (Substring.sub (s, j)))) | |
21 | ||
22 | val stringToBytes = Word8Vector.fromPoly o Primitive.String8.idToWord8Vector | |
23 | ||
24 | local | |
25 | fun make (length, sub) s = | |
26 | String.tabulate (length s, fn i => byteToChar (sub (s, i))) | |
27 | in | |
28 | val unpackString = make (Word8ArraySlice.length, Word8ArraySlice.sub) | |
29 | val unpackStringVec = make (Word8VectorSlice.length, Word8VectorSlice.sub) | |
30 | end | |
31 | end |