Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Tracker SCM

SCM Repository

[smlnj] View of /sml/trunk/src/system/Basis/Implementation/byte.sml
ViewVC logotype

View of /sml/trunk/src/system/Basis/Implementation/byte.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1350 - (download) (annotate)
Fri Sep 5 21:34:27 2003 UTC (19 years ago) by mblume
File size: 1636 byte(s)
a lot of Basis hacking, among other things adding slices
(* byte.sml
 *
 * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
 *
 *)

structure Byte : BYTE =
  struct
(*
    val chr     : Word8.word -> char = InlineT.cast
    val ord     : char -> Word8.word = InlineT.cast
*)

    val byteToChar : Word8.word -> char = InlineT.cast
    val charToByte : char -> Word8.word = InlineT.cast

    val bytesToString : Word8Vector.vector -> string = InlineT.cast
    val stringToBytes : string -> Word8Vector.vector = InlineT.cast

(*
    val vectorToString : (Word8Vector.vector * int * int) -> string
	  = InlineT.cast CharVector.extract
    val arrayToString : (Word8Array.array * int * int) -> string
	  = InlineT.cast CharArray.extract
*)

    fun unpackStringVec (v, start, olen) =
	StringImp.extract (bytesToString v, start, olen)
    fun unpackString (a, start, olen) =
	bytesToString
	    (Word8ArraySlice.vector (Word8ArraySlice.slice (a, start, olen)))


    local
    (* the substring type is abstract, so we use a cast to an equivalent type
     * to get around this problem.
     *)
      datatype substring' = SS of (string * int * int)
      val toSS : Substring.substring -> substring' = InlineT.cast
      structure A = InlineT.Word8Array
      structure V = InlineT.CharVector
    in
    fun packString (arr, i, ss) = let
	  val SS(src, srcStart, srcLen) = toSS ss
	  val dstLen = A.length arr
	  fun cpy (_, _, 0) = ()
	    | cpy (srcIndx, dstIndx, n) = (
		A.update (arr, dstIndx, InlineT.cast(V.sub(src, srcIndx)));
		cpy (srcIndx+1, dstIndx+1, n-1))
	  in
	    if (i < 0) orelse (i > dstLen-srcLen) then raise Subscript else ();
	    cpy (srcStart, i, srcLen)
	  end
    end

  end



root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0