aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-06-25 15:54:30 -0400
committerDavid Robillard <d@drobilla.net>2024-06-25 16:51:38 -0400
commitd0c6099462d40a63399d02c2a84237d7fd2f89f8 (patch)
tree9aa496ddd58f6842cc102f2fcfe3896b6f85ca00 /src/writer.c
parent51cc405d288a078543523efd380ce3c7d11ac501 (diff)
downloadserd-d0c6099462d40a63399d02c2a84237d7fd2f89f8.tar.gz
serd-d0c6099462d40a63399d02c2a84237d7fd2f89f8.tar.bz2
serd-d0c6099462d40a63399d02c2a84237d7fd2f89f8.zip
Reduce size of character classification code
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c60
1 files changed, 13 insertions, 47 deletions
diff --git a/src/writer.c b/src/writer.c
index 08192bb1..e4ef5651 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -283,21 +283,8 @@ write_character(SerdWriter* writer,
SERD_NODISCARD static bool
uri_must_escape(const uint8_t c)
{
- switch (c) {
- case ' ':
- case '"':
- case '<':
- case '>':
- case '\\':
- case '^':
- case '`':
- case '{':
- case '|':
- case '}':
- return true;
- default:
- return !in_range(c, 0x20, 0x7E);
- }
+ return (c == '"') || (c == '<') || (c == '>') || (c == '\\') || (c == '^') ||
+ (c == '`') || in_range(c, '{', '}') || !in_range(c, 0x21, 0x7E);
}
static size_t
@@ -368,38 +355,17 @@ write_uri_from_node(SerdWriter* writer, const SerdNode* node)
static bool
lname_must_escape(const uint8_t c)
{
- /* This arbitrary list of characters, most of which have nothing to do with
- Turtle, must be handled as special cases here because the RDF and SPARQL
- WGs are apparently intent on making the once elegant Turtle a baroque
- and inconsistent mess, throwing elegance and extensibility completely
- out the window for no good reason.
-
- Note '-', '.', and '_' are also in PN_LOCAL_ESC, but are valid unescaped
- in local names, so they are not escaped here. */
-
- switch (c) {
- case '\'':
- case '!':
- case '#':
- case '$':
- case '%':
- case '&':
- case '(':
- case ')':
- case '*':
- case '+':
- case ',':
- case '/':
- case ';':
- case '=':
- case '?':
- case '@':
- case '~':
- return true;
- default:
- break;
- }
- return false;
+ /* Most of these characters have nothing to do with Turtle, but were taken
+ from SPARQL and mashed into the Turtle grammar (despite not being used)
+ with RDF 1.1. So now Turtle is a mess because the SPARQL grammar is
+ poorly designed and didn't use a leading character to distinguish things
+ like path patterns like it should have.
+
+ Note that '-', '.', and '_' are also in PN_LOCAL_ESC, but are valid
+ unescaped in local names, so they are not escaped here. */
+
+ return (c == '!') || (c == '/') || (c == ';') || (c == '=') || (c == '?') ||
+ (c == '@') || (c == '~') || in_range(c, '#', ',');
}
SERD_NODISCARD static SerdStatus