The Standard ML Basis Library


The Byte structure


Synopsis

signature BYTE
structure Byte :> BYTE

Bytes are 8-bit integers as provided by the Word8 structure, but serve the dual role as elements composing the extended ASCII character set. The Byte structure provides functions for converting values between these two roles.


Interface

val byteToChar : Word8.word -> char
val charToByte : char -> Word8.word
val bytesToString : Word8Vector.vector -> string
val stringToBytes : string -> Word8Vector.vector
val unpackStringVec : Word8VectorSlice.slice -> string
val unpackString : Word8ArraySlice.slice -> string
val packString : Word8Array.array * int * substring -> unit

Description

byteToChar i
returns the character whose code is i.

charToByte c
returns an 8-bit word holding the code for the character c.

val bytesToString : Word8Vector.vector -> string
val stringToBytes : string -> Word8Vector.vector
These functions convert between a vector of character codes and the corresponding string. Note that these functions do not perform end-of-line, or other character, translations. The semantics of these functions can be defined as follows, although one expects actual implementations will be more efficient:
	    fun bytesToString bv =
		  CharVector.tabulate(
        	    Word8Vector.length bv,
        	    fn i => byteToChar(Word8Vector.sub(bv, i)))
	    fun stringToBytes s =
		  Word8Vector.tabulate(
        	    String.size s,
        	    fn i => charToByte(String.sub(s, i)))
	  
Implementation note:

For implementations where the underlying representation of the Word8Vector.vector and string types are the same, these functions should be constant-time operations.



unpackStringVec slice
returns the string consisting of characters whose codes are held in the vector slice slice.

val unpackString : Word8ArraySlice.slice -> string
returns the string consisting of characters whose codes are held in the array slice slice.

packString (arr, i, s)
puts the substring s into the array arr starting at offset i. It raises Subscript if i < 0 or size s + i > |arr|.

See Also

Char, String, Substring, WORD, Word8, Word8Vector, Word8VectorSlice, Word8Array, Word8ArraySlice

[ Top | Parent | Contents | Index | Root ]

Generated April 12, 2004
Last Modified August 9, 1996
Comments to John Reppy.


This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy.

Copyright © 2004 AT&T and Lucent Technologies. All rights reserved.

Permission is granted for internet users to make one paper copy for their own personal use. Further hardcopy reproduction is strictly prohibited. Permission to distribute the HTML document electronically on any medium other than the internet must be requested from the copyright holders by contacting the editors. Printed versions of the SML Basis Manual are available from Cambridge University Press. To order, please visit www.cup.org (North America) or www.cup.cam.ac.uk (outside North America).