aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/n3.c25
-rw-r--r--src/node.c76
-rw-r--r--src/string.c46
-rw-r--r--src/string_utils.h3
-rw-r--r--src/writer.c3
5 files changed, 23 insertions, 130 deletions
diff --git a/src/n3.c b/src/n3.c
index edc0f52b..dd1b5168 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -155,11 +155,9 @@ read_ECHAR(SerdReader* reader, SerdNode* dest)
eat_byte_safe(reader, 'b');
return push_byte(reader, dest, '\b');
case 'n':
- dest->flags |= SERD_HAS_NEWLINE;
eat_byte_safe(reader, 'n');
return push_byte(reader, dest, '\n');
case 'r':
- dest->flags |= SERD_HAS_NEWLINE;
eat_byte_safe(reader, 'r');
return push_byte(reader, dest, '\r');
case 'f':
@@ -248,23 +246,8 @@ read_utf8_code(SerdReader* reader, SerdNode* dest, uint32_t* code, uint8_t c)
static inline SerdStatus
read_character(SerdReader* reader, SerdNode* dest, uint8_t c)
{
- if (!(c & 0x80)) {
- switch (c) {
- case 0xA:
- case 0xD:
- dest->flags |= SERD_HAS_NEWLINE;
- break;
- case '"':
- case '\'':
- dest->flags |= SERD_HAS_QUOTE;
- break;
- default:
- break;
- }
-
- return push_byte(reader, dest, c);
- }
- return read_utf8_character(reader, dest, c);
+ return (c & 0x80) ? read_utf8_character(reader, dest, c)
+ : push_byte(reader, dest, c);
}
// [10] comment ::= '#' ( [^#xA #xD] )*
@@ -350,7 +333,7 @@ read_STRING_LITERAL_LONG(SerdReader* reader, SerdNode* ref, uint8_t q)
eat_byte_safe(reader, q3);
break;
}
- ref->flags |= SERD_HAS_QUOTE;
+
push_byte(reader, ref, c);
st = read_character(reader, ref, (uint8_t)q2);
} else {
@@ -436,6 +419,8 @@ read_String(SerdReader* reader, SerdNode* node)
}
eat_byte_safe(reader, q3);
+ node->flags |= SERD_IS_LONG_LITERAL;
+
return read_STRING_LITERAL_LONG(reader, node, (uint8_t)q1);
}
diff --git a/src/node.c b/src/node.c
index 0283b14f..606789c9 100644
--- a/src/node.c
+++ b/src/node.c
@@ -117,9 +117,8 @@ serd_node_malloc(size_t n_bytes, SerdNodeFlags flags, SerdNodeType type)
const size_t size = sizeof(SerdNode) + serd_node_pad_size(n_bytes);
SerdNode* node = (SerdNode*)serd_calloc_aligned(sizeof(SerdNode), size);
- node->n_bytes = 0;
- node->flags = flags;
- node->type = type;
+ node->flags = flags;
+ node->type = type;
assert((uintptr_t)node % sizeof(SerdNode) == 0u);
return node;
@@ -165,17 +164,10 @@ serd_node_zero_pad(SerdNode* node)
SerdNode*
serd_new_simple_node(SerdNodeType type, const SerdStringView str)
{
- if (type != SERD_BLANK && type != SERD_CURIE && type != SERD_URI &&
- type != SERD_VARIABLE) {
- return NULL;
- }
-
- SerdNodeFlags flags = 0;
- const size_t n_bytes = str.buf ? serd_strlen(str.buf, &flags) : 0;
- SerdNode* node = serd_node_malloc(n_bytes, flags, type);
+ SerdNode* const node = serd_node_malloc(str.len, 0, type);
- memcpy(serd_node_buffer(node), str.buf, n_bytes);
- node->n_bytes = n_bytes;
+ memcpy(serd_node_buffer(node), str.buf, str.len);
+ node->n_bytes = str.len;
serd_node_check_padding(node);
return node;
@@ -184,32 +176,28 @@ serd_new_simple_node(SerdNodeType type, const SerdStringView str)
SerdNode*
serd_new_string(const SerdStringView str)
{
- SerdNodeFlags flags = 0;
- const size_t n_bytes = serd_substrlen(str.buf, str.len, &flags);
- SerdNode* node = serd_node_malloc(n_bytes, flags, SERD_LITERAL);
+ SerdNodeFlags flags = 0;
+ SerdNode* node = serd_node_malloc(str.len, flags, SERD_LITERAL);
memcpy(serd_node_buffer(node), str.buf, str.len);
- node->n_bytes = n_bytes;
+ node->n_bytes = str.len;
serd_node_check_padding(node);
return node;
}
-/// Internal pre-measured implementation of serd_new_plain_literal
-static SerdNode*
-serd_new_plain_literal_i(const SerdStringView str,
- SerdNodeFlags flags,
- const SerdStringView lang)
+SerdNode*
+serd_new_plain_literal(const SerdStringView str, const SerdStringView lang)
{
- assert(str.len);
- assert(lang.len);
-
- flags |= SERD_HAS_LANGUAGE;
+ if (!lang.len) {
+ return serd_new_string(str);
+ }
const size_t len = serd_node_pad_size(str.len);
const size_t total_len = len + sizeof(SerdNode) + lang.len;
- SerdNode* node = serd_node_malloc(total_len, flags, SERD_LITERAL);
+ SerdNode* node = serd_node_malloc(total_len, SERD_HAS_LANGUAGE, SERD_LITERAL);
+
memcpy(serd_node_buffer(node), str.buf, str.len);
node->n_bytes = str.len;
@@ -287,34 +275,6 @@ serd_new_typed_literal_uri(const SerdStringView str,
return node;
}
-/// Internal pre-measured implementation of serd_new_typed_literal
-static SerdNode*
-serd_new_typed_literal_i(const SerdStringView str,
- SerdNodeFlags flags,
- SerdNodeType datatype_type,
- const SerdStringView datatype)
-{
- assert(str.len);
- assert(datatype.len);
- assert(strcmp(datatype.buf, NS_RDF "langString"));
-
- return serd_new_typed_literal_expanded(
- str, flags, datatype_type, datatype, SERD_EMPTY_STRING());
-}
-
-SerdNode*
-serd_new_plain_literal(const SerdStringView str, const SerdStringView lang)
-{
- if (!lang.len) {
- return serd_new_string(str);
- }
-
- SerdNodeFlags flags = 0;
- serd_strlen(str.buf, &flags);
-
- return serd_new_plain_literal_i(str, flags, lang);
-}
-
SerdNode*
serd_new_typed_literal(const SerdStringView str,
const SerdStringView datatype_uri)
@@ -327,10 +287,8 @@ serd_new_typed_literal(const SerdStringView str,
return NULL;
}
- SerdNodeFlags flags = 0;
- serd_strlen(str.buf, &flags);
-
- return serd_new_typed_literal_i(str, flags, SERD_URI, datatype_uri);
+ return serd_new_typed_literal_expanded(
+ str, 0, SERD_URI, datatype_uri, SERD_EMPTY_STRING());
}
SerdNode*
diff --git a/src/string.c b/src/string.c
index f31dfe0b..d9a0140c 100644
--- a/src/string.c
+++ b/src/string.c
@@ -75,49 +75,3 @@ serd_strerror(SerdStatus status)
}
return "Unknown error"; // never reached
}
-
-static inline void
-serd_update_flags(const char c, SerdNodeFlags* const flags)
-{
- switch (c) {
- case '\r':
- case '\n':
- *flags |= SERD_HAS_NEWLINE;
- break;
- case '"':
- *flags |= SERD_HAS_QUOTE;
- default:
- break;
- }
-}
-
-size_t
-serd_substrlen(const char* const str,
- const size_t len,
- SerdNodeFlags* const flags)
-{
- assert(flags);
-
- size_t i = 0;
- *flags = 0;
- for (; i < len && str[i]; ++i) {
- serd_update_flags(str[i], flags);
- }
-
- return i;
-}
-
-size_t
-serd_strlen(const char* str, SerdNodeFlags* flags)
-{
- if (flags) {
- size_t i = 0;
- *flags = 0;
- for (; str[i]; ++i) {
- serd_update_flags(str[i], flags);
- }
- return i;
- }
-
- return strlen(str);
-}
diff --git a/src/string_utils.h b/src/string_utils.h
index a302bc49..cad800b9 100644
--- a/src/string_utils.h
+++ b/src/string_utils.h
@@ -96,9 +96,6 @@ is_windows_path(const char* path)
(path[2] == '/' || path[2] == '\\');
}
-size_t
-serd_substrlen(const char* str, size_t len, SerdNodeFlags* flags);
-
static inline char
serd_to_upper(const char c)
{
diff --git a/src/writer.c b/src/writer.c
index d15320ae..566c6fde 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -694,8 +694,7 @@ write_literal(SerdWriter* writer,
}
SerdStatus st = SERD_SUCCESS;
- if (supports_abbrev(writer) &&
- (node->flags & (SERD_HAS_NEWLINE | SERD_HAS_QUOTE))) {
+ if (supports_abbrev(writer) && (node->flags & SERD_IS_LONG_LITERAL)) {
TRY(st, esink("\"\"\"", 3, writer));
TRY(st, write_text(writer, WRITE_LONG_STRING, node_str, node->n_bytes));
TRY(st, esink("\"\"\"", 3, writer));