aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-02-28 18:15:16 -0500
committerDavid Robillard <d@drobilla.net>2023-03-31 11:10:31 -0400
commit647179b76fe15e5306a5a4f7ebbc1ad933d5a526 (patch)
tree29b6d123b0b3e1311d26039c1669f489662c2853 /src
parentf38e959688a206104df32ebb29b727874be5e7df (diff)
downloadserd-647179b76fe15e5306a5a4f7ebbc1ad933d5a526.tar.gz
serd-647179b76fe15e5306a5a4f7ebbc1ad933d5a526.tar.bz2
serd-647179b76fe15e5306a5a4f7ebbc1ad933d5a526.zip
Factor out read_string_escape()
Diffstat (limited to 'src')
-rw-r--r--src/n3.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/n3.c b/src/n3.c
index 11461e76..71a2fc56 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -1,4 +1,4 @@
-// Copyright 2011-2020 David Robillard <d@drobilla.net>
+// Copyright 2011-2023 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#include "byte_source.h"
@@ -323,6 +323,21 @@ eat_delim(SerdReader* const reader, const uint8_t delim)
return false;
}
+static SerdStatus
+read_string_escape(SerdReader* const reader,
+ const Ref ref,
+ SerdNodeFlags* const flags)
+{
+ SerdStatus st = SERD_SUCCESS;
+ uint32_t code = 0;
+ if ((st = read_ECHAR(reader, ref, flags)) &&
+ (st = read_UCHAR(reader, ref, &code))) {
+ return r_err(reader, st, "invalid escape '\\%c'\n", peek_byte(reader));
+ }
+
+ return st;
+}
+
// STRING_LITERAL_LONG_QUOTE and STRING_LITERAL_LONG_SINGLE_QUOTE
// Initial triple quotes are already eaten by caller
static SerdStatus
@@ -337,11 +352,7 @@ read_STRING_LITERAL_LONG(SerdReader* const reader,
const int c = peek_byte(reader);
if (c == '\\') {
skip_byte(reader, c);
- uint32_t code = 0;
- if ((st = read_ECHAR(reader, ref, flags)) &&
- (st = read_UCHAR(reader, ref, &code))) {
- return r_err(reader, st, "invalid escape '\\%c'\n", peek_byte(reader));
- }
+ st = read_string_escape(reader, ref, flags);
} else if (c == q) {
skip_byte(reader, q);
const int q2 = eat_byte_safe(reader, peek_byte(reader));
@@ -375,8 +386,7 @@ read_STRING_LITERAL(SerdReader* const reader,
SerdStatus st = SERD_SUCCESS;
while (!st || !reader->strict) {
- const int c = peek_byte(reader);
- uint32_t code = 0;
+ const int c = peek_byte(reader);
switch (c) {
case EOF:
return r_err(
@@ -386,9 +396,8 @@ read_STRING_LITERAL(SerdReader* const reader,
return r_err(reader, SERD_ERR_BAD_SYNTAX, "line end in short string\n");
case '\\':
skip_byte(reader, c);
- if ((st = read_ECHAR(reader, ref, flags)) &&
- (st = read_UCHAR(reader, ref, &code))) {
- return r_err(reader, st, "invalid escape '\\%c'\n", peek_byte(reader));
+ if ((st = read_string_escape(reader, ref, flags))) {
+ return st;
}
break;
default: