]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
tokenizer now skips multiple occurrences of delimiters in a row
authorJelte Jansen <jeltejan@NLnetLabs.nl>
Wed, 6 Apr 2005 08:04:07 +0000 (08:04 +0000)
committerJelte Jansen <jeltejan@NLnetLabs.nl>
Wed, 6 Apr 2005 08:04:07 +0000 (08:04 +0000)
buffer.c
parse.c

index 47c7c29569e9d1a36c0e9724f28183d4eee7515f..9010a19c8012df448fddf8ec6e89870f0b351ad3 100644 (file)
--- 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 6bb89251411c785deaaaefaf88186ff9c3e9727e..4d17dc2bbd6c2f86aec360a96f17f0beba527e21 100644 (file)
--- 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;
        }
 }