Nilorea Library
C utilities for networking, threading, graphics
n_str.h File Reference

N_STR and string function declaration. More...

#include "n_common.h"
#include "n_list.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <math.h>
#include <fcntl.h>
#include <unistd.h>
#include <inttypes.h>
+ Include dependency graph for n_str.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  N_STR
 A box including a string and his lenght. More...
 

Macros

#define BAD_METACHARS   "/-+&;`'\\\"|*?~<>^()[]{}$\n\r\t "
 list of evil characters More...
 
#define free_nstr(__ptr)
 free a N_STR structure and set the pointer to NULL More...
 
#define local_strdup(__src_)
 local strdup More...
 
#define n_remove_ending_cr(__nstr_var)
 Remove carriage return (backslash r) if there is one in the last position of the string. More...
 
#define n_replace_cr(__nstr_var, __replacement)
 Find and replace all occurences of carriage return (backslash r) in the string. More...
 
#define nstrprintf(__nstr_var, ...)
 Macro to quickly allocate and sprintf to N_STR *. More...
 
#define nstrprintf_cat(__nstr_var, ...)
 Macro to quickly allocate and sprintf and cat to a N_STR *. More...
 
#define resize_nstr(__nstr, new_size)
 Do tar(1) matching rules, which ignore a trailing slash? More...
 
#define strprintf(__n_var, ...)
 Macro to quickly allocate and sprintf to a char *. More...
 
#define WILDMAT_ABORT   -2
 Abort code to sped up pattern matching. More...
 
#define WILDMAT_NEGATE_CLASS   '^'
 What character marks an inverted character class? More...
 

Typedefs

typedef size_t NSTRBYTE
 N_STR base unit. More...
 

Functions

int _free_nstr (N_STR **ptr)
 Free a N_STR structure and set the pointer to NULL. More...
 
N_STRchar_to_nstr (const char *src)
 Convert a char into a N_STR, short version. More...
 
int char_to_nstr_ex (const char *from, NSTRBYTE nboct, N_STR **to)
 Convert a char into a N_STR, extended version. More...
 
N_STRchar_to_nstr_nocopy (char *src)
 Convert a char into a N_STR, direct use of linked source pointer, short version. More...
 
int char_to_nstr_nocopy_ex (char *from, NSTRBYTE nboct, N_STR **to)
 Convert a char into a N_STR, direct use of linked source pointer, extended version. More...
 
int empty_nstr (N_STR *nstr)
 empty a N_STR string More...
 
N_STRfile_to_nstr (char *filename)
 Load a whole file into a N_STR. More...
 
int free_nstr_nolog (N_STR **ptr)
 Free a N_STR structure and set the pointer to NULL. More...
 
void free_nstr_ptr (void *ptr)
 Free a N_STR pointer structure. More...
 
void free_nstr_ptr_nolog (void *ptr)
 Free a N_STR pointer structure. More...
 
int free_split_result (char ***tab)
 Free a split result allocated array. More...
 
char * join (char **splitresult, char *delim)
 join the array into a string More...
 
N_STRnew_nstr (NSTRBYTE size)
 create a new N_STR string More...
 
char * nfgets (char *buffer, NSTRBYTE size, FILE *stream)
 try to fgets More...
 
int nstr_to_fd (N_STR *str, FILE *out, int lock)
 Write a N_STR content into a file. More...
 
int nstr_to_file (N_STR *n_str, char *filename)
 Write a N_STR content into a file. More...
 
int nstrcat (N_STR *dst, N_STR *src)
 Add N_STR *src content to N_STR *dst, resizing it if needed. More...
 
int nstrcat_bytes (N_STR *dest, void *src)
 Append data into N_STR using internal N_STR size and cursor position. More...
 
int nstrcat_bytes_ex (N_STR *dest, void *src, NSTRBYTE size)
 Append data into N_STR using internal N_STR size and cursor position. More...
 
int nstrcat_ex (N_STR *dest, void *src, NSTRBYTE size, int resize_flag)
 Append data into N_STR using internal N_STR size and cursor position. More...
 
N_STRnstrdup (N_STR *msg)
 Duplicate a N_STR. More...
 
int scan_dir (const char *dir, LIST *result, const int recurse)
 Scan a list of directory and return a list of char *file. More...
 
int scan_dir_ex (const char *dir, const char *pattern, LIST *result, const int recurse, const int mode)
 Scan a list of directory and return a list of char *file. More...
 
int skipu (char *string, char toskip, NSTRBYTE *iterator, int inc)
 skip until 'toskip' occurence is found from 'iterator' to the next 'toskip' value. More...
 
int skipw (char *string, char toskip, NSTRBYTE *iterator, int inc)
 skip while 'toskip' occurence is found from 'iterator' to the next non 'toskip' position. More...
 
char ** split (const char *str, const char *delim, int empty)
 split the strings into a an array of char *pointer , ended by a NULL one. More...
 
int split_count (char **split_result)
 Count split elements. More...
 
char * str_replace (const char *string, const char *substr, const char *replacement)
 Replace "substr" by "replacement" inside string taken from http://coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring By Chantra. More...
 
int str_sanitize (char *string, const char *mask, const char replacement)
 clean a string by replacing evil characteres More...
 
int str_sanitize_ex (char *string, const NSTRBYTE string_len, const char *mask, const NSTRBYTE masklen, const char replacement)
 clean a string by replacing evil characteres More...
 
int str_to_int (const char *s, int *i, const int base)
 Helper for string to integer. More...
 
int str_to_int_ex (const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base)
 Helper for string[start to end] to integer. More...
 
int str_to_int_nolog (const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base, N_STR **infos)
 Helper for string[start to end] to integer. More...
 
int str_to_long (const char *s, long int *i, const int base)
 Helper for string to integer. More...
 
int str_to_long_ex (const char *s, NSTRBYTE start, NSTRBYTE end, long int *i, const int base)
 Helper for string[start to end] to long integer. More...
 
int str_to_long_long (const char *s, long long int *i, const int base)
 Helper for string to integer. More...
 
int str_to_long_long_ex (const char *s, NSTRBYTE start, NSTRBYTE end, long long int *i, const int base)
 Helper for string[start to end] to long long integer. More...
 
int strcpy_u (char *from, char *to, NSTRBYTE to_size, char split, NSTRBYTE *it)
 Copy from start to dest until from[ iterator ] == split. More...
 
int strlo (char *string, char *dest)
 Upper case a string. More...
 
int strup (char *string, char *dest)
 Upper case a string. More...
 
char * trim (char *s)
 trim and put a \0 at the end, return new char * More...
 
char * trim_nocopy (char *s)
 trim and zero end the string, WARNING: keep and original pointer to delete the string correctly More...
 
int wildmat (register const char *text, register const char *p)
 Written by Rich Salz rsalz at osf.org, refurbished by me. More...
 
int wildmatcase (register const char *text, register const char *p)
 Written by Rich Salz rsalz at osf.org, refurbished by me. More...
 
int write_and_fit (char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src)
 concatenate a copy of src of size strlen( src ) to dest, starting at dest[ written ], updating written and size variable, allocation of new blocks of (needed size + 512) if resize is needed. More...
 
int write_and_fit_ex (char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src, NSTRBYTE src_size, NSTRBYTE additional_padding)
 concatenate a copy of src of size src_size to dest, starting at dest[ written ], updating written and size variable, allocation of new blocks of (needed size + additional_padding ) if resize is needed. More...
 

Detailed Description

N_STR and string function declaration.

Author
Castagnier Mickael
Version
2.0
Date
05/02/14

Definition in file n_str.h.

Macro Definition Documentation

◆ BAD_METACHARS

#define BAD_METACHARS   "/-+&;`'\\\"|*?~<>^()[]{}$\n\r\t "

list of evil characters

Definition at line 12 of file n_str.h.