diff options
author | David Robillard <d@drobilla.net> | 2018-12-30 17:45:07 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-01-05 18:55:50 +0100 |
commit | 04e6f01432a5888a6abf95d6dfdec8094c380e70 (patch) | |
tree | 23ecb0b8d9ad21fa1caa5ca7b035e8ba60d7db2c | |
parent | bb9d51a0f607ebe8d3802f7880ef588420cb9394 (diff) | |
download | serd-04e6f01432a5888a6abf95d6dfdec8094c380e70.tar.gz serd-04e6f01432a5888a6abf95d6dfdec8094c380e70.tar.bz2 serd-04e6f01432a5888a6abf95d6dfdec8094c380e70.zip |
Rewrite switch statements that are better written as ifs
-rw-r--r-- | src/n3.c | 32 | ||||
-rw-r--r-- | src/uri.c | 6 |
2 files changed, 16 insertions, 22 deletions
@@ -305,32 +305,28 @@ read_STRING_LITERAL_LONG(SerdReader* reader, SerdNodeFlags* flags, uint8_t q) Ref ref = push_node(reader, SERD_LITERAL, "", 0); while (!reader->status) { const uint8_t c = peek_byte(reader); - uint32_t code; - switch (c) { - case '\\': + if (c == '\\') { eat_byte_safe(reader, c); + uint32_t code; if (!read_ECHAR(reader, ref, flags) && !read_UCHAR(reader, ref, &code)) { r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid escape `\\%c'\n", peek_byte(reader)); return pop_node(reader, ref); } - break; - default: - if (c == q) { - eat_byte_safe(reader, q); - const uint8_t q2 = eat_byte_safe(reader, peek_byte(reader)); - const uint8_t q3 = peek_byte(reader); - if (q2 == q && q3 == q) { // End of string - eat_byte_safe(reader, q3); - return ref; - } - *flags |= SERD_HAS_QUOTE; - push_byte(reader, ref, c); - read_character(reader, ref, flags, q2); - } else { - read_character(reader, ref, flags, eat_byte_safe(reader, c)); + } else if (c == q) { + eat_byte_safe(reader, q); + const uint8_t q2 = eat_byte_safe(reader, peek_byte(reader)); + const uint8_t q3 = peek_byte(reader); + if (q2 == q && q3 == q) { // End of string + eat_byte_safe(reader, q3); + return ref; } + *flags |= SERD_HAS_QUOTE; + push_byte(reader, ref, c); + read_character(reader, ref, flags, q2); + } else { + read_character(reader, ref, flags, eat_byte_safe(reader, c)); } } return ref; @@ -188,12 +188,10 @@ query: if (*ptr == '?') { out->query.buf = ++ptr; for (uint8_t c; (c = *ptr) != '\0'; ++ptr) { - switch (c) { - case '#': + if (c == '#') { goto fragment; - default: - ++out->query.len; } + ++out->query.len; } } |