// Copyright 2023 alexevier // licensed under the zlib license #ifndef lexlib_str_h #define lexlib_str_h #include #include"common.h" // create a new cstring allocated on the heap. // on error returns NULL (failed to allocate memory). LEXLIB_EXTERN char *lexlibStrNew(const char *str); // creates a new heap allocated and null terminated string from concatenating 2 strings. // note that strings to be concatenated should be null terminated. // on error returns NULL (failed to allocate memory). LEXLIB_EXTERN char *lexlibStrCat(const char *str1, const char *str2); // creates a new heap allocated copy of a string. // the string passed should be null terminated; the string returned will be null terminated. // on error returns NULL (failed to allocate memory). LEXLIB_EXTERN char *lexlibStrCopy(const char *str); // read a file into a null terminated heap allocated string. // returns a valid string on success, NULL on error. LEXLIB_EXTERN char *lexlibStrFile(const char *filename); // creates a string with a correctly formated path. (unix: / ; windows: \) // on error returns NULL (failed to allocate memory). LEXLIB_EXTERN char *lexlibStrPathNew(const char *str); // adds a element to the end of a formated path. // returns 0 on success, LEXLIB_INVALID_VALUE or LEXLIB_OUT_OF_MEMORY on error. LEXLIB_EXTERN uint8_t lexlibStrPathPush(char **str, const char *add); // removes the last element. // returns 0 on success, LEXLIB_OUT_OF_MEMORY or LEXLIB_INVALID_OPERATION on error. LEXLIB_EXTERN uint8_t lexlibStrPathPop(char **str); // converts the path as if it was a dir (aka: path/to/dir/), in short adds a / to the end. (\ on windows). // returns 0 on success, LEXLIB_INVALID_VALUE or LEXLIB_OUT_OF_MEMORY on error. LEXLIB_EXTERN uint8_t lexlibStrPathAsDir(char **str); // if the str has a / or \ at the end it will be removed and count as if was referencing a file. // returns 0 on success, LEXLIB_INVALID_VALUE or LEXLIB_OUT_OF_MEMORY on error. LEXLIB_EXTERN uint8_t lexlibStrPathAsFile(char **str); #endif