From: Ben Pfaff Date: Wed, 5 Mar 2008 05:56:51 +0000 (+0000) Subject: Patch #6441. Reviewed by John Darrington. X-Git-Tag: v0.6.0~77 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45eea3ba2455d9aebd471bbe9396581d255c266e;p=pspp-builds.git Patch #6441. Reviewed by John Darrington. (ss_match_char_in): New function. --- diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog index 7f224610..c201dc07 100644 --- a/src/libpspp/ChangeLog +++ b/src/libpspp/ChangeLog @@ -1,3 +1,9 @@ +2008-03-04 Ben Pfaff + + Patch #6441. Reviewed by John Darrington. + + * str.c (ss_match_char_in): New function. + 2008-02-18 Ben Pfaff Patch #6426. Thanks to John Darrington for review. diff --git a/src/libpspp/str.c b/src/libpspp/str.c index b88493d4..9a7c6da8 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -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 diff --git a/src/libpspp/str.h b/src/libpspp/str.h index 0d48bd9b..ff00b359 100644 --- a/src/libpspp/str.h +++ b/src/libpspp/str.h @@ -105,6 +105,7 @@ bool ss_tokenize (struct substring src, struct substring delimiters, size_t *save_idx, struct substring *token); void ss_advance (struct substring *, size_t); bool ss_match_char (struct substring *, char); +int ss_match_char_in (struct substring *, struct substring); bool ss_match_string (struct substring *, const struct substring); int ss_get_char (struct substring *); size_t ss_get_chars (struct substring *, size_t cnt, struct substring *);