aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-11-09 09:32:39 +0100
committerDavid Robillard <d@drobilla.net>2018-02-04 09:28:37 +0100
commit4bb5e376544d66c96e6753f1bee133feb52824eb (patch)
treeddefe0ff23aee73fd6e29808f3d34c227740f371
parent0d886733b5fafceb8c3b954dbb31c57ed7583d9a (diff)
downloadserd-4bb5e376544d66c96e6753f1bee133feb52824eb.tar.gz
serd-4bb5e376544d66c96e6753f1bee133feb52824eb.tar.bz2
serd-4bb5e376544d66c96e6753f1bee133feb52824eb.zip
Factor out is_xdigit
-rw-r--r--src/reader.c9
-rw-r--r--src/serd_internal.h9
2 files changed, 12 insertions, 6 deletions
diff --git a/src/reader.c b/src/reader.c
index d2e10f69..a1c517e3 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -253,11 +253,10 @@ static inline uint8_t
read_HEX(SerdReader* reader)
{
const uint8_t c = peek_byte(reader);
- if (is_digit(c) || in_range(c, 'A', 'F') || in_range(c, 'a', 'f')) {
- return eat_byte_safe(reader, c);
- }
- return r_err(reader, SERD_ERR_BAD_SYNTAX,
- "invalid hexadecimal digit `%c'\n", c);
+ return is_xdigit(c)
+ ? eat_byte_safe(reader, c)
+ : r_err(reader, SERD_ERR_BAD_SYNTAX,
+ "invalid hexadecimal digit `%c'\n", c);
}
// Read UCHAR escape, initial \ is already eaten by caller
diff --git a/src/serd_internal.h b/src/serd_internal.h
index a74bde38..a150d9bb 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -296,7 +296,7 @@ in_range(const uint8_t c, const uint8_t min, const uint8_t max)
return (c >= min && c <= max);
}
-/** RFC2234: ALPHA := %x41-5A / %x61-7A ; A-Z / a-z */
+/** RFC2234: ALPHA ::= %x41-5A / %x61-7A ; A-Z / a-z */
static inline bool
is_alpha(const uint8_t c)
{
@@ -317,6 +317,13 @@ is_hexdig(const uint8_t c)
return is_digit(c) || in_range(c, 'A', 'F');
}
+/* Turtle / JSON / C: XDIGIT ::= DIGIT / A-F / a-f */
+static inline bool
+is_xdigit(const uint8_t c)
+{
+ return is_hexdig(c) || in_range(c, 'a', 'f');
+}
+
static inline bool
is_space(const char c)
{