implement syllable modifiers
This commit is contained in:
parent
63eb389ae2
commit
2f6c487976
3 changed files with 54 additions and 4 deletions
13
iast.c
13
iast.c
|
@ -1,6 +1,13 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "iast.h"
|
||||
|
||||
void diacritics_modifier_test(struct syllable *syllable)
|
||||
{
|
||||
free(syllable->data);
|
||||
syllable->data = strdup("X");
|
||||
}
|
||||
|
||||
static const struct transliteration_letter table_letters[] = {
|
||||
|
||||
/* Vowels */
|
||||
|
@ -62,12 +69,18 @@ static const struct transliteration_letter table_letters[] = {
|
|||
{0, NULL}
|
||||
};
|
||||
|
||||
static const struct transliteration_modifier table_modifiers[] = {
|
||||
{0x0940, diacritics_modifier_test},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
struct transliteration_context *transliteration_context_iast_alloc()
|
||||
{
|
||||
struct transliteration_context *context;
|
||||
|
||||
context = malloc(sizeof(*context));
|
||||
context->table_letters = table_letters;
|
||||
context->table_modifiers = table_modifiers;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -5,10 +5,30 @@
|
|||
#include "syllable.h"
|
||||
#include "utf8.h"
|
||||
|
||||
struct transliteration_letter *find_letter_by_code(unsigned long c,
|
||||
struct transliteration_letter *table)
|
||||
const struct transliteration_letter *find_letter_by_code(unsigned long c,
|
||||
const struct transliteration_letter *table)
|
||||
{
|
||||
struct transliteration_letter *walk = table;
|
||||
const struct transliteration_letter *walk = table;
|
||||
|
||||
if (c == 0)
|
||||
return NULL;
|
||||
|
||||
while (walk->code != 0) {
|
||||
if (c == walk->code)
|
||||
return walk;
|
||||
walk++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct transliteration_modifier *find_modifier_by_code(unsigned long c,
|
||||
const struct transliteration_modifier *table)
|
||||
{
|
||||
const struct transliteration_modifier *walk = table;
|
||||
|
||||
if (c == 0)
|
||||
return NULL;
|
||||
|
||||
while (walk->code != 0) {
|
||||
if (c == walk->code)
|
||||
|
@ -28,7 +48,8 @@ char *transliterate_devanagari_to_latin(const char *text,
|
|||
char *tmp;
|
||||
unsigned long c;
|
||||
struct syllable *head, *tail;
|
||||
struct transliteration_letter *letter;
|
||||
const struct transliteration_letter *letter;
|
||||
const struct transliteration_modifier *modifier;
|
||||
|
||||
head = syllable_alloc("");
|
||||
tail = head;
|
||||
|
@ -43,6 +64,12 @@ char *transliterate_devanagari_to_latin(const char *text,
|
|||
continue;
|
||||
}
|
||||
|
||||
modifier = find_modifier_by_code(c, context->table_modifiers);
|
||||
if (modifier != NULL) {
|
||||
modifier->modifier(tail);
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp = utf8_code_to_string(c);
|
||||
tail = syllable_append(tail, tmp);
|
||||
free(tmp);
|
||||
|
|
|
@ -1,13 +1,23 @@
|
|||
#ifndef __TRANSLITERATION_H
|
||||
#define __TRANSLITERATION_H
|
||||
|
||||
#include "syllable.h"
|
||||
|
||||
struct transliteration_letter {
|
||||
unsigned long code;
|
||||
const char *data;
|
||||
};
|
||||
|
||||
typedef void (*syllable_modification_t)(struct syllable *syllable);
|
||||
|
||||
struct transliteration_modifier {
|
||||
unsigned long code;
|
||||
syllable_modification_t modifier;
|
||||
};
|
||||
|
||||
struct transliteration_context {
|
||||
const struct transliteration_letter *table_letters;
|
||||
const struct transliteration_modifier *table_modifiers;
|
||||
};
|
||||
|
||||
char *transliterate_devanagari_to_latin(const char *text,
|
||||
|
|
Loading…
Reference in a new issue