PreviousUpNext

15.4.1046  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

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

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

    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

        package wu =  inline_t::rw_vector_of_one_byte_unts;     # inline_t      is from   src/lib/core/init/built-in.pkg
        package vc =  inline_t::vector_of_chars;
        package ss =  substring;

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

        # The substring type is abstract,
        # so we use a cast to an equivalent type
        # to get around this problem.                           # =8-0   Cursed by ye C gods!!   XXX SUCKO FIXME
        
        to_ss =   inline_t::cast:  ss::Substring -> Substring';


    herein

        fun pack_string (rw_vector_of_one_byte_unts: wu::Rw_Vector, i, substring: ss::Substring):   Void
            =
            {   (to_ss  substring) ->   SS (src, src_start, src_len);
                #
                dst_len =  wu::length  rw_vector_of_one_byte_unts;

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

                cpy (src_start, i, src_len)
                where
                    fun cpy (_, _, 0) =>   ();
                        #
                        cpy (src_index, dst_index, n)
                            =>
                            {   wu::set (rw_vector_of_one_byte_unts, dst_index, inline_t::cast (vc::get (src, src_index)));
                                #
                                cpy (src_index+1, dst_index+1, n - 1);
                            };
                    end;
                end;
            };
    end;
};



## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2013,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext