aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-02-24 20:44:32 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commitf74a7448036d6fbe3f6562aa6e87d7e7478f0341 (patch)
tree8b220b7c6ca2f560f3e15dfc69d0a904636c196a /src
parent343124df71010055c2c1e6cdcadd13d23b2c013a (diff)
downloadserd-f74a7448036d6fbe3f6562aa6e87d7e7478f0341.tar.gz
serd-f74a7448036d6fbe3f6562aa6e87d7e7478f0341.tar.bz2
serd-f74a7448036d6fbe3f6562aa6e87d7e7478f0341.zip
Factor out serd_byte_source_skip_bom()
Diffstat (limited to 'src')
-rw-r--r--src/byte_source.c16
-rw-r--r--src/byte_source.h3
-rw-r--r--src/reader.c21
3 files changed, 22 insertions, 18 deletions
diff --git a/src/byte_source.c b/src/byte_source.c
index 6ec2084a..8959b1e6 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -123,3 +123,19 @@ serd_byte_source_prepare(SerdByteSource* const source)
return serd_byte_source_advance(source);
}
+
+SerdStatus
+serd_byte_source_skip_bom(SerdByteSource* const source)
+{
+ if (serd_byte_source_peek(source) == 0xEF) {
+ if (serd_byte_source_advance(source) ||
+ serd_byte_source_peek(source) != 0xBB ||
+ serd_byte_source_advance(source) ||
+ serd_byte_source_peek(source) != 0xBF ||
+ serd_byte_source_advance(source)) {
+ return SERD_BAD_SYNTAX;
+ }
+ }
+
+ return SERD_SUCCESS;
+}
diff --git a/src/byte_source.h b/src/byte_source.h
index ced36b82..5ae40acb 100644
--- a/src/byte_source.h
+++ b/src/byte_source.h
@@ -47,6 +47,9 @@ serd_byte_source_prepare(SerdByteSource* source);
SerdStatus
serd_byte_source_page(SerdByteSource* source);
+SerdStatus
+serd_byte_source_skip_bom(SerdByteSource* source);
+
ZIX_PURE_FUNC static inline uint8_t
serd_byte_source_peek(SerdByteSource* source)
{
diff --git a/src/reader.c b/src/reader.c
index 85db9b0b..cfeaf0c0 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -309,23 +309,6 @@ serd_reader_free(SerdReader* const reader)
serd_wfree(reader->world, reader);
}
-static SerdStatus
-skip_bom(SerdReader* const me)
-{
- if (serd_byte_source_peek(me->source) == 0xEF) {
- if (serd_byte_source_advance(me->source) ||
- serd_byte_source_peek(me->source) != 0xBB ||
- serd_byte_source_advance(me->source) ||
- serd_byte_source_peek(me->source) != 0xBF ||
- serd_byte_source_advance(me->source)) {
- r_err(me, SERD_BAD_SYNTAX, "corrupt byte order mark");
- return SERD_BAD_SYNTAX;
- }
- }
-
- return SERD_SUCCESS;
-}
-
SerdStatus
serd_reader_start(SerdReader* const reader,
SerdInputStream* const input,
@@ -354,7 +337,9 @@ serd_reader_prepare(SerdReader* const reader)
{
SerdStatus st = serd_byte_source_prepare(reader->source);
if (st == SERD_SUCCESS) {
- st = skip_bom(reader);
+ if ((st = serd_byte_source_skip_bom(reader->source))) {
+ r_err(reader, SERD_BAD_SYNTAX, "corrupt byte order mark");
+ }
} else if (st == SERD_FAILURE) {
reader->source->eof = true;
}