MLib Alpha 1 API Reference

MLib Alpha 1 API Reference

Ropes

"Ropes" are the MLib's implementation of dynamic strings. They can be easily resized, concatenated, cropped, etc..


M_Rope


  typedef struct M_RopeRec_*     M_Rope;

a handle to a M_RopeRec structure. Ropes are simple dynamic strings they are easy to use for appends, prepends, inserts, etc..



M_RopeRec


  typedef struct M_RopeRec_
  {
    M_String  str;
    M_Size    len;

  } M_RopeRec;

this structure holds the public fields of a M_Rope object.


fields
str

pointer to string bytes. can be NULL

len

rope string length in bytes


m_rope_new


  MLIB_API(M_Rope)      m_rope_new( M_Memory   memory,
                                    M_CString  init,
                                    M_Bool     push );

create a new rope.


input
memory

memory manager handle

init

initial zero-terminated string. can be NULL

push

boolean. when set, the new rope is pushed on top of the cleanup stack

return

new rope handle

throws

m_err_memory_alloc


m_rope_new_c


  MLIB_API(M_Rope)      m_rope_new_c( M_Memory      memory,
                                      const M_Char  init,
                                      M_Bool        push );

create a new single-char rope.


input
memory

memory manager handle

init

initial character, can be '\0'

push

boolean. when set, the new rope is pushed on top of the cleanup stack

return

new rope handle

throws

m_err_memory_alloc


m_rope_new_bound


  MLIB_API(M_Rope)      m_rope_new_bound( M_Memory   memory,
                                          M_CString  init,
                                          M_Size     length,
                                          M_Bool     push );

create a new rope from a bounded string.


input
memory

memory manager handle

init

initial string. can be NULL

length

maximal length of initial string

push

boolean. when set, the new rope is pushed on top of the cleanup stack

return

new rope handle

throws

m_err_memory_alloc


m_rope_destroy


  MLIB_API(void)        m_rope_destroy( M_Rope  rope );

destroy/release a given rope and its character string


input
rope

target rope handle


m_rope_destroy_keep


  MLIB_API(M_String)    m_rope_destroy_keep( M_Rope  rope );

destroy/release a given rope, but keep its character string aliv


input
rope

target rope handle

return

character string. it must be freed by the called through M_FREE or m_mem_free


m_rope_append


  MLIB_API(void)        m_rope_append( M_Rope     target,
                                       M_CString  source );

append a given C string to a given rope


input
rope

target rope handle

source

C-string pointer, can be NULL

throws

m_err_memory_alloc


m_rope_append_bound


  MLIB_API(void)        m_rope_append_bound( M_Rope     target,
                                             M_CString  source,
                                             M_Size     src_len );

append a given bounded string to a given rope


input
rope

target rope handle

source

C-string pointer, can be NULL

src_len

maximal length of the bounded string

throws

m_err_memory_alloc


m_rope_append_c


  MLIB_API(void)        m_rope_append_c( M_Rope  target,
                                         M_Char  c );

append a given character to a given rope


input
rope

target rope handle

source

source character. can be '\0'

throws

m_err_memory_alloc


m_rope_prepend


  MLIB_API(void)        m_rope_prepend( M_Rope     target,
                                        M_CString  source );

prepend a given C string to a rope


input
rope

target rope handle

source

constant C-string pointer, can be NULL

throws

m_err_memory_alloc


m_rope_prepend_bound


  MLIB_API(void)        m_rope_prepend_bound( M_Rope     target,
                                              M_CString  source,
                                              M_Size     src_len );

prepend a given bounded string to a rope


input
rope

target rope handle

source

C-string pointer, can be NULL

src_len

maximal length of the bounded string

throws

m_err_memory_alloc


m_rope_prepend_c


  MLIB_API(void)        m_rope_prepend_c( M_Rope  target,
                                          M_Char  c );

prepend a given character to a rope


input
rope

target rope handle

source

source character. can be '\0'

throws

m_err_memory_alloc


m_rope_insert


  MLIB_API(void)        m_rope_insert( M_Rope     target,
                                       M_Int      pos,
                                       M_CString  source );

insert a given C string within a rope


input
rope

target rope handle

pos

position of source C-string in the rope

source

source C-string

throws

m_err_memory_alloc


m_rope_insert_bound


  MLIB_API(void)        m_rope_insert_bound( M_Rope     target,
                                             M_Int      pos,
                                             M_CString  source,
                                             M_Size     src_len );

insert a given bounded string within a rope


input
rope

target rope handle

pos

position of source string in the rope

source

source bounded string

src_len

maximal length of the source bounded string

throws

m_err_memory_alloc


m_rope_insert_c


  MLIB_API(void)        m_rope_insert_c( M_Rope  target,
                                         M_Int   pos,
                                         M_Char  c );

insert a given character within a rope


input
rope

target rope handle

pos

position of source char in the rope

source

source character. can be '\0'

throws

m_err_memory_alloc


m_rope_remove


  MLIB_API(void)        m_rope_remove( M_Rope   target,
                                       M_Int    start,
                                       M_Int    len );

remove some bytes from a rope


input
rope

target rope handle

start

position of first removable char in rope

len

number of characters to remove

throws

m_err_memory_alloc


m_rope_crop


  MLIB_API(void)        m_rope_crop( M_Rope  target,
                                     M_Int   start,
                                     M_Int   len );

crop a given rope to only a few characters


input
rope

target rope handle

start

position of first character to keep

len

number of characters to keep

throws

m_err_memory_alloc


m_rope_compare


  MLIB_API(M_Int)       m_rope_compare( const M_Rope  rope1,
                                        const M_Rope  rope2 );

compare the content of two rope objects. this function is really useful as a generic comparison function for containers. Otherwise, you'd better directly use m_string_compare on the rope strings..


input
rope1

first rope in comparison

rope2

second rope in comparision

return

-1, 0 or 1, depending on the content of the ropes


m_rope_hash


  MLIB_API(M_Size)      m_rope_hash( const M_Rope  rope );

compute the hash from the content of a rope. this function is to be used as a generic hash for containers. Otherwise, you'd better use m_string_hash directly on the rope string


input
rope

source rope

return

hash value


m_rope_copy


  MLIB_API(M_Rope)      m_rope_copy( const M_Rope  rope,
                                     M_Bool        push );

copy a given rope to another one


input
rope

source rope

push

boolean. when set, the copy is pushed on the cleanup stack

return

handle to new rope


m_rope_push


  MLIB_API(void)        m_rope_push( M_Rope  rope );

push a given rope on top of the cleanup stack


input
rope

rope handle


m_rope_pop


  MLIB_API(void)        m_rope_pop( M_Rope  rope,
                                    M_Bool  keep_it );

pop a given rope from the top of the cleanup stack


input
rope

rope handle

keep_it

boolean. if true, the rope isn't destroyed


generated on Tue Oct 09 23:59:46 2001