add transliteration.c with a dummy transliteration loop

This commit is contained in:
Vlasta Vesely 2018-04-25 16:13:34 +02:00
parent 8480315ea9
commit 2083889d4e
5 changed files with 39 additions and 3 deletions

View file

@ -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:

30
transliteration.c Normal file
View file

@ -0,0 +1,30 @@
#include <stdlib.h>
#include <string.h>
#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);
}

6
transliteration.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef __TRANSLITERATION_H
#define __TRANSLITERATION_H
char *transliterate_devanagari_to_latin(const char *text);
#endif /* __TRANSLITERATION_H */

2
utf8.c
View file

@ -1,7 +1,7 @@
#include <stdlib.h>
#include "utf8.h"
unsigned long utf8_unpack_char(char *src)
unsigned long utf8_unpack_char(const char *src)
{
unsigned long c = 0;

2
utf8.h
View file

@ -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);