aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-23 09:16:38 +0000
committerDavid Robillard <d@drobilla.net>2011-01-23 09:16:38 +0000
commitebcef72577398fa10a6ad6545317f704bcf9a1c4 (patch)
treecb6ada04b2a4c4eefa1fa86c6b8a854c7fc7488d
parent5de15ccf0a0216e5aadd93ab9095bf15279bfb7c (diff)
downloadserd-ebcef72577398fa10a6ad6545317f704bcf9a1c4.tar.gz
serd-ebcef72577398fa10a6ad6545317f704bcf9a1c4.tar.bz2
serd-ebcef72577398fa10a6ad6545317f704bcf9a1c4.zip
Rearrange code, put common internal stuff in serd_internal.h.
git-svn-id: http://svn.drobilla.net/serd/trunk@46 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--src/reader.c22
-rw-r--r--src/serd_internal.h (renamed from src/serd_stack.h)34
-rw-r--r--src/uri.c23
-rw-r--r--src/writer.c3
4 files changed, 37 insertions, 45 deletions
diff --git a/src/reader.c b/src/reader.c
index 9667abf5..8bae4c03 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -23,8 +23,7 @@
#include <stdlib.h>
#include <string.h>
-#include "serd/serd.h"
-#include "serd_stack.h"
+#include "serd_internal.h"
#define NS_XSD "http://www.w3.org/2001/XMLSchema#"
#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
@@ -185,12 +184,6 @@ eat_string(SerdReader reader, const char* str, unsigned n)
}
}
-static inline bool
-in_range(const uchar c, const uchar min, const uchar max)
-{
- return (c >= min && c <= max);
-}
-
#ifdef STACK_DEBUG
static inline bool
stack_is_top_string(SerdReader reader, Ref ref)
@@ -687,7 +680,7 @@ static inline uchar
read_nameStartChar(SerdReader reader, bool required)
{
const uint8_t c = peek_byte(reader);
- if (in_range(c, 'A', 'Z') || (c == '_') || in_range(c, 'a', 'z')) {
+ if (c == '_' || is_alpha(c)) {
return eat_byte(reader, c);
} else {
if (required) {
@@ -711,9 +704,8 @@ read_nameChar(SerdReader reader)
case '5': case '6': case '7': case '8': case '9':
return eat_byte(reader, c);
default:
- if (in_range(c, 0x300, 0x036F) || in_range(c, 0x203F, 0x2040)) {
- return eat_byte(reader, c);
- }
+ // TODO: 0x300-0x036F | 0x203F-0x2040
+ return 0;
}
return 0;
}
@@ -814,10 +806,10 @@ read_0_9(SerdReader reader, Ref str, bool at_least_one)
{
uint8_t c;
if (at_least_one) {
- TRY_RET(in_range(c = peek_byte(reader), '0', '9'));
+ TRY_RET(is_digit((c = peek_byte(reader))));
push_byte(reader, str, eat_byte(reader, c));
}
- while (in_range((c = peek_byte(reader)), '0', '9')) {
+ while (is_digit((c = peek_byte(reader)))) {
push_byte(reader, str, eat_byte(reader, c));
}
return str;
@@ -900,7 +892,7 @@ read_literal(SerdReader reader, Node* dest)
Ref str = 0;
Node datatype = SERD_NODE_NULL;
const uint8_t c = peek_byte(reader);
- if (in_range(c, '0', '9') || c == '-' || c == '+') {
+ if (c == '-' || c == '+' || is_digit(c)) {
return read_number(reader, dest);
} else if (c == '\"') {
str = read_quotedString(reader);
diff --git a/src/serd_stack.h b/src/serd_internal.h
index 7d8bcd07..bb3f3910 100644
--- a/src/serd_stack.h
+++ b/src/serd_internal.h
@@ -15,22 +15,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef SERD_STACK_H
-#define SERD_STACK_H
+#ifndef SERD_INTERNAL_H
+#define SERD_INTERNAL_H
#include <assert.h>
#include "serd/serd.h"
-/** An offset to start the stack at. Note 0 is reserved for NULL. */
-#define SERD_STACK_BOTTOM sizeof(void*)
-
+/** A dynamic stack in memory. */
typedef struct {
uint8_t* buf; ///< Stack memory
size_t buf_size; ///< Allocated size of buf (>= size)
size_t size; ///< Conceptual size of stack in buf
} SerdStack;
+/** An offset to start the stack at. Note 0 is reserved for NULL. */
+#define SERD_STACK_BOTTOM sizeof(void*)
+
static inline SerdStack
serd_stack_new(size_t size)
{
@@ -76,4 +77,25 @@ serd_stack_pop(SerdStack* stack, size_t n_bytes)
stack->size -= n_bytes;
}
-#endif // SERD_STACK_H
+/** Return true if @a c lies within [min...max] (inclusive) */
+static inline bool
+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 */
+static inline bool
+is_alpha(const uint8_t c)
+{
+ return in_range(c, 'A', 'Z') || in_range(c, 'a', 'z');
+}
+
+/** RFC2234: DIGIT ::= %x30-39 ; 0-9 */
+static inline bool
+is_digit(const uint8_t c)
+{
+ return in_range(c, '0', '9');
+}
+
+#endif // SERD_INTERNAL_H
diff --git a/src/uri.c b/src/uri.c
index c738724e..5b2e4423 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -19,31 +19,10 @@
#include <stdlib.h>
#include <string.h>
-#include "serd/serd.h"
+#include "serd_internal.h"
// #define URI_DEBUG 1
-/** Return true if @a c lies within [min...max] (inclusive) */
-static inline bool
-in_range(const char c, const char min, const char max)
-{
- return (c >= min && c <= max);
-}
-
-/** RFC2234: ALPHA := %x41-5A / %x61-7A ; A-Z / a-z */
-static inline bool
-is_alpha(const uint8_t c)
-{
- return in_range(c, 'A', 'Z') || in_range(c, 'a', 'z');
-}
-
-/** RFC2234: DIGIT ::= %x30-39 ; 0-9 */
-static inline bool
-is_digit(const uint8_t c)
-{
- return in_range(c, '0', '9');
-}
-
SERD_API
bool
serd_uri_string_has_scheme(const uint8_t* utf8)
diff --git a/src/writer.c b/src/writer.c
index 93a2e4d1..94f91f49 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -19,8 +19,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include "serd/serd.h"
-#include "serd_stack.h"
+#include "serd_internal.h"
typedef struct {
const SerdString* graph;