![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Data Structures | |
| struct | N_STR |
| A box including a string and his lenght. More... | |
Macros | |
| #define | free_nstr(__ptr) |
| free a N_STR structure and set the pointer to NULL | |
| #define | local_strdup(__src_) |
| Do tar(1) matching rules, which ignore a trailing slash? | |
| #define | n_remove_ending_cr(__nstr_var) |
| Remove carriage return (backslash r) if there is one in the last position of the string. | |
| #define | n_replace_cr(__nstr_var, __replacement) |
| Find and replace all occurences of carriage return (backslash r) in the string. | |
| #define | nstrcat(__nstr_dst, __nstr_src) |
| Macro to quickly concatenate two N_STR. | |
| #define | nstrcat_bytes(__nstr_dst, __void_src) |
| Macro to quickly concatenate a '\0' ended byte stream to a N_STR. | |
| #define | nstrprintf(__nstr_var, __format, ...) |
| Macro to quickly allocate and sprintf to N_STR. | |
| #define | nstrprintf_cat(__nstr_var, __format, ...) |
| Macro to quickly allocate and sprintf and cat to a N_STR. | |
| #define | strprintf(__n_var, ...) |
| Macro to quickly allocate and sprintf to a char. | |
| #define | WILDMAT_ABORT -2 |
| Abort code to sped up pattern matching. | |
| #define | WILDMAT_NEGATE_CLASS '^' |
| What character marks an inverted character class? | |
Typedefs | |
| typedef size_t | NSTRBYTE |
| N_STR base unit. | |
Functions | |
| int | _free_nstr (N_STR **ptr) |
| free a N_STR and set the pointer to NULL | |
| N_STR * | char_to_nstr (const char *src) |
| convert a char into a N_STR, shorter version | |
| int | char_to_nstr_ex (const char *from, NSTRBYTE nboct, N_STR **to) |
| convert a char into a N_STR | |
| N_STR * | char_to_nstr_nocopy (char *src) |
| convert a char into a N_STR without copying, shorter version | |
| int | char_to_nstr_nocopy_ex (char *from, NSTRBYTE nboct, N_STR **to) |
| convert a char into a N_STR without copying | |
| int | empty_nstr (N_STR *nstr) |
| reinitialize a nstr | |
| N_STR * | file_to_nstr (char *filename) |
| load a whole file into a N_STR | |
| int | free_nstr_nolog (N_STR **ptr) |
| free a N_STR and set to NULL without logging | |
| void | free_nstr_ptr (void *ptr) |
| free a N_STR without setting the pointer to NULL | |
| void | free_nstr_ptr_nolog (void *ptr) |
| free a N_STR without logging or setting to NULL | |
| int | free_split_result (char ***tab) |
| free a char **tab and set it to NULL | |
| char * | join (char **splitresult, const char *delim) |
| join a split result into a string | |
| N_STR * | n_str_template_expand (const char *tmpl, struct HASH_TABLE *vars) |
| Expand double-brace tokens in a template using a hash table. | |
| N_STR * | n_str_url_encode (const char *src) |
| Percent-encode a string per RFC 3986 (unreserved chars kept). | |
| N_STR * | new_nstr (NSTRBYTE size) |
| create a new string | |
| char * | nfgets (char *buffer, NSTRBYTE size, FILE *stream) |
| N_STR wrapper around fgets. | |
| int | nstr_to_fd (N_STR *str, FILE *out, int lock) |
| write a whole N_STR into an open file descriptor | |
| int | nstr_to_file (N_STR *n_str, char *filename) |
| write a whole N_STR into a file | |
| N_STR * | nstrcat_bytes_ex (N_STR **dest, void *src, NSTRBYTE size) |
| wrapper to nstrcat_ex to concatenate void *data | |
| N_STR * | nstrcat_ex (N_STR **dest, void *src, NSTRBYTE size, int resize_flag) |
| concatenate data inside a N_STR | |
| N_STR * | nstrdup (N_STR *msg) |
| make a copy of a N_STR | |
| N_STR * | nstrprintf_cat_ex (N_STR **nstr_var, const char *format,...) |
| concatenate printf on a N_STR | |
| N_STR * | nstrprintf_ex (N_STR **nstr_var, const char *format,...) |
| printf on a N_STR | |
| int | resize_nstr (N_STR *nstr, size_t size) |
| resize a N_STR | |
| int | scan_dir (const char *dir, LIST *result, const int recurse) |
| get a list of files in a directory | |
| int | scan_dir_ex (const char *dir, const char *pattern, LIST *result, const int recurse, const int mode) |
| get a list of files in a directory, extended N_STR version | |
| int | skipu (const char *string, char toskip, NSTRBYTE *iterator, int inc) |
| skip characters in string until string[iterator] == toskip | |
| int | skipw (const char *string, char toskip, NSTRBYTE *iterator, int inc) |
| skip characters in string while string[iterator] == toskip | |
| char ** | split (const char *str, const char *delim, int empty) |
| return an array of char pointers to the split sections | |
| int | split_count (char **split_result) |
| count split elements | |
| char * | str_replace (const char *string, const char *substr, const char *replacement) |
| return a new string with all occurrences of substr replaced | |
| int | str_sanitize (char *string, const char *mask, const char replacement) |
| in-place substitution of a set of chars by a single one | |
| int | str_sanitize_ex (char *string, const NSTRBYTE string_len, const char *mask, const NSTRBYTE masklen, const char replacement) |
| sanitize a string using a character mask | |
| int | str_to_int (const char *s, int *i, const int base) |
| string to integer, shorter version | |
| int | str_to_int_ex (const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base) |
| string to integer, with error checking | |
| int | str_to_int_nolog (const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base, N_STR **infos) |
| string to integer, with error checking and no logging | |
| int | str_to_long (const char *s, long int *i, const int base) |
| string to long integer, shorter version | |
| int | str_to_long_ex (const char *s, NSTRBYTE start, NSTRBYTE end, long int *i, const int base) |
| string to long integer, with error checking | |
| int | str_to_long_long (const char *s, long long int *i, const int base) |
| string to long long integer, shorter version | |
| int | str_to_long_long_ex (const char *s, NSTRBYTE start, NSTRBYTE end, long long int *i, const int base) |
| string to long long integer, with error checking | |
| int | strcpy_u (const char *from, char *to, NSTRBYTE to_size, char delim, NSTRBYTE *it) |
| copy from string to dest until from[iterator] == delim | |
| int | strlo (const char *string, char *dest) |
| lower case a string | |
| int | strup (const char *string, char *dest) |
| upper case a string | |
| char * | trim (const char *s) |
| trim and put a \0 at the end, return new char * | |
| char * | trim_nocopy (char *s) |
| trim and put a \0 at the end, return new begin pointer | |
| int | wildmat (register const char *text, register const char *p) |
| pattern matching | |
| int | wildmatcase (register const char *text, register const char *p) |
| pattern matching, case insensitive | |
| int | write_and_fit (char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src) |
| write and fit into the char array | |
| int | write_and_fit_ex (char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src, NSTRBYTE src_size, NSTRBYTE additional_padding) |
| write and fit bytes into a dynamically sized buffer | |
| struct N_STR |
A box including a string and his lenght.
| Data Fields | ||
|---|---|---|
| char * | data | the string |
| size_t | length | total allocation (in bytes) of the data buffer, padding included |
| size_t | written | number of meaningful bytes in data, excluding the null terminator; the size including the null terminator is written + 1. |
| #define free_nstr | ( | __ptr | ) |
free a N_STR structure and set the pointer to NULL
Definition at line 203 of file n_str.h.
Referenced by _n_mock_request_clean(), _netw_sni_servername_cb(), add_bytes_to_msg(), addr2line(), avro_encode_container(), avro_file_to_json(), avro_json_to_file(), check_refused(), client_worker_echo(), destroy_data(), expect_canon(), expect_encode(), expect_hex(), expect_resolve(), expect_unified(), file_to_nstr(), get_config_section_value(), get_nb_config_file_sections_entries(), handle_request(), load_config_file(), main(), main(), main(), make_str_from_msg(), manage_client(), mp_part_free(), n_base64_encode(), n_cookiejar_build_header(), n_get_current_dir_hd_serial(), n_json_parse_file(), n_kafka_delete(), n_kafka_dump_unprocessed(), n_kafka_event_destroy_ptr(), n_kafka_load_config(), n_kafka_move_file_to_sended(), n_kafka_new_event_from_file(), n_mock_server_run(), n_popen(), n_proxy_connect_tunnel(), n_proxy_connect_tunnel_ssl(), n_sse_connect(), n_sse_event_clean(), n_str_url_encode(), n_vigenere_cypher(), n_vigenere_decode_file(), n_vigenere_decode_file_qa(), n_vigenere_decode_qa(), n_vigenere_encode_file(), n_vigenere_encode_file_qa(), n_vigenere_encode_qa(), n_vigenere_get_answer(), n_vigenere_get_question(), n_vigenere_quick_decode(), n_vigenere_quick_encode(), n_ws_close(), n_ws_connect(), n_ws_recv(), n_x509_generate_ca(), n_x509_mint_host_cert(), netw_get_ident(), netw_get_string(), netw_pool_add(), netw_pool_remove(), netw_recv_func(), netw_send_func(), nstrcat_ex(), on_send_click(), poll_network_msgs(), run_client(), run_server(), scan_dir_ex(), send_net_datas(), test_decode_roundtrip(), test_replace(), test_scripts(), test_sha256_hex(), test_to_text(), test_token(), unzip4_nstr(), unzip_nstr(), zip4_nstr(), and zip_nstr().
| #define local_strdup | ( | __src_ | ) |
Do tar(1) matching rules, which ignore a trailing slash?
local strdup
Definition at line 79 of file n_str.h.
Referenced by avro_schema_from_cjson(), and main().
| #define n_remove_ending_cr | ( | __nstr_var | ) |
Remove carriage return (backslash r) if there is one in the last position of the string.
| #define n_replace_cr | ( | __nstr_var, | |
| __replacement ) |
Find and replace all occurences of carriage return (backslash r) in the string.
| #define nstrcat | ( | __nstr_dst, | |
| __nstr_src ) |
Macro to quickly concatenate two N_STR.
Definition at line 125 of file n_str.h.
Referenced by main(), and netw_build_http_response().
| #define nstrcat_bytes | ( | __nstr_dst, | |
| __void_src ) |
Macro to quickly concatenate a '\0' ended byte stream to a N_STR.
| #define nstrprintf | ( | __nstr_var, | |
| __format, | |||
| ... ) |
Macro to quickly allocate and sprintf to N_STR.
Definition at line 117 of file n_str.h.
Referenced by avro_encode_container(), get_config_section_value(), get_nb_config_file_sections_entries(), get_nodup_indexed_key(), get_nodup_key(), handle_request(), load_config_file(), main(), main(), n_get_cpu_id(), n_get_current_dir_hd_serial(), n_kafka_dump_unprocessed(), n_kafka_load_config(), n_kafka_move_file_to_sended(), n_kafka_poll(), n_url_build(), n_url_canonicalize(), n_url_resolve(), netw_build_http_response(), netw_pool_add(), netw_pool_remove(), scan_dir_ex(), and str_to_int_nolog().
| #define nstrprintf_cat | ( | __nstr_var, | |
| __format, | |||
| ... ) |
Macro to quickly allocate and sprintf and cat to a N_STR.
Definition at line 121 of file n_str.h.
Referenced by _n_git_diff_print_cb(), main(), main(), n_cookiejar_build_header(), n_popen(), n_sse_connect(), n_str_template_expand(), n_str_url_encode(), n_url_build(), n_url_canonicalize(), n_url_decode(), n_url_resolve(), n_vigenere_get_question(), and test_scripts().
| #define strprintf | ( | __n_var, | |
| ... ) |
Macro to quickly allocate and sprintf to a char.
Definition at line 95 of file n_str.h.
Referenced by dump_nodup_log().
| #define WILDMAT_ABORT -2 |
Abort code to sped up pattern matching.
Special thanks to Lars Mathiesen thori.nosp@m.nn@d.nosp@m.iku.d.nosp@m.k for the ABORT code.
Definition at line 72 of file n_str.h.
Referenced by wildmat(), and wildmatcase().
| #define WILDMAT_NEGATE_CLASS '^' |
What character marks an inverted character class?
Definition at line 74 of file n_str.h.
Referenced by wildmat(), and wildmatcase().
| typedef size_t NSTRBYTE |
| int _free_nstr | ( | N_STR ** | ptr | ) |
| N_STR * char_to_nstr | ( | const char * | src | ) |
convert a char into a N_STR, shorter version
convert a char into a N_STR, shorter version
| src | A char *string to convert |
Definition at line 262 of file n_str.c.
References __n_assert, and char_to_nstr_ex().
Referenced by _n_html_push_link(), _n_mock_parse_request(), _out_finish(), add_strdup_to_msg(), avro_file_to_json(), avro_nstr_avro_to_json(), client_worker_echo(), handle_request(), main(), main(), main(), n_proxy_connect_tunnel(), n_proxy_connect_tunnel_ssl(), n_sitemap_extract_urls(), n_sse_connect(), n_vigenere_quick_decode(), n_vigenere_quick_encode(), on_request(), and run_client().
convert a char into a N_STR
convert a char into a N_STR
| from | A char *string to convert |
| nboct | The size to copy, from 1 octet to nboctet (ustrsizez( from ) ) |
| to | A N_STR pointer who will be Malloced |
Definition at line 239 of file n_str.c.
References __n_assert, _str, Free, LOG_ERR, n_log, and new_nstr().
Referenced by bio_to_nstr(), char_to_nstr(), gz_compress(), n_html_extract_scripts(), n_html_to_text(), n_http_build_multipart(), n_http_inflate(), and npcre_replace().
| N_STR * char_to_nstr_nocopy | ( | char * | src | ) |
convert a char into a N_STR without copying, shorter version
convert a char into a N_STR without copying, shorter version
| src | A char *string to use |
Definition at line 275 of file n_str.c.
References __n_assert, N_STR::data, N_STR::length, new_nstr(), and N_STR::written.
Referenced by _out_finish(), _out_finish(), and n_pretty_json().
convert a char into a N_STR without copying
References file_to_nstr(), N_PRINTF_FORMAT, nstr_to_fd(), nstr_to_file(), and nstrprintf_cat_ex().
| int empty_nstr | ( | N_STR * | nstr | ) |
reinitialize a nstr
reinitialize a nstr
| nstr | the N_STR *str string to empty |
Definition at line 192 of file n_str.c.
References __n_assert, N_STR::data, N_STR::length, and N_STR::written.
Referenced by main().
| N_STR * file_to_nstr | ( | char * | filename | ) |
load a whole file into a N_STR
load a whole file into a N_STR
Be aware of the NSTRBYTE addressing limit (2GB commonly)
| filename | The filename to load inside a N_STR |
Definition at line 295 of file n_str.c.
References __n_assert, N_STR::data, free_nstr, LOG_DEBUG, LOG_ERR, n_log, new_nstr(), and N_STR::written.
Referenced by avro_file_to_json(), avro_json_to_file(), char_to_nstr_nocopy_ex(), handle_request(), main(), main(), n_json_parse_file(), n_kafka_load_config(), n_kafka_new_event_from_file(), n_vigenere_decode_file(), n_vigenere_decode_file_qa(), n_vigenere_encode_file(), and n_vigenere_encode_file_qa().
| int free_nstr_nolog | ( | N_STR ** | ptr | ) |
| void free_nstr_ptr | ( | void * | ptr | ) |
free a N_STR without setting the pointer to NULL
free a N_STR without setting the pointer to NULL
| ptr | A N_STR *object to free |
Definition at line 70 of file n_str.c.
References N_STR::data, and FreeNoLog.
Referenced by _n_html_push_link(), add_bytes_to_msg(), add_nstrdup_to_msg(), add_nstrptr_to_msg(), add_strdup_to_msg(), main(), n_html_extract_scripts(), n_kafka_poll(), n_sitemap_extract_urls(), netw_add_msg(), netw_add_msg_ex(), netw_recv_func(), and scan_dir_ex().
| void free_nstr_ptr_nolog | ( | void * | ptr | ) |
| int free_split_result | ( | char *** | tab | ) |
free a char **tab and set it to NULL
free a char **tab and set it to NULL
| tab | A pointer to a split result to free |
Definition at line 1023 of file n_str.c.
References Free.
Referenced by handle_request(), load_config_file(), main(), n_kafka_delete(), n_kafka_delivery_message_callback(), and split().
| char * join | ( | char ** | splitresult, |
| const char * | delim ) |
join a split result into a string
join a split result into a string
| splitresult | the split result to join |
| delim | The delimiter, one or more characters |
Definition at line 1044 of file n_str.c.
References __n_assert, LOG_ERR, Malloc, and n_log.
Referenced by main(), n_kafka_load_config(), and n_kafka_polling_thread().
| N_STR * n_str_template_expand | ( | const char * | tmpl, |
| struct HASH_TABLE * | vars ) |
Expand double-brace tokens in a template using a hash table.
Tokens not found in vars are left unchanged.
| tmpl | Template string with {{key}} tokens. Must not be NULL. |
| vars | Hash table mapping key to value. May be NULL. |
Definition at line 1690 of file n_str.c.
References ht_get_string(), key, new_nstr(), and nstrprintf_cat.
| N_STR * n_str_url_encode | ( | const char * | src | ) |
Percent-encode a string per RFC 3986 (unreserved chars kept).
Letters, digits and -_.~ are written verbatim; all other bytes become HH. Uses explicit range checks (locale-independent). n_url_encode() in n_network.h is a convenience alias that delegates to this function. See the full parameter contract on the implementation in src/n_str.c.
Percent-encode a string per RFC 3986 (unreserved chars kept).
Letters, digits and the characters '-', '_', '.', '~' are written verbatim. Every other byte is written as HH using upper-case hex. The function is binary-safe in the sense that it never assumes UTF-8 boundaries; it only stops at the terminating NUL of src.
| src | NUL-terminated input string. NULL returns NULL. |
Definition at line 1734 of file n_str.c.
References free_nstr, new_nstr(), and nstrprintf_cat.
Referenced by main(), and n_url_encode().
create a new string
create a new string
| size | Size of the new string. 0 for no allocation. The maximum representable size is rejected: the allocation is size + 1 for the terminator and that sum would wrap to 0, handing back a one-element buffer for a huge string. |
Definition at line 209 of file n_str.c.
References __n_assert, N_STR::data, Free, N_STR::length, LOG_ERR, Malloc, n_log, and N_STR::written.
Referenced by add_bytes_to_msg(), char_to_nstr_ex(), char_to_nstr_nocopy(), file_to_nstr(), handle_request(), main(), main(), n_base64_decode(), n_base64_encode(), n_cookiejar_build_header(), n_git_diff_commits(), n_git_diff_workdir(), n_hex_encode(), n_http_parse_multipart(), n_kafka_load_config(), n_kafka_new(), n_popen(), n_str_template_expand(), n_str_url_encode(), n_url_build(), n_url_canonicalize(), n_url_decode(), n_url_resolve(), n_vigenere_get_answer(), n_vigenere_get_question(), n_vigenere_get_rootkey(), n_ws_connect(), n_ws_recv(), nstrcat_ex(), nstrdup(), nstrprintf_cat_ex(), nstrprintf_ex(), send_net_datas(), test_scripts(), unzip4_nstr(), unzip_nstr(), zip4_nstr(), and zip_nstr().
| char * nfgets | ( | char * | buffer, |
| NSTRBYTE | size, | ||
| FILE * | stream ) |
| int nstr_to_fd | ( | N_STR * | str, |
| FILE * | out, | ||
| int | lock ) |
write a whole N_STR into an open file descriptor
write a whole N_STR into an open file descriptor
| str | The N_STR *content to write down |
| out | An opened FILE *handler |
| lock | a write lock will be put if lock = 1 |
Definition at line 378 of file n_str.c.
References __n_assert, N_STR::data, LOG_ERR, n_log, and N_STR::written.
Referenced by char_to_nstr_nocopy_ex(), and nstr_to_file().
| int nstr_to_file | ( | N_STR * | str, |
| char * | filename ) |
write a whole N_STR into a file
write a whole N_STR into a file
| str | The N_STR *content to write down |
| filename | The destination filename |
Definition at line 431 of file n_str.c.
References __n_assert, _str, LOG_DEBUG, LOG_ERR, n_log, nstr_to_fd(), and N_STR::written.
Referenced by avro_file_to_json(), avro_json_to_file(), char_to_nstr_nocopy_ex(), main(), main(), n_kafka_dump_unprocessed(), n_vigenere_decode_file(), n_vigenere_decode_file_qa(), n_vigenere_encode_file(), and n_vigenere_encode_file_qa().
wrapper to nstrcat_ex to concatenate void *data
wrapper to nstrcat_ex to concatenate void *data
Wrapper to nstrcat_ex, with resize_flag on and a block size one byte higher than size.
| dest | The N_STR **destination (accumulator) |
| data | The data to append |
| size | The number of octet of data we want to append in dest |
Definition at line 1161 of file n_str.c.
References __n_assert, LOG_ERR, n_log, and nstrcat_ex().
concatenate data inside a N_STR
concatenate data inside a N_STR
| dest | The N_STR *destination (accumulator) |
| src | The data to append |
| size | The number of octet of data we want to append in dest |
| resize_flag | Set it to a positive non zero value to allow resizing, or to zero to forbid resizing |
Definition at line 1096 of file n_str.c.
References __n_assert, free_nstr, LOG_ERR, n_log, new_nstr(), and Reallocz.
Referenced by avro_encode_bytes_raw(), avro_encode_container(), avro_encode_datum(), avro_encode_long(), and nstrcat_bytes_ex().
make a copy of a N_STR
make a copy of a N_STR
| str | A N_STR *object to free |
Definition at line 723 of file n_str.c.
References __n_assert, N_STR::data, Free, N_STR::length, LOG_ERR, n_log, new_nstr(), and N_STR::written.
Referenced by add_nstrdup_to_msg(), main(), n_http_decompress_body(), n_vigenere_cypher(), netw_pool_broadcast(), on_send_click(), pick_cert(), and userlist_add_msg_to_ex().
concatenate printf on a N_STR
concatenate printf on a N_STR
| nstr_var | Pointer to a pointer to the N_STR object to allocate/resize and concatenate. |
| format | The format string (like printf). |
| ... | Variadic arguments for formatting. |
Definition at line 1626 of file n_str.c.
References __n_assert, LOG_ERR, n_log, new_nstr(), and resize_nstr().
Referenced by char_to_nstr_nocopy_ex().
printf on a N_STR
printf on a N_STR
| nstr_var | Pointer to a pointer to the N_STR object to allocate/resize. |
| format | The format string (like printf). |
| ... | Arguments to be formatted. |
Definition at line 1574 of file n_str.c.
References __n_assert, LOG_ERR, n_log, new_nstr(), and resize_nstr().
| int resize_nstr | ( | N_STR * | nstr, |
| size_t | size ) |
resize a N_STR
resize a N_STR
Warning: N_STR content will be reset if size = 0 !
| nstr | targeted N_STR *string |
| size | new internal buffer size |
Definition at line 1543 of file n_str.c.
References __n_assert, N_STR::data, Free, N_STR::length, Malloc, Reallocz, and N_STR::written.
Referenced by main(), nstrprintf_cat_ex(), and nstrprintf_ex().
| int scan_dir | ( | const char * | dir, |
| LIST * | result, | ||
| const int | recurse ) |
get a list of files in a directory
get a list of files in a directory
| dir | The directory to scan |
| result | A pointer to a valid LIST for the results |
| recurse | Recursive search if TRUE, directory only if FALSE |
Definition at line 1247 of file n_str.c.
References scan_dir_ex().
Referenced by main().
| int scan_dir_ex | ( | const char * | dir, |
| const char * | pattern, | ||
| LIST * | result, | ||
| const int | recurse, | ||
| const int | mode ) |
get a list of files in a directory, extended N_STR version
get a list of files in a directory, extended N_STR version
| dir | The directory to scan |
| pattern | Pattern that files must follow to figure in the list |
| result | A pointer to a valid LIST for the results |
| recurse | Recursive search if TRUE, directory only if FALSE |
| mode | 0 for a list of char* , 1 for a list of N_STR * |
Definition at line 1260 of file n_str.c.
References N_STR::data, free_nstr, free_nstr_ptr(), list_push(), LOG_ERR, mode, n_log, nstrprintf, scan_dir_ex(), and wildmatcase().
Referenced by scan_dir(), and scan_dir_ex().
| int skipu | ( | const char * | string, |
| char | toskip, | ||
| NSTRBYTE * | iterator, | ||
| int | inc ) |
skip characters in string until string[iterator] == toskip
skip characters in string until string[iterator] == toskip
The new iterator index is automatically stored, returning to it first value if an error append.
| string | a char *string to search in |
| toskip | skipping while char character 'toskip' isnt found |
| iterator | an int iteraor position on the string |
| inc | an int to specify the step of skipping |
Definition at line 801 of file n_str.c.
References __n_assert.
Referenced by load_config_file(), and main().
| int skipw | ( | const char * | string, |
| char | toskip, | ||
| NSTRBYTE * | iterator, | ||
| int | inc ) |
skip characters in string while string[iterator] == toskip
skip characters in string while string[iterator] == toskip
The new iterator index is automatically stored, returning to it first value if an error append.
| string | a char *string to search in |
| toskip | skipping while char character 'toskip' is found |
| iterator | an int iteraor position on the string |
| inc | an int to specify the step of skipping |
Definition at line 754 of file n_str.c.
References __n_assert.
Referenced by main().
| char ** split | ( | const char * | str, |
| const char * | delim, | ||
| int | empty ) |
return an array of char pointers to the split sections
return an array of char pointers to the split sections
| str | The char *str to split |
| delim | The delimiter, one or more characters |
| empty | Empty flag. If 1, then empty delimited areas will be added as NULL entries, else they will be skipped. |
Definition at line 927 of file n_str.c.
References __n_assert, free_split_result(), and Malloc.
Referenced by handle_request(), main(), main(), n_kafka_delivery_message_callback(), and n_kafka_load_config().
| int split_count | ( | char ** | split_result | ) |
count split elements
count split elements
| split_result | A char **result from a split call |
Definition at line 1007 of file n_str.c.
References __n_assert.
Referenced by load_config_file(), main(), n_kafka_delivery_message_callback(), and n_kafka_load_config().
| char * str_replace | ( | const char * | string, |
| const char * | substr, | ||
| const char * | replacement ) |
return a new string with all occurrences of substr replaced
return a new string with all occurrences of substr replaced
Occurrences are found from left to right and do not overlap: after one is replaced, the search goes on after it, never inside the replacement, so replacing "a" by "aa" ends. The occurrences are counted first and the result is allocated once, at its final size.
| string | Original string, not modified |
| substr | String to search; NULL or empty gives a plain copy |
| replacement | Substitution string; NULL gives a plain copy |
Definition at line 1460 of file n_str.c.
References LOG_ERR, Malloc, and n_log.
Referenced by load_config_file(), and main().
| int str_sanitize | ( | char * | string, |
| const char * | mask, | ||
| const char | replacement ) |
in-place substitution of a set of chars by a single one
in-place substitution of a set of chars by a single one
| string | The string to change |
| mask | The caracters to kill |
| replacement | replacement for mask |
Definition at line 1533 of file n_str.c.
References str_sanitize_ex().
Referenced by main().
| int str_sanitize_ex | ( | char * | string, |
| const NSTRBYTE | string_len, | ||
| const char * | mask, | ||
| const NSTRBYTE | masklen, | ||
| const char | replacement ) |
sanitize a string using a character mask
sanitize a string using a character mask
| string | The string to change |
| string_len | Size of the data to treat |
| mask | The caracters to kill |
| masklen | size of mask |
| replacement | replacement for mask |
Definition at line 1510 of file n_str.c.
References __n_assert.
Referenced by str_sanitize().
| int str_to_int | ( | const char * | s, |
| int * | i, | ||
| const int | base ) |
string to integer, shorter version
string to integer, shorter version
| s | String to convert |
| i | A pointer to an integer variable which will receive the value. |
| base | Base for converting values |
Definition at line 560 of file n_str.c.
References str_to_int_ex().
Referenced by main().
string to integer, with error checking
string to integer, with error checking
Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.
| s | String to convert |
| start | Start position of the chunk |
| end | End position of the chunk |
| i | A pointer to an integer variable which will receive the value. |
| base | Base for converting values |
Definition at line 469 of file n_str.c.
References __n_assert, Free, LOG_ERR, Malloc, and n_log.
Referenced by str_to_int().
| int str_to_int_nolog | ( | const char * | s, |
| NSTRBYTE | start, | ||
| NSTRBYTE | end, | ||
| int * | i, | ||
| const int | base, | ||
| N_STR ** | infos ) |
string to integer, with error checking and no logging
string to integer, with error checking and no logging
Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.
| s | String to convert |
| start | Start position of the chunk |
| end | End position of the chunk |
| i | A pointer to an integer variable which will receive the value. |
| base | Base for converting values |
| infos | If not NULL , contain the errors. remember to free the pointer if returned !! |
Definition at line 517 of file n_str.c.
References __n_assert, Free, LOG_ERR, Malloc, n_log, and nstrprintf.
| int str_to_long | ( | const char * | s, |
| long int * | i, | ||
| const int | base ) |
string to long integer, shorter version
string to long integer, shorter version
| s | String to convert |
| i | A pointer to an integer variable which will receive the value. |
| base | Base for converting values |
Definition at line 695 of file n_str.c.
References str_to_long_ex().
Referenced by main().
string to long integer, with error checking
string to long integer, with error checking
Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.
| s | String to convert |
| start | Start position of the chunk |
| end | End position of the chunk |
| i | A pointer to an integer variable which will receive the value. |
| base | Base for converting values |
Definition at line 579 of file n_str.c.
References __n_assert, Free, LOG_DEBUG, LOG_ERR, Malloc, and n_log.
Referenced by str_to_long().
| int str_to_long_long | ( | const char * | s, |
| long long int * | i, | ||
| const int | base ) |
string to long long integer, shorter version
string to long long integer, shorter version
| s | String to convert |
| i | A pointer to an integer variable which will receive the value. |
| base | Base for converting values |
Definition at line 710 of file n_str.c.
References str_to_long_long_ex().
Referenced by main().
| int str_to_long_long_ex | ( | const char * | s, |
| NSTRBYTE | start, | ||
| NSTRBYTE | end, | ||
| long long int * | i, | ||
| const int | base ) |
string to long long integer, with error checking
string to long long integer, with error checking
Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.
| s | String to convert |
| start | Start position of the chunk |
| end | End position of the chunk |
| i | A pointer to an integer variable which will receive the value. |
| base | Base for converting values |
Definition at line 638 of file n_str.c.
References __n_assert, Free, LOG_DEBUG, LOG_ERR, Malloc, and n_log.
Referenced by str_to_long_long().
copy from string to dest until from[iterator] == delim
copy from string to dest until from[iterator] == delim
| from | Source string |
| to | Dest string |
| to_size | the maximum size to write |
| delim | stopping character |
| it | Save of iterator |
Definition at line 891 of file n_str.c.
References __n_assert, LOG_DEBUG, and n_log.
| int strlo | ( | const char * | string, |
| char * | dest ) |
lower case a string
lower case a string
| string | the string to change to lower case |
| dest | the string where storing result |
Definition at line 868 of file n_str.c.
References __n_assert.
Referenced by main().
| int strup | ( | const char * | string, |
| char * | dest ) |
upper case a string
upper case a string
| string | the string to change to upper case |
| dest | the string where storing result |
Definition at line 847 of file n_str.c.
References __n_assert.
Referenced by main().
| char * trim | ( | const char * | s | ) |
trim and put a \0 at the end, return new char *
| s | The string to trim |
Definition at line 152 of file n_str.c.
References __n_assert, and trim_nocopy().
Referenced by main().
| char * trim_nocopy | ( | char * | s | ) |
trim and put a \0 at the end, return new begin pointer
trim and put a \0 at the end, return new begin pointer
| s | The string to trim |
Definition at line 123 of file n_str.c.
References __n_assert.
Referenced by load_config_file(), main(), and trim().
| int wildmat | ( | register const char * | text, |
| register const char * | p ) |
pattern matching
pattern matching
Wildcard pattern matching .
| text | The source text to search |
| p | The text to search, with wildcards |
Definition at line 1325 of file n_str.c.
References last, wildmat(), WILDMAT_ABORT, and WILDMAT_NEGATE_CLASS.
Referenced by main(), and wildmat().
| int wildmatcase | ( | register const char * | text, |
| register const char * | p ) |
pattern matching, case insensitive
pattern matching, case insensitive
Wildcard pattern matching case insensitive.
| text | The source text to search |
| p | The text to search, with wildcards |
Definition at line 1389 of file n_str.c.
References last, WILDMAT_ABORT, WILDMAT_NEGATE_CLASS, and wildmatcase().
Referenced by main(), scan_dir_ex(), and wildmatcase().
write and fit into the char array
write and fit into the char array
Convenience wrapper over write_and_fit_ex with src_size = strlen(src) and 8 bytes of headroom on growth (so a few short appends after a resize don't each trigger their own realloc). Same post-call invariants as write_and_fit_ex (*size = total allocation, *written = bytes excluding '\0').
| dest | pointer to the destination buffer (in/out, may be reallocated) |
| size | pointer to the destination's total allocation, in bytes (in/out) |
| written | pointer to the meaningful-byte count, excluding '\0' (in/out) |
| src | null-terminated source string to append |
Definition at line 1236 of file n_str.c.
References write_and_fit_ex().
Referenced by main().
| int write_and_fit_ex | ( | char ** | dest, |
| NSTRBYTE * | size, | ||
| NSTRBYTE * | written, | ||
| const char * | src, | ||
| NSTRBYTE | src_size, | ||
| NSTRBYTE | additional_padding ) |
write and fit bytes into a dynamically sized buffer
write and fit bytes into a dynamically sized buffer
Post-call invariants (matching N_STR semantics):
If *dest is NULL it is allocated from scratch (with *size, *written reset to 0 first).
| dest | pointer to the destination buffer (in/out, may be reallocated) |
| size | pointer to the destination's total allocation, in bytes (in/out) |
| written | pointer to the meaningful-byte count, excluding '\0' (in/out) |
| src | source bytes to append (read-only, copied verbatim) |
| src_size | number of bytes to copy from src |
| additional_padding | extra bytes to over-allocate at realloc time |
Definition at line 1194 of file n_str.c.
References LOG_ERR, n_log, and Reallocz.
Referenced by _out_mem(), _out_mem(), main(), and write_and_fit().