summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2019-01-03 22:45:18 +0300
committerOxore <oxore@protonmail.com>2019-01-03 22:49:40 +0300
commit5ecd8885556cdfc07d2bccaede45f86e329da637 (patch)
treefd23f04ad159bcae5d863ac788df140c4b4465ce /src
parent6c3579c976a14c4eda8964491c649839a189828f (diff)
Move unicode module to separate library lib8
Diffstat (limited to 'src')
-rw-r--r--src/engine.c2
-rw-r--r--src/target/test.c89
-rw-r--r--src/text.c2
-rw-r--r--src/unicode.c54
4 files changed, 13 insertions, 134 deletions
diff --git a/src/engine.c b/src/engine.c
index 2a5755b..bad04f5 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -25,6 +25,7 @@
*
* */
+#include <f8.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -38,7 +39,6 @@
#include "vector.h"
#include "text.h"
#include "field.h"
-#include "unicode.h"
#include "painter.h"
#include "engine.h"
diff --git a/src/target/test.c b/src/target/test.c
index b807b92..a92642a 100644
--- a/src/target/test.c
+++ b/src/target/test.c
@@ -1,79 +1,20 @@
#include "munit.h"
-#include "unicode.h"
-
-struct u_pair {
- char *utf8;
- wchar_t *utf32;
-};
-
-struct u_pair text_fixture[] = {
- {
- .utf8 = "Single byte ascii symbols string",
- .utf32 = L"Single byte ascii symbols string"
- },
- {
- .utf8 = "\u041A\u0438\u0440\u0438\u043B\u043B\u0438\u0446\u0430",
- .utf32 = L"\u041A\u0438\u0440\u0438\u043B\u043B\u0438\u0446\u0430"
- },
- {
- .utf8 = "\u0814\u0820\u080C\u081D\u0813\u0829\u0809\u080C",
- .utf32 = L"\u0814\u0820\u080C\u081D\u0813\u0829\u0809\u080C"
- },
- {
- .utf8 = "𓁹",
- .utf32 = L"𓁹"
- }
-};
-
-
-static void *test_utf8_strlen_setup(const MunitParameter params[],
- void *user_data)
-{
- (void) params;
- (void) user_data;
-
- return text_fixture;
-}
-
-static MunitResult test_utf8_strlen(const MunitParameter params[],
- void *fixture)
+static void *test_dummy_setup(
+ const MunitParameter params[],
+ void *user_data)
{
(void) params;
- struct u_pair *f = fixture;
- for (int i = 0; i < 4; i++)
- munit_assert_ulong(utf8_strlen(f[i].utf8) * (i + 1),
- ==, strlen(f[i].utf8));
-
- return MUNIT_OK;
-}
-
-static void *test_utf8to32_strcpy_setup(const MunitParameter params[],
- void *user_data)
-{
- (void) params;
- (void) user_data;
-
- return text_fixture;
+ return user_data;
}
-static MunitResult test_utf8to32_strcpy(const MunitParameter params[],
- void *fixture)
+static MunitResult test_dummy(
+ const MunitParameter params[],
+ void *fixture)
{
(void) params;
-
- struct u_pair *f = fixture;
- size_t len;
- wchar_t *str;
-
- for (int i = 0; i < 4; i++) {
- len = utf8_strlen(f[i].utf8);
- str = malloc((len + 1) * sizeof(wchar_t));
- utf8to32_strcpy(str, f[i].utf8);
- munit_assert_uint(memcmp(str, f[i].utf32, len), ==, 0);
- free(str);
- }
+ (void) fixture;
return MUNIT_OK;
}
@@ -82,17 +23,9 @@ static const MunitSuite test_suite = {
"unit",
(MunitTest[]){
{
- "/unicode/utf8_strlen",
- test_utf8_strlen,
- test_utf8_strlen_setup,
- NULL,
- MUNIT_TEST_OPTION_NONE,
- NULL
- },
- {
- "/unicode/utf8to32_strcpy",
- test_utf8to32_strcpy,
- test_utf8to32_strcpy_setup,
+ "/dummy/dummy",
+ test_dummy,
+ test_dummy_setup,
NULL,
MUNIT_TEST_OPTION_NONE,
NULL
diff --git a/src/text.c b/src/text.c
index 3b361dd..9bace21 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1,3 +1,4 @@
+#include <f8.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -6,7 +7,6 @@
#include "idlist.h"
#include "vector.h"
#include "text.h"
-#include "unicode.h"
static FILE *openFile(char *filename)
{
diff --git a/src/unicode.c b/src/unicode.c
deleted file mode 100644
index de25ffb..0000000
--- a/src/unicode.c
+++ /dev/null
@@ -1,54 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-
-#include "unicode.h"
-
-static inline size_t utf8_char_len(unsigned char c)
-{
- if (c > 0x00 && c < 0xC0)
- return 1;
- else if (c >= 0xC2 && c < 0xE0)
- return 2;
- else if (c >= 0xE0 && c < 0xF0)
- return 3;
- else if (c >= 0xF0 && c < 0xF5)
- return 4;
- else
- return 0;
-}
-
-size_t utf8_strlen(char *string)
-{
- size_t len = 0, keep = 0;
- for (char *c = string; *c; (keep ? --keep : ++len), ++c)
- if (!keep)
- keep = (keep = utf8_char_len(*c)) ? keep - 1 : keep;
- return len;
-}
-
-void utf8to32_strcpy(wchar_t *dest, char *src)
-{
- wchar_t *dc = dest;
- char *c = src;
- size_t len = 0;
- while (*c) {
- int clen = utf8_char_len(*c);
- if (clen == 1) {
- dc[len] = c[0] & 0x7f;
- } else if (clen == 2) {
- dc[len] = ((c[0] & 0x1f) << 6) | ((c[1] & 0x3f) << 0);
- } else if (clen == 3) {
- dc[len] = ((c[0] & 0x0f) << 12) | ((c[1] & 0x3f) << 6)
- | ((c[2] & 0x3f) << 0);
- } else if (clen == 4) {
- dc[len] = ((c[0] & 0x07) << 18) | ((c[1] & 0x3f) << 12)
- | ((c[2] & 0x3f) << 6) | ((c[3] & 0x3f) << 0);
- } else {
- dc[len] = 0;
- return;
- }
- c += clen;
- ++len;
- }
- dc[len] = 0;
-}