From 25d4829d7b42117f54fdb9f5250d1d94ddd16095 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 3 Apr 2023 13:17:25 +0200 Subject: [PATCH] Add utilities function for parsing FILE or char* while skipping space character --- m-core.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/m-core.h b/m-core.h index 4d93537d..fecd2788 100644 --- a/m-core.h +++ b/m-core.h @@ -2621,7 +2621,27 @@ M_FSCAN_DEFAULT_TYPE_DEF(m_core_fscan_float, float, "%f") M_FSCAN_DEFAULT_TYPE_DEF(m_core_fscan_double, double, "%lf") M_FSCAN_DEFAULT_TYPE_DEF(m_core_fscan_ldouble, long double, "%Lf") -#endif +/* Return the next character (like fgetc) which is not a space character */ +static inline int m_core_fgetc_nospace(FILE *f) +{ + int c; + do { + c = fgetc(f); + } while (c != EOF && isspace(c)); + return c; +} + +#endif /* End of stdio definitions */ + +/* Return the next character (like fgetc) which is not a space character */ +static inline char m_core_str_nospace(const char **str) +{ + char c; + do { + c = *((*str)++); + } while (isspace((unsigned char) c)); + return c; +} /* Transform a C variable into a m_string_t (needs m-string.h) */ #define M_GET_STRING_ARG(str, x, append) \