The Byte 구조

The Byte 구조

바이트(Byte)는 Word8 구조가 제공하는 8비트 정수지만, 확장 ASCII 문자 집합을 구성하는 요소라는 이중 역할도 해요. Byte 구조는 이 두 역할 사이에서 값을 변환하는 함수를 제공해요.

출처: 문서

본문

시놉시스 (Synopsis)

signature BYTE
structure Byte :> BYTE

인터페이스 (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

코드가 i인 문자를 돌려줘요.

charToByte c

문자 c의 코드를 담은 8비트 워드를 돌려줘요.

val bytesToString : Word8Vector.vector -> string
val stringToBytes : string -> Word8Vector.vector

이 함수들은 문자 코드 벡터와 해당 문자열 사이를 변환해요. 이 함수들은 줄바꿈이나 다른 문자 변환을 수행하지 않는다는 점에 주의해요. 이 함수들의 의미론은 다음과 같이 정의할 수 있는데, 실제 구현은 더 효율적일 거예요. 구현 참고: Word8Vector.vectorstring 타입의 밑에 깔린 표현이 같은 구현에서는 이 함수들이 상수 시간 연산이어야 해요.

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)))

unpackStringVec slice

벡터 슬라이스 slice에 담긴 코드를 갖는 문자들로 이루어진 문자열을 돌려줘요.

val unpackString : Word8ArraySlice.slice -> string

배열 슬라이스 slice에 담긴 코드를 갖는 문자들로 이루어진 문자열을 돌려줘요.

packString (arr, i, s)

부분 문자열 s를 오프셋 i에서 시작해 배열 arr에 넣어요. i < 0이거나 size s + i > |arr|이면 Subscript를 발생시켜요.

더 알아보기 (Learn more)

  • [ 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).