ATSLIB/libats/stringbuf

This package implements string buffers that can grow or shrink. A typical use of such a buffer is for turning a value into some form of string representation (stringization).


  • stringbuf
  • stringbuf_vtype
  • stringbuf$recapacitize
  • stringbuf_make_nil
  • stringbuf_free
  • stringbuf_getfree_strnptr
  • stringbuf_get_size
  • stringbuf_get_capacity
  • stringbuf_insert_char
  • stringbuf_insert_string
  • stringbuf_insert_strlen
  • stringbuf_insert_bool
  • stringbuf_insert_int
  • stringbuf_insert_uint
  • stringbuf_insert_lint
  • stringbuf_insert_ulint
  • stringbuf_reset_capacity
  • stringbuf_truncate
  • stringbuf_truncout
  • stringbuf_truncout_all

  • stringbuf

    Synopsis

    vtypedef stringbuf = stringbuf_vtype

    stringbuf_vtype

    Synopsis

    absvtype stringbuf_vtype = ptr

    stringbuf$recapacitize

    Synopsis

    fun{} stringbuf$recapacitize ((*void*)): int

    Description

    The value returned by this function determines whether the capacity of a string buffer is allowed to be expanded automatically if needed.

    stringbuf_make_nil

    Synopsis

    overload stringbuf_make_nil with stringbuf_make_nil_int
    overload stringbuf_make_nil with stringbuf_make_nil_size

    Description

    Given a size m, this function returns a string buffer of capacity m and size 0.

    stringbuf_free

    Synopsis

    fun{}
    stringbuf_free (sbf: stringbuf):<!wrt> void

    Description

    This function frees a given string buffer.

    stringbuf_getfree_strnptr

    Synopsis

    fun{}
    stringbuf_getfree_strnptr
      (sbf: stringbuf, n: &size_t? >> size_t(n)):<!wrt> #[n:nat] strnptr(n)

    Description

    This function returns the string associated with a given string buffer after freeing the buffer, and ot stores the length of the returned string in its second (call-by-reference) parameter.

    stringbuf_get_size

    Synopsis

    fun{}
    stringbuf_get_size (sbf: !stringbuf):<> size_t

    Description

    Given a string buffer, this function returns its current size, that is, the number of characters stored in the buffer.

    stringbuf_get_capacity

    Synopsis

    fun{}
    stringbuf_get_capacity (sbf: !stringbuf):<> size_t

    Description

    Given a string buffer, this function returns its current capacity, that is, the maximal number of characters that can be stored in the buffer.

    stringbuf_insert_char

    Synopsis

    fun{}
    stringbuf_insert_char (!stringbuf, x: charNZ): int

    Description

    This function inserts a non-null character into a given string buffer. If the character is inserted, then 1 is returned. Otherwise, 0 is returned (due to the buffer being full but not allowed to recapacitize).

    stringbuf_insert_string

    Synopsis

    fun{}
    stringbuf_insert_string (!stringbuf, x: string): int

    Description

    This function inserts a string into a given string buffer. If the string is inserted, then the length of the string is returned. Otherwise, 0 is returned.

    stringbuf_insert_strlen

    Synopsis

    fun{}
    stringbuf_insert_strlen{n:int} (!stringbuf, string(n), size_t(n)): int

    Description

    This function is a slight variant of stringbuf_insert_string.

    stringbuf_insert_bool

    Synopsis

    fun{}
    stringbuf_insert_bool (sbf: !stringbuf, x: bool): int

    Description

    Given a string buffer and a boolean, this function inserts a string representation of the boolean into the buffer.

    stringbuf_insert_int

    Synopsis

    fun{}
    stringbuf_insert_int (sbf: !stringbuf, x: int): int

    Description

    Given a string buffer and an integer, this function inserts a string representation of the integer into the buffer.

    stringbuf_insert_uint

    Synopsis

    fun{}
    stringbuf_insert_uint (sbf: !stringbuf, x: uint): int

    Description

    This function is a slight variant of stringbuf_insert_int.

    stringbuf_insert_lint

    Synopsis

    fun{}
    stringbuf_insert_lint (sbf: !stringbuf, x: lint): int

    Description

    This function is a slight variant of stringbuf_insert_int.

    stringbuf_insert_ulint

    Synopsis

    fun{}
    stringbuf_insert_ulint (sbf: !stringbuf, x: ulint): int

    Description

    This function is a slight variant of stringbuf_insert_int.

    stringbuf_reset_capacity

    Synopsis

    fun{}
    stringbuf_reset_capacity
      (sbf: !stringbuf, m2: sizeGte(1)):<!wrt> bool(*done/ignored*)

    Description

    Given a string buffer and a size m2, this function resets the capacity of the buffer to m2. Note that m2 is expected to be greater than or equal to the current size of the buffer for otherwise this function returns false to indicate the capacity of the buffer is not reset.

    stringbuf_truncate

    Synopsis

    fun{}
    stringbuf_truncate
      (sbf: !stringbuf, n2: size_t):<!wrt> bool(*done/ignored*)

    Description

    Given a stringbuf-value sbf and an integer n2, if n2 is less than the current size of the buffer associated with sbf, then the function resets the size of the buffer to n2. Otherwise, the function makes no change.

    stringbuf_truncout

    Synopsis

    fun{}
    stringbuf_truncout
      (sbf: !stringbuf, n2: size_t):<!wrt> Strptr0

    Description

    This function is like stringbuf_trunout except that it returns a linear string representing the truncated portion of a given stringbuf-value.

    stringbuf_truncout_all

    Synopsis

    fun{}
    stringbuf_truncout_all (sbf: !stringbuf):<!wrt> Strptr1

    Description

    This function is just the special case of stringbuf_truncout where the second passed argument equals 0.
    This page is created with ATS by Hongwei Xi and also maintained by Hongwei Xi. SourceForge.net Logo