PreviousUpNext

15.4.1047  src/lib/std/src/byte.pkg

## byte.pkg

# Compiled by:
#     src/lib/std/src/standard-core.sublib

###               "Cooking is like love. It should be
###                entered into with abandon or not at all."
###
###                           -- Harriet Van Horne



package   byte
: (weak)  Byte                                  # Byte          is from   src/lib/std/src/byte.api
{                                               # inline_t      is from   src/lib/core/init/built-in.pkg

    my byte_to_char:  one_byte_unt::Unt -> Char = inline_t::cast;
    my char_to_byte:  Char -> one_byte_unt::Unt = inline_t::cast;

    my bytes_to_string:  vector_of_one_byte_unts::Vector -> String = inline_t::cast;
    my string_to_bytes:  String -> vector_of_one_byte_unts::Vector = inline_t::cast;

    unpack_string_vector =  bytes_to_string o    vector_slice_of_one_byte_unts::to_vector;
    unpack_string        =  bytes_to_string o rw_vector_slice_of_one_byte_unts::to_vector;

    stipulate
        # The substring type is abstract,
        # so we use a cast to an equivalent type
        # to get around this problem.

        Substring' = SS  ((String, Int, Int));

        my to_ss:  substring::Substring -> Substring' = inline_t::cast;

        package a= inline_t::rw_vector_of_one_byte_unts;        # inline_t      is from   src/lib/core/init/built-in.pkg
        package v = inline_t::vector_of_chars;

    herein

        fun pack_string (arr, i, ss)
            =
            {
                my SS (src, src_start, src_len)
                    =
                    to_ss ss;

                dst_len = a::length arr;

                fun cpy (_, _, 0)
                        =>
                        ();

                    cpy (src_index, dst_index, n)
                        =>
                        {
                            a::set (arr, dst_index, inline_t::cast (v::get (src, src_index)));

                            cpy (src_index+1, dst_index+1, n - 1);
                        };
                end;

                if  (i < 0
                or   i > dst_len-src_len
                )
                     raise exception SUBSCRIPT;
                fi;

                cpy (src_start, i, src_len);
              };
    end;
};



## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2012,
## released under Gnu Public Licence version 3.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext