From 2b8cf5e771cac4c2b087dc96a7ca05a459f630b5 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 7 Feb 2018 09:26:36 -0500 Subject: conditionals, returns, cleaner code --- shelpers.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 shelpers.h (limited to 'shelpers.h') diff --git a/shelpers.h b/shelpers.h new file mode 100644 index 0000000..7f2ad63 --- /dev/null +++ b/shelpers.h @@ -0,0 +1,62 @@ +#ifndef SHELPERS_H_ +#define SHELPERS_H_ + +#include + +/** + * Clones the given string, malloc'ing a new one. + * @param s the string to clone + * @return the malloc'd copy + */ +char *strclone(const char *s); + +/** + * Clones the given string until the given count. + * @param s the string to clone + * @param n the number of characters to clone + * @return the malloc'd copy + */ +char *strnclone(const char *s, uint32_t n); + + +/** + * Returns non-zero if the character is considered an end-of-line. + * @param c a character + * @return non-zero if eol, zero if not + */ +uint8_t eol(int c); + +/** + * Returns non-zero if the character is considered an end-of-token. + * @param c a character + * @return non-zero if eot, zero if not + */ +uint8_t eot(int c); + +/** + * Returns non-zero if the character is considered an end-of-expression. + * @param c a character + * @return non-zero if eoe, zero if not + */ +uint8_t eoe(int c); + + +/** + * Finds the matching end character in a string, e.g. matching parens. + * @param s the string to search + * @param o the starting, opening character (e.g. '(') + * @param c the end, closing character (e.g. ')') + * @return offset of the end character in the string + */ +uint32_t findend(const char *s, char o, char c); + +/** + * Increments offset until the character in the string is not blank or fails + * the given comparison. + * @param s the string to use + * @param cmp a comparing function, stops search if returns true + * @param offset the variable to increment while searching + */ +void skipblank(const char *s, uint8_t (*cmp)(int), uint32_t *offset); + +#endif // SHELPERS_H_ -- cgit v1.2.3