aboutsummaryrefslogtreecommitdiffstats
path: root/common/stringhelp.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2013-02-21 19:25:12 +0000
committerWerner Koch <[email protected]>2013-02-21 19:25:12 +0000
commit4af0c62b15c51056dc293c8e3b907e7c41fbf08c (patch)
tree13f3ad09ea7734ff486db5d79d9dde3dbf11d887 /common/stringhelp.c
parentRemove build hacks for FreeBSD. (diff)
downloadgnupg-4af0c62b15c51056dc293c8e3b907e7c41fbf08c.tar.gz
gnupg-4af0c62b15c51056dc293c8e3b907e7c41fbf08c.zip
common: Add func has_leading_keyword.
* common/stringhelp.c (has_leading_keyword): New.
Diffstat (limited to 'common/stringhelp.c')
-rw-r--r--common/stringhelp.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/common/stringhelp.c b/common/stringhelp.c
index 842f6a14b..d51d3e0ce 100644
--- a/common/stringhelp.c
+++ b/common/stringhelp.c
@@ -74,6 +74,29 @@ change_slashes (char *name)
/*
+ * Check whether STRINGS starts with KEYWORD. The keyword is
+ * delimited by end of string, a space or a tab. Returns NULL if not
+ * found or a pointer into STRING to the next non-space character
+ * after the KEYWORD (which may be end of string).
+ */
+char *
+has_leading_keyword (const char *string, const char *keyword)
+{
+ size_t n = strlen (keyword);
+
+ if (!strncmp (string, keyword, n)
+ && (!string[n] || string[n] == ' ' || string[n] == '\t'))
+ {
+ string += n;
+ while (*string == ' ' || *string == '\t')
+ string++;
+ return (char*)string;
+ }
+ return NULL;
+}
+
+
+/*
* Look for the substring SUB in buffer and return a pointer to that
* substring in BUFFER or NULL if not found.
* Comparison is case-insensitive.