Patch #6441. Reviewed by John Darrington.
[pspp-builds.git] / src / libpspp / str.c
index b88493d47fabafff46fd36a724cdcc1ad3e26d68..9a7c6da8bfa8c36e50cca3cfd7b7bfe99a6cf0db 100644 (file)
@@ -546,6 +546,23 @@ ss_match_char (struct substring *ss, char c)
     return false;
 }
 
+/* If the first character in SS is in MATCH, removes it and
+   returns the character that was removed.
+   Otherwise, returns EOF without changing the string. */
+int
+ss_match_char_in (struct substring *ss, struct substring match)
+{
+  int c = EOF;
+  if (ss->length > 0
+      && memchr (match.string, ss->string[0], match.length) != NULL)
+    {
+      c = ss->string[0];
+      ss->string++;
+      ss->length--;
+    }
+  return c;
+}
+
 /* If SS begins with TARGET, removes it and returns true.
    Otherwise, returns false without changing SS. */
 bool