libk  Diff

Differences From Artifact [8ba3da6088]:

To Artifact [b3e2b4c4d7]:


     2      2   
     3      3   **kstr** is the libk string library. it uses the **short** naming convention with the glyph `s`. **kstr** implies `#include <k/mem.h>`.
     4      4   
     5      5   ## types
     6      6   
     7      7   ### struct kstr
     8      8   `struct kstr` is a structure for holding pascal strings (length-prefixed strings). it is the basic libk string type. **note:** if `ptr.ref` ≠ NULL and `sz` = 0, the string's length is unknown and should be calculated by any function that operates on a kstr, storing the result in the object if possible.
     9         - * `size_t sz` - length of string, excluding any null terminator
            9  + * `sz size` - length of string, excluding any null terminator
    10     10    * `kmptr ptr` - pointer to string in memory
    11     11   
    12     12   ### struct ksraw
    13     13   `struct ksraw` is like `kstr` except it uses raw `char` pointers instead of a `kmptr`.
    14         - * `size_t sz` - length of string, excluding any null terminator
           14  + * `sz size` - length of string, excluding any null terminator
    15     15    * `char* ptr` - pointer to string in memory
    16     16   
    17     17   ### struct ksbuf
    18     18   `struct ksbuf` is a structure used to hold buffers.
    19         - * `size_t sz` - maximum size of buffer, including any null terminator
           19  + * `sz size` - maximum size of buffer, including any null terminator
    20     20    * `char* buf` - region of memory to store buffer in
    21     21    * `ksalloc strat` - allocation strategy
    22     22    * `kmkind rule` - kind of allocator to use. only needs to be set if `where` is NULL. see [kmem](../kmem/kmem.md).
    23     23    * `kmcell* where` - where to allocate the object, in case of pool or tree allocation.
    24     24   
    25     25   ### struct kschain
    26     26   `struct kschain` is a structure used for string accumulators that works by aggregating pointers to strings, instead of copying the strings themselves.
    27     27    * `kschain_kind kind` - kind of chain
    28     28    * `kmkind rule` - kind of allocation to use if `kind` ≠ `kschain_kind_linked`
    29     29    * `pstr* ptrs` - pointer to pointer list
    30         - * `size_t ptrc` - number of pointers
    31         - * `size_t sz` - total amount of space in `ptrs`
           30  + * `sz ptrc` - number of pointers
           31  + * `sz size` - total amount of space in `ptrs`
    32     32   
    33     33   #### enum kschain_kind
    34     34    * `kschain_kind_block` - occupies a single block of memory
    35     35    * `kschain_kind_linked` - uses a linked list, allocated and deallocated as necessary
    36     36   
    37     37   ### enum ksalloc
    38     38   `enum ksalloc` is an enumerator that tells libk what strategy to use when filling a `ksbuf` or `kschain` struct.
................................................................................
    61     61   	char* src = <...>;
    62     62   	kmbuf buf = { sizeof mem, &mem, kmkind_none };
    63     63       kstr chain[] = {
    64     64   		Kstr("<a href=\""), { 0, src }, Kstr("\">"),
    65     65   			ksref(text),
    66     66   		Kstr("</a>")
    67     67   	};
    68         -	char* html = kscomp([Kmsz(chain)](../kmem/kmem.md), chain, &buf);
           68  +	char* html = kscomp(Kmsz(chain), chain, &buf);
    69     69   
    70     70   kscomp will only calculate the length of individual strings if they are not already known. when it needs to calculate the length of a string, it will store that length in the original array so repeated calls can be made without needing to repeatedly calculate the lengths. this is not always desirable, so the variant `kscompc` exists, which is exactly the same as `kscomp` in every respect except that `chain` is not altered in any way.
    71     71   
    72     72   ### macros
    73     73   if `KFclean` is not set when <k/str.h> is included, the following macros are defined.
    74     74   
    75     75    * `Kstr(string)` - the compile-time equivalent to `kstr()`. `Kstr` takes a literal string and inserts the text `{ sizeof (string), string }` into the document, suitable for initializing a kstr.