summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorAndrew Sidwell <andy@entai.co.uk>2008-06-26 09:19:59 +0000
committerAndrew Sidwell <andy@entai.co.uk>2008-06-26 09:19:59 +0000
commit9acb291f49419a1ebe0235f6622ef4e2976f9f33 (patch)
tree17160c35fa7c0edb0f335cadb231a0268a779d2a /src/utils
parent968646860abb10e7db6dc810fc13cb9d41ba3237 (diff)
downloadlibhubbub-9acb291f49419a1ebe0235f6622ef4e2976f9f33.tar.gz
libhubbub-9acb291f49419a1ebe0235f6622ef4e2976f9f33.tar.bz2
Add code to adjust foreign attributes, as per spec.
svn path=/trunk/hubbub/; revision=4454
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/Makefile2
-rw-r--r--src/utils/string.c62
-rw-r--r--src/utils/string.h16
3 files changed, 79 insertions, 1 deletions
diff --git a/src/utils/Makefile b/src/utils/Makefile
index c9cd076..1910dc0 100644
--- a/src/utils/Makefile
+++ b/src/utils/Makefile
@@ -32,7 +32,7 @@ dirstack_$(sp) := $(d)
d := $(DIR)
# Sources
-SRCS_$(d) := dict.c errors.c utf8.c utf16.c
+SRCS_$(d) := dict.c errors.c utf8.c utf16.c string.c
# Append to sources for component
SOURCES += $(addprefix $(d), $(SRCS_$(d)))
diff --git a/src/utils/string.c b/src/utils/string.c
new file mode 100644
index 0000000..ea588f7
--- /dev/null
+++ b/src/utils/string.c
@@ -0,0 +1,62 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 Andrew Sidwell
+ */
+
+#include <stddef.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include "utils/string.h"
+
+
+/**
+ * Check if one string starts with another.
+ *
+ * \param a String to compare
+ * \param a_len Length of first string
+ * \param b String to compare
+ * \param b_len Length of second string
+ */
+bool hubbub_string_starts(const uint8_t *a, size_t a_len,
+ const uint8_t *b, size_t b_len)
+{
+ uint8_t z1, z2;
+
+ if (a_len < b_len)
+ return false;
+
+ for (const uint8_t *s1 = a, *s2 = b; b_len > 0; s1++, s2++, b_len--)
+ {
+ z1 = *s1;
+ z2 = *s2;
+ if (z1 != z2) return false;
+ if (!z1) return true;
+ }
+
+ return true;
+}
+
+/**
+ * Check that one string is exactly equal to another
+ *
+ * \param a String to compare
+ * \param a_len Length of first string
+ * \param b String to compare
+ * \param b_len Length of second string
+ */
+bool hubbub_string_match(const uint8_t *a, size_t a_len,
+ const uint8_t *b, size_t b_len)
+{
+ if (a_len != b_len)
+ return false;
+
+ for (const uint8_t *s1 = a, *s2 = b; b_len > 0; s1++, s2++, b_len--)
+ {
+ if (*s1 != *s2) return false;
+ }
+
+ return true;
+}
+
diff --git a/src/utils/string.h b/src/utils/string.h
new file mode 100644
index 0000000..d6bfe42
--- /dev/null
+++ b/src/utils/string.h
@@ -0,0 +1,16 @@
+/*
+ * This file is part of Hubbub.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 Andrew Sidwell
+ */
+
+#ifndef hubbub_string_h_
+#define hubbub_string_h_
+
+bool hubbub_string_starts(const uint8_t *a, size_t a_len,
+ const uint8_t *b, size_t b_len);
+bool hubbub_string_match(const uint8_t *a, size_t a_len,
+ const uint8_t *b, size_t b_len);
+
+#endif