summaryrefslogtreecommitdiff
path: root/liboil/utf8
diff options
context:
space:
mode:
authorDavid Schleef <ds@schleef.org>2005-03-01 23:29:52 +0000
committerDavid Schleef <ds@schleef.org>2005-03-01 23:29:52 +0000
commit06413ff9f05be868bb5dbbf3565afa2a0c027cdd (patch)
treee15d624abceb3db1475f58a28fc0767aca199111 /liboil/utf8
parent5533b305d3f81ab510f4e46bd70480563517ec95 (diff)
downloadliboil-06413ff9f05be868bb5dbbf3565afa2a0c027cdd.tar.gz
* configure.ac: add utf8
* examples/work/work.c: (test), (dump_array), (dump_test), (dump_source), (main): improve things a bit * liboil/Makefile.am: add utf8 * liboil/liboilfuncs.h: add utf8 * liboil/liboilfunction.c: (oil_class_optimize): Fix memleak. * liboil/utf8/Makefile.am: utf8 functions * liboil/utf8/utf8.c: (utf8_validate_test), (utf8_validate_ref): * liboil/utf8/utf8.h: same * testsuite/dso_check.c: (main): fix compilation
Diffstat (limited to 'liboil/utf8')
-rw-r--r--liboil/utf8/Makefile.am33
-rw-r--r--liboil/utf8/utf8.c89
-rw-r--r--liboil/utf8/utf8.h36
3 files changed, 158 insertions, 0 deletions
diff --git a/liboil/utf8/Makefile.am b/liboil/utf8/Makefile.am
new file mode 100644
index 0000000..163f592
--- /dev/null
+++ b/liboil/utf8/Makefile.am
@@ -0,0 +1,33 @@
+
+if USE_ALT_OPT
+opt_libs = libutf8_opt.la
+else
+opt_libs =
+endif
+
+noinst_LTLIBRARIES = libutf8.la $(opt_libs)
+
+noinst_HEADERS = utf8.h
+
+c_sources = utf8.c
+
+if HAVE_CPU_I386
+#i386_sources = utf8_i386.c
+else
+#i386_sources =
+endif
+
+if HAVE_CPU_POWERPC
+#powerpc_sources = utf8_powerpc.c
+else
+#powerpc_sources =
+endif
+
+libutf8_la_SOURCES = \
+ $(c_sources) $(i386_sources) $(powerpc_sources)
+libutf8_la_LIBADD = $(opt_libs)
+libutf8_la_CFLAGS = $(LIBOIL_CFLAGS)
+
+libutf8_opt_la_SOURCES = $(c_sources)
+libutf8_opt_la_CFLAGS = $(LIBOIL_CFLAGS) $(LIBOIL_OPT_CFLAGS)
+
diff --git a/liboil/utf8/utf8.c b/liboil/utf8/utf8.c
new file mode 100644
index 0000000..885d9e4
--- /dev/null
+++ b/liboil/utf8/utf8.c
@@ -0,0 +1,89 @@
+/*
+ * LIBOIL - Library of Optimized Inner Loops
+ * Copyright (c) 2004 David A. Schleef <ds@schleef.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <liboil/liboil.h>
+#include <liboil/liboiltest.h>
+#include <liboil/liboilrandom.h>
+#include "utf8.h"
+
+
+static void
+utf8_validate_test (OilTest *test)
+{
+ int i;
+ int n = test->n;
+ uint8_t *ptr = (uint8_t *)test->params[OIL_ARG_SRC1].src_data +
+ OIL_TEST_HEADER;
+
+ for (i=0;i<n;i++){
+ OIL_GET(ptr, i, uint8_t) = oil_rand_u8() & 0x7f;
+ }
+
+}
+
+OIL_DEFINE_CLASS_FULL (utf8_validate, "int32_t *d_1, uint8_t *s, int n",
+ utf8_validate_test);
+
+
+static void
+utf8_validate_ref (int32_t *d_1, uint8_t *s, int n)
+{
+ int i;
+ int extra_bytes;
+ int mask;
+
+ for(i=0;i<n;i++){
+ if (s[i] < 128) continue;
+ if ((s[i] & 0xe0) == 0xc0) {
+ extra_bytes = 1;
+ mask = 0x7f;
+ } else if ((s[i] & 0xf0) == 0xe0) {
+ extra_bytes = 2;
+ mask = 0x1f;
+ } else if ((s[i] & 0xf8) == 0xf0) {
+ extra_bytes = 3;
+ mask = 0x0f;
+ } else {
+ goto error;
+ }
+ if (i + extra_bytes >= n) goto error;
+ while(extra_bytes--) {
+ if ((s[i] & 0xc0) != 0x80) goto error;
+ i++;
+ }
+ }
+
+error:
+ d_1[0] = i;
+}
+
+OIL_DEFINE_IMPL_REF (utf8_validate_ref, utf8_validate);
+
diff --git a/liboil/utf8/utf8.h b/liboil/utf8/utf8.h
new file mode 100644
index 0000000..2145461
--- /dev/null
+++ b/liboil/utf8/utf8.h
@@ -0,0 +1,36 @@
+/*
+ * LIBOIL - Library of Optimized Inner Loops
+ * Copyright (c) 2004 David A. Schleef <ds@schleef.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBOIL_MD5_H_
+#define _LIBOIL_MD5_H_
+
+#include <liboil/liboilfunction.h>
+
+OIL_DECLARE_CLASS(utf8_validate);
+
+#endif
+