add transliteration.c with a dummy transliteration loop
This commit is contained in:
parent
8480315ea9
commit
2083889d4e
5 changed files with 39 additions and 3 deletions
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(CC) main.c syllable.c utf8.c -o main
|
$(CC) main.c syllable.c utf8.c transliteration.c -o main
|
||||||
./main
|
./main
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
30
transliteration.c
Normal file
30
transliteration.c
Normal 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
6
transliteration.h
Normal 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
2
utf8.c
|
@ -1,7 +1,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
unsigned long utf8_unpack_char(char *src)
|
unsigned long utf8_unpack_char(const char *src)
|
||||||
{
|
{
|
||||||
unsigned long c = 0;
|
unsigned long c = 0;
|
||||||
|
|
||||||
|
|
2
utf8.h
2
utf8.h
|
@ -1,7 +1,7 @@
|
||||||
#ifndef __UTF8_H
|
#ifndef __UTF8_H
|
||||||
#define __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);
|
void utf8_pack_char(char *dest, unsigned long c);
|
||||||
|
|
||||||
unsigned int utf8_char_length(unsigned long c);
|
unsigned int utf8_char_length(unsigned long c);
|
||||||
|
|
Loading…
Add table
Reference in a new issue