From: Jelte Jansen Date: Wed, 6 Apr 2005 08:04:07 +0000 (+0000) Subject: tokenizer now skips multiple occurrences of delimiters in a row X-Git-Tag: release-0.50~167 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01dfa59b30640a0fd5fe9a35e2970e04ebfdb50b;p=thirdparty%2Fldns.git tokenizer now skips multiple occurrences of delimiters in a row --- diff --git a/buffer.c b/buffer.c index 47c7c295..9010a19c 100644 --- a/buffer.c +++ b/buffer.c @@ -189,3 +189,49 @@ ldns_bgetc(ldns_buffer *buffer) } return (int)ldns_buffer_read_u8(buffer); } + +/* fast forwards the buffer, skipping the given char, setting the + * buffer position to the location of the first different char + * (or to the end of the buffer) + */ +void +ldns_bskipc(ldns_buffer *buffer, char c) +{ + while (c == (char) ldns_buffer_read_u8_at(buffer, ldns_buffer_position(buffer))) { + if (ldns_buffer_available_at(buffer, buffer->_position + sizeof(char), sizeof(char))) { + buffer->_position += sizeof(char); + } else { + return; + } + } +} + +/* fast forwards the buffer, skipping all chars in the given string, + * setting the buffer position to the first char that is not contained + * in the string (or to the end of the buffer) + */ +void +ldns_bskipcs(ldns_buffer *buffer, char *s) +{ + bool found; + char c; + char *d; + + while(ldns_buffer_available_at(buffer, buffer->_position, sizeof(char))) { + c = (char) ldns_buffer_read_u8_at(buffer, + buffer->_position); + found = false; + for (d = s; *d; d++) { + if (*d == c) { + found = true; + } + } + if (found && buffer->_limit > buffer->_position) { + buffer->_position += sizeof(char); + } else { + return; + } + } +} + + diff --git a/parse.c b/parse.c index 6bb89251..4d17dc2b 100644 --- a/parse.c +++ b/parse.c @@ -188,7 +188,7 @@ ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit) const char *d; const char *del; - /* standard delimeters */ + /* standard delimiters */ if (!delim) { /* from isspace(3) */ del = LDNS_PARSE_NORMAL; @@ -241,6 +241,8 @@ tokenread: return 0; } else { *t = '\0'; + /* skip delimiters for next token */ + ldns_bskipcs(b, del); return (ssize_t)i; } }