cstring

Lightweight string library for C
git clone git://git.margiolis.net/cstring.git
Log | Files | Refs | README | LICENSE

commit 0190c79fa1c2b92ca9007610b9895ab00d61a7db
parent 1f1d53a300efbdeb73f56545976590d50a1a3357
Author: Christos Margiolis <christos@margiolis.net>
Date:   Fri, 13 May 2022 04:26:05 +0300

make manpage unreadable

Diffstat:
Mcstring.3 | 84++++++++++++++++++++-----------------------------------------------------------
1 file changed, 21 insertions(+), 63 deletions(-)

diff --git a/cstring.3 b/cstring.3 @@ -1,5 +1,5 @@ .Dd cstring\-VERSION -.Dt cstring 3 +.Dt CSTRING 3 .Sh NAME .Nm cstring .Nd A simple and lightweight string library for C inspired by C++'s @@ -14,7 +14,6 @@ The .Nm library offers a lightweight and fast way to manage strings with a wide range of useful functions. - .Bl -tag -width Ds typedef struct _cstring { size_t len; /* string length */ @@ -25,10 +24,9 @@ CSTRING_SORT_DESCENDING 0x02 /* sort in descending order */ CSTRING_SORT_CALLBACK 0x04 /* sort using a callback function */ CSTRING_SORT_REST 0x10 /* sort the rest of the array */ } cstring; - .It typedef\ int\ (*cstring_sort_callback)(const void *, const void *); Used in sort functions. - +.El .Sh USAGE You must .Ar always @@ -49,197 +47,157 @@ If a function requires a you can access the .Ar .str field and pass it to the function. - .Sh FUNCTIONS .Bl -tag -width Ds .It void Fn cstring_create "const char *s" Instanciates and initializes a .Ar cstring object. - .It void Fn cstring_delete "cstring *cs" Deallocate string. - .It void Fn cstring_assign "cstring *cs" "const char *s" Assign a new string to current string. - .It void Fn cstring_insert "cstring *cs" "const char *s" "size_t i" Insert at a specific index. - .It void Fn cstring_append "cstring *cs" "const char *s" Append to end of string. - .It void Fn cstring_prepend "cstring *cs" "const char *s" Prepend to beginning of string. - .It void Fn cstring_erase "cstring *cs" "size_t pos" "size_t len" Erase a portion of the string. - .It void Fn cstring_erase_matching "cstring *cs" "const char *s" Erase first match from string. - .It void Fn cstring_erase_all_matching "cstring *cs" "const char *s" Erase all matches from string. - .It void Fn cstring_trim "cstring *cs" "const char *s" Trim characters from string. - .It void Fn cstring_push_back "cstring *cs" "char c" Add a character at the end of the string. - .It void Fn cstring_pop_back "cstring *cs" Remove the last character in the string. - .It void Fn cstring_replace_char "cstring *cs" "size_t i" "char c" Replace character at a specific index. - .It void Fn cstring_replace_str "cstring *cs" "const char *s" "size_t pos" "size_t olen" Replace portion of the string. .Ar olen -is the length of the old string. An example use could be: +is the length of the old string. +An example use could be: .br .Fn cstring_replace_str "&string" "new_word" "cstring_find(&s, old_word)" "old_word_len" - .It cstring Fn cstring_substr "cstring *cs" "size_t pos" "size_t len" Extract a substring from current string. - .It void Fn cstring_swap "cstring *lhs" "cstring *rhs" Swap contents of two strings. - .It void Fn cstring_sort "cstring *cs" "size_t len" "int flags" "cstring_sort_callback callback" -Sort an array of cstrings. If you want to use the builtin comparison pass +Sort an array of cstrings. +If you want to use the builtin comparison pass .Ar NULL -in the last argument. In case you want to use your own callback use the +in the last argument. +In case you want to use your own callback use the .Ar CSTRING_SORT_CALLBACK flag and pass your own callback function in the last argument. You can also combine flags using the bitwise OR operator. - .It void Fn cstring_sort_partial "cstring *cs" "size_t pos" "size_t len" "int flags" "cstring_sort_callback callback" Like .Fn cstring_sort but for specified part of an array. - .It void Fn cstring_sort_chars "cstring *cs" "int flags" "cstring_sort_callback callback" -Sort a cstring's contents. If you want to use the builtin comparison pass +Sort a cstring's contents. +If you want to use the builtin comparison pass .Ar NULL -in the last argument. In case you want to use your own callback use the +in the last argument. +In case you want to use your own callback use the .Ar CSTRING_SORT_CALLBACK flag and pass your own callback function in the last argument. You can also combine flags using the bitwise OR operator. - .It void Fn cstring_sort_chars_partial "cstring *cs" "size_t pos" "size_t len" "int flags" "cstring_sort_callback callback" Like .Fn cstring_sort_chars but for specified part of string. - .It void Fn cstring_shrink_to_fit "cstring *cs" Reduce string's capacity to its size. - .It void Fn cstring_clear "cstring *cs" Erase the whole string. - .It size_t Fn cstring_find "const cstring *cs" "const char *s" Find first occurence of a pattern in string. - .It size_t Fn cstring_rfind "const cstring *cs" "const char *s" Find last occurence of a pattern in string. - .It size_t Fn cstring_find_first_of "const cstring *cs" "const char *s" Find first occurence of specified characters in string. - .It size_t Fn cstring_find_first_not_of "const cstring *cs" "const char *s" Find the first character that does not match any of the specified characters. - .It size_t Fn cstring_find_last_of "const cstring *cs" "const char *s" Find last occurence of specified characters in string. - .It size_t Fn cstring_find_last_not_of "const cstring *cs" "const char *s" Find the last character that does not match any of the specified characters. - .It char Fn cstring_front "const cstring *cs" Returns the first character of the string. - .It char Fn cstring_back "const cstring *cs" Returns the last character of the string. - .It int Fn cstring_empty "const cstring *cs" Check to see if the string is empty. - .It int Fn cstring_starts_with_str "const cstring *cs" "const char *s" Check to see if string begins with .Ar s - .It int Fn cstring_ends_with_str "const cstring *cs" "const char *s" Check to see if string ends with .Ar s - .It int Fn cstring_starts_with_char "const cstring *cs" "char c" Check to see if string starts with .Ar c - .It int Fn cstring_ends_with_char "const cstring *cs" "char c" Check to see if string ends with .Ar c - .It void Fn *cstring_data "const cstring *cs" Get string's content in raw bytes. - .It char Fn *cstring_copy "const char *s" Make a copy of a given .Ar const\ char\ * - .It void Fn cstring_resize "cstring *cs" "size_t newcapacity" Resize the .Ar str array inside a given .Ar cstring struct. - .It cstring Fn *cstring_getline "FILE *fd" "cstring *cs" "char delim" Read a line from a .Ar FILE -stream. Similar behavior to +stream. +Similar behavior to .Ar stdio's\ getline - .It int Fn cstring_equal "const cstring *lhs" "const cstring *rhs" Check if lhs == rhs - .It int Fn cstring_greater "const cstring *lhs" "const cstring *rhs" Check if lhs > rhs - .It int Fn cstring_greater_or_equal "const cstring *lhs" "const cstring *rhs" Check if lhs >= rhs - .It int Fn cstring_less "const cstring *lhs" "const cstring *rhs" Check if lhs < rhs - .It int Fn cstring_less_or_equal "const cstring *lhs" "const cstring *rhs" Check if lhs <= rhs - +.El .Sh MACROS .Bl -tag -width Ds .It Fn CSTRING_OUT_OF_BOUNDS "len" "pos" Check if .Ar pos is out of bounds (pos > len). - .It Fn CSTRING_ARR_LEN "x" -Determine an array's length. The macro must be called in the same function -the array is declared. - +Determine an array's length. +The macro must be called in the same function the array is declared. .It Fn CSTRING_MALLOC "ptr" "size" Allocate memory with error cheking. - +.El .Sh CONSTANTS .Bl -tag -width Ds .It CSTRING_NPOS This constant signifies that a pattern hasn't been found inside -the string. Its value is -1. - +the string. +Its value is -1. .It CSTRING_INIT_EMPTY Used with .Fn cstring_create in case the string is to be initliazed as empty. - +.El .Sh AUTHORS .An Christos Margiolis Aq Mt christos@margiolis.net