mirror of
https://github.com/troglobit/finit.git
synced 2026-10-19 11:09:35 +00:00
util: new function unquote()
Refactor to reduce code duplication Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
4 files changed
+26
-28
No files matched your search
+21
@@ -165,6 +165,27 @@ static inline void hexdump(const char *buf, size_t len)
|
||||
}
|
||||
}
|
||||
|
||||
/* drop quotes from a string at point, if any */
|
||||
static inline int unquote(char **str, char *end)
|
||||
{
|
||||
char *ptr = *str;
|
||||
|
||||
/* unquote value, if quoted */
|
||||
if (ptr[0] == '"' || ptr[0] == '\'') {
|
||||
char q = ptr[0];
|
||||
|
||||
if (!end && !(end = strchr(&ptr[1], q)))
|
||||
return -1;
|
||||
|
||||
if (*end == q) {
|
||||
*str = &ptr[1];
|
||||
*end = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* FINIT_UTIL_H_ */
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user