From 2083889d4e40dd34073f6f9355ec081bce3914a5 Mon Sep 17 00:00:00 2001 From: Vlasta Vesely Date: Wed, 25 Apr 2018 16:13:34 +0200 Subject: [PATCH] add transliteration.c with a dummy transliteration loop --- Makefile | 2 +- transliteration.c | 30 ++++++++++++++++++++++++++++++ transliteration.h | 6 ++++++ utf8.c | 2 +- utf8.h | 2 +- 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 transliteration.c create mode 100644 transliteration.h diff --git a/Makefile b/Makefile index 3a65fce..9796375 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: all clean all: - $(CC) main.c syllable.c utf8.c -o main + $(CC) main.c syllable.c utf8.c transliteration.c -o main ./main clean: diff --git a/transliteration.c b/transliteration.c new file mode 100644 index 0000000..b838747 --- /dev/null +++ b/transliteration.c @@ -0,0 +1,30 @@ +#include +#include + +#include "transliteration.h" +#include "syllable.h" +#include "utf8.h" + +char *transliterate_devanagari_to_latin(const char *text) +{ + unsigned int length = strlen(text); + const char *ptr = text; + const char *end = ptr + length; + char *tmp; + unsigned long c; + struct syllable *head, *tail; + + head = syllable_alloc(""); + tail = head; + + while (ptr < end) { + c = utf8_unpack_char(ptr); + ptr += utf8_char_length(c); + + tmp = utf8_code_to_string(c); + tail = syllable_append(tail, tmp); + free(tmp); + } + + return syllable_chain_to_string(head); +} diff --git a/transliteration.h b/transliteration.h new file mode 100644 index 0000000..d1da50e --- /dev/null +++ b/transliteration.h @@ -0,0 +1,6 @@ +#ifndef __TRANSLITERATION_H +#define __TRANSLITERATION_H + +char *transliterate_devanagari_to_latin(const char *text); + +#endif /* __TRANSLITERATION_H */ diff --git a/utf8.c b/utf8.c index 20ca835..1ae6faa 100644 --- a/utf8.c +++ b/utf8.c @@ -1,7 +1,7 @@ #include #include "utf8.h" -unsigned long utf8_unpack_char(char *src) +unsigned long utf8_unpack_char(const char *src) { unsigned long c = 0; diff --git a/utf8.h b/utf8.h index 772384d..7d0694e 100644 --- a/utf8.h +++ b/utf8.h @@ -1,7 +1,7 @@ #ifndef __UTF8_H #define __UTF8_H -unsigned long utf8_unpack_char(char *src); +unsigned long utf8_unpack_char(const char *src); void utf8_pack_char(char *dest, unsigned long c); unsigned int utf8_char_length(unsigned long c);