koliseo 0.4.8
Loading...
Searching...
No Matches
kls_gulp.h File Reference
#include "koliseo.h"
#include "ctype.h"

Go to the source code of this file.

Data Structures

struct  Kstr
 

Macros

#define KSTR(c_lit)
 
#define KSTR_NULL   kstr_new(NULL, 0)
 
#define Kstr_Fmt   "%.*s"
 Format macro for a Kstr.
 
#define Kstr_Arg(kstr)
 Format matching macro for a Kstr.
 
#define ONEGB_DEC_INT   1073741824
 Defines a one GB size as decimal integer representation.
 
#define GULP_MAX_FILE_SIZE   ONEGB_DEC_INT
 Defines max size allowed for a file passed to KLS_GULP_FILE().
 
#define Gulp_Res_Fmt   "%s"
 Format macro for a Gulp_Res.
 
#define Gulp_Res_Arg(gr)
 Format matching macro for a Gulp_Res.
 
#define KLS_GULP_FILE(kls, filepath)
 
#define KLS_GULP_FILE_KSTR(kls, filepath)
 

Typedefs

typedef struct Kstr Kstr
 
typedef enum Gulp_Res Gulp_Res
 Defines possible results for kls_gulp_file_sized().
 

Enumerations

enum  Gulp_Res {
  GULP_FILE_OK =0 , GULP_FILE_NOT_EXIST , GULP_FILE_TOO_LARGE , GULP_FILE_READ_ERROR ,
  GULP_FILE_CONTAINS_NULLCHAR , GULP_FILE_KLS_NULL , TOT_GULP_RES
}
 Defines possible results for kls_gulp_file_sized(). More...
 

Functions

Kstr kstr_new (const char *str, size_t len)
 Returns a new Kstr with the passed args set.
 
Kstr kstr_from_c_lit (const char *c_lit)
 Returns a new Kstr from the passed null-terminated string.
 
bool kstr_eq (Kstr left, Kstr right)
 Checks if the two passed Kstr have exactly equal data.
 
bool kstr_eq_ignorecase (Kstr left, Kstr right)
 Checks if the two passed Kstr have equal data, ignoring case.
 
Kstr kstr_cut_l (Kstr *k, size_t n)
 Cuts the passed Kstr by up to n chars, from the left.
 
Kstr kstr_cut_r (Kstr *k, size_t n)
 Cuts the passed Kstr by up to n chars, from the right.
 
Kstr kstr_trim_left (Kstr kstr)
 Returns a new Kstr after removing heading spaces from the passed one.
 
Kstr kstr_trim_right (Kstr kstr)
 Returns a new Kstr after removing trailing spaces from the passed one.
 
Kstr kstr_trim (Kstr kstr)
 Returns a new Kstr after removing heading and trailing spaces from the passed one.
 
bool kstr_indexof (Kstr k, char c, int *idx)
 Checks if passed Kstr contains the passed char, and if so, sets the value pointed by idx to the first occurrence.
 
Kstr kstr_token (Kstr *k, char delim)
 Scans the passed Kstr and cuts it up to the first occurrence of passed char, even if it is not present.
 
bool kstr_try_token (Kstr *k, char delim, Kstr *part)
 Scans the first passed Kstr and if the passed char is present, the old Kstr is set to second pointer and the first one is cut at the first occurrence of it.
 
Kstr kstr_token_kstr (Kstr *k, Kstr delim)
 
const char * string_from_Gulp_Res (Gulp_Res g)
 Return a constant string for the passed Gulp_Res.
 
char * kls_gulp_file_sized (Koliseo *kls, const char *filepath, Gulp_Res *err, size_t max_size)
 Tries mapping the passed file on the Koliseo.
 
char * try_kls_gulp_file (Koliseo *kls, const char *filepath, size_t max_size)
 Tries mapping the passed file on the Koliseo.
 
Kstrkls_gulp_file_sized_to_kstr (Koliseo *kls, const char *filepath, Gulp_Res *err, size_t max_size, bool allow_nullchar)
 Tries mapping the passed file on the Koliseo.
 
Kstrtry_kls_gulp_file_to_kstr (Koliseo *kls, const char *filepath, size_t max_size, bool allow_nullchar)
 Tries mapping the passed file on the Koliseo.
 

Variables

const char * gulp_res_names [TOT_GULP_RES+1]
 String array for representations of Gulp_Res.
 

Macro Definition Documentation

◆ GULP_MAX_FILE_SIZE

#define GULP_MAX_FILE_SIZE   ONEGB_DEC_INT

Defines max size allowed for a file passed to KLS_GULP_FILE().

Use try_kls_gulp_file() if you want a different upper limit.

◆ Gulp_Res_Arg

#define Gulp_Res_Arg ( gr)
Value:
const char * string_from_Gulp_Res(Gulp_Res g)
Return a constant string for the passed Gulp_Res.
Definition koliseo.c:3285

Format matching macro for a Gulp_Res.

◆ Gulp_Res_Fmt

#define Gulp_Res_Fmt   "%s"

Format macro for a Gulp_Res.

◆ KLS_GULP_FILE

#define KLS_GULP_FILE ( kls,
filepath )
Value:
#define GULP_MAX_FILE_SIZE
Defines max size allowed for a file passed to KLS_GULP_FILE().
Definition kls_gulp.h:71
char * try_kls_gulp_file(Koliseo *kls, const char *filepath, size_t max_size)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3664

◆ KLS_GULP_FILE_KSTR

#define KLS_GULP_FILE_KSTR ( kls,
filepath )
Value:
Kstr * try_kls_gulp_file_to_kstr(Koliseo *kls, const char *filepath, size_t max_size, bool allow_nullchar)
Tries mapping the passed file on the Koliseo.
Definition koliseo.c:3805

◆ KSTR

#define KSTR ( c_lit)
Value:
kstr_new(c_lit, sizeof(c_lit) - 1)
Kstr kstr_new(const char *str, size_t len)
Returns a new Kstr with the passed args set.
Definition koliseo.c:3298

◆ Kstr_Arg

#define Kstr_Arg ( kstr)
Value:
(int) (kstr.len), (kstr.data)

Format matching macro for a Kstr.

◆ Kstr_Fmt

#define Kstr_Fmt   "%.*s"

Format macro for a Kstr.

◆ KSTR_NULL

#define KSTR_NULL   kstr_new(NULL, 0)

◆ ONEGB_DEC_INT

#define ONEGB_DEC_INT   1073741824

Defines a one GB size as decimal integer representation.

See also
GULP_MAX_FILE_SIZE
GULP_FILE_TOO_LARGE
kls_gulp_file_sized()
KLS_GULP_FILE()

Typedef Documentation

◆ Gulp_Res

typedef enum Gulp_Res Gulp_Res

Defines possible results for kls_gulp_file_sized().

See also
kls_gulp_file_sized().

◆ Kstr

typedef struct Kstr Kstr

Enumeration Type Documentation

◆ Gulp_Res

enum Gulp_Res

Defines possible results for kls_gulp_file_sized().

See also
kls_gulp_file_sized().
Enumerator
GULP_FILE_OK 
GULP_FILE_NOT_EXIST 
GULP_FILE_TOO_LARGE 
GULP_FILE_READ_ERROR 
GULP_FILE_CONTAINS_NULLCHAR 
GULP_FILE_KLS_NULL 
TOT_GULP_RES 

Function Documentation

◆ kls_gulp_file_sized()

char * kls_gulp_file_sized ( Koliseo * kls,
const char * filepath,
Gulp_Res * err,
size_t max_size )

Tries mapping the passed file on the Koliseo.

Sets the passed Gulp_Res to the result of the operation, .

Parameters
klsThe Koliseo to push to.
filepathPath to the file to gulp.
errPointer to the Gulp_Res variable to store result.
max_sizeMax size allowed for the read file.
See also
KLS_GULP_FILE()

◆ kls_gulp_file_sized_to_kstr()

Kstr * kls_gulp_file_sized_to_kstr ( Koliseo * kls,
const char * filepath,
Gulp_Res * err,
size_t max_size,
bool allow_nullchar )

Tries mapping the passed file on the Koliseo.

Sets the passed Gulp_Res to the result of the operation.

Parameters
klsThe Koliseo to push to.
filepathPath to the file to gulp.
errPointer to the Gulp_Res variable to store result.
max_sizeMax size allowed for the read file.
allow_nullcharBool to avoid returning NULL for a binary file.
See also
KLS_GULP_FILE()
Returns
A Kstr for the passed filepath contents.

◆ kstr_cut_l()

Kstr kstr_cut_l ( Kstr * k,
size_t n )

Cuts the passed Kstr by up to n chars, from the left.

Returns cut portion as a new Kstr.

See also
Kstr
Parameters
kThe Kstr to cut.
nHow many chars to cut.
Returns
The cut part as a new Kstr.

◆ kstr_cut_r()

Kstr kstr_cut_r ( Kstr * k,
size_t n )

Cuts the passed Kstr by up to n chars, from the right.

Returns cut portion as a new Kstr.

See also
Kstr
Parameters
kThe Kstr to cut.
nHow many chars to cut.
Returns
The cut part as a new Kstr.

◆ kstr_eq()

bool kstr_eq ( Kstr left,
Kstr right )

Checks if the two passed Kstr have exactly equal data.

See also
Kstr
Parameters
leftThe first Kstr to compare.
rightThe second Kstr to compare.
Returns
A bool result for the comparation.

◆ kstr_eq_ignorecase()

bool kstr_eq_ignorecase ( Kstr left,
Kstr right )

Checks if the two passed Kstr have equal data, ignoring case.

See also
Kstr
Parameters
leftThe first Kstr to compare.
rightThe second Kstr to compare.
Returns
A bool result for the comparation.

◆ kstr_from_c_lit()

Kstr kstr_from_c_lit ( const char * c_lit)

Returns a new Kstr from the passed null-terminated string.

See also
Kstr
Parameters
c_litThe cstring pointer to set.
Returns
The resulting Kstr.

◆ kstr_indexof()

bool kstr_indexof ( Kstr k,
char c,
int * idx )

Checks if passed Kstr contains the passed char, and if so, sets the value pointed by idx to the first occurrence.

See also
Kstr
Parameters
kThe Kstr to scan.
cThe char to look for.
idxPointer to the value to be set as index.
Returns
false if the passed Kstr doesn't contain the passed char, true otherwise.

◆ kstr_new()

Kstr kstr_new ( const char * data,
size_t len )

Returns a new Kstr with the passed args set.

See also
Kstr
Parameters
dataThe string pointer to set.
lenThe len to set.
Returns
The resulting Kstr.

◆ kstr_token()

Kstr kstr_token ( Kstr * k,
char delim )

Scans the passed Kstr and cuts it up to the first occurrence of passed char, even if it is not present.

Returns a new Kstr with the original data.

See also
Kstr
Parameters
kThe Kstr to scan.
delimThe char to look for.
Returns
A new Kstr with the original data.

◆ kstr_token_kstr()

Kstr kstr_token_kstr ( Kstr * k,
Kstr delim )

◆ kstr_trim()

Kstr kstr_trim ( Kstr kstr)

Returns a new Kstr after removing heading and trailing spaces from the passed one.

See also
Kstr
kstr_trim_l()
kstr_trim_r()
Parameters
kstrThe Kstr to trim.
Returns
The resulting Kstr.

◆ kstr_trim_left()

Kstr kstr_trim_left ( Kstr kstr)

Returns a new Kstr after removing heading spaces from the passed one.

See also
Kstr
Parameters
kstrThe Kstr to trim.
Returns
The resulting Kstr.

◆ kstr_trim_right()

Kstr kstr_trim_right ( Kstr kstr)

Returns a new Kstr after removing trailing spaces from the passed one.

See also
Kstr
Parameters
kstrThe Kstr to trim.
Returns
The resulting Kstr.

◆ kstr_try_token()

bool kstr_try_token ( Kstr * k,
char delim,
Kstr * part )

Scans the first passed Kstr and if the passed char is present, the old Kstr is set to second pointer and the first one is cut at the first occurrence of it.

See also
Kstr
Parameters
kThe Kstr to scan.
delimThe char to look for.
partThe Kstr to set to the original data, if the delimiter is found.
Returns
false if the passed Kstr doesn't contain the passed char, true otherwise.

◆ string_from_Gulp_Res()

const char * string_from_Gulp_Res ( Gulp_Res g)

Return a constant string for the passed Gulp_Res.

See also
gulp_res_names
Gulp_Res
Parameters
gThe Gulp_Res to get a string for.
Returns
A constant string representation of passed Gulp_Res.

◆ try_kls_gulp_file()

char * try_kls_gulp_file ( Koliseo * kls,
const char * filepath,
size_t max_size )

Tries mapping the passed file on the Koliseo.

Parameters
klsThe Koliseo to push to.
filepathPath to the file to gulp.
max_sizeMax size allowed for the read file.
See also
KLS_GULP_FILE()
Returns
A pointer to the string with file contents.

◆ try_kls_gulp_file_to_kstr()

Kstr * try_kls_gulp_file_to_kstr ( Koliseo * kls,
const char * filepath,
size_t max_size,
bool allow_nullchar )

Tries mapping the passed file on the Koliseo.

Parameters
klsThe Koliseo to push to.
filepathPath to the file to gulp.
max_sizeMax size allowed for the read file.
allow_nullcharBoolean to avoid returning NULL for a binary file.
See also
KLS_GULP_FILE()
Returns
A pointer to the Kstr with file contents.

Variable Documentation

◆ gulp_res_names

const char* gulp_res_names[TOT_GULP_RES+1]
extern

String array for representations of Gulp_Res.

See also
string_from_Gulp_Res()

String array for representations of Gulp_Res.

See also
Gulp_Res