Ejemplo n.º 1
0
Archivo: bogo.c Proyecto: hainp/bogo-c
/*
Apply all transformations in a list of transformations into a result string.

input_list = [{
    type: TRANS_APPEND,
    key: "a"
},
{
    type: TRANS_TONE,
    key: "s",
    effect: TONE_ACUTE,
    targets: [input_list[0]]
}]

output = "á"
*/
void flatten(bgstr output,
             struct List *transList)
{
    int output_index = 0;

    struct ListItem *iterator = transList->first;
    while (iterator != NULL) {

        struct TransT trans = *((struct TransT *) iterator->item);

        switch (trans.rule->type) {
        case TRANS_APPEND:
            bgstrAssign(output + output_index, trans.rule->key);
            trans.dest_index = output_index;
            output_index++;  // Only TRANS_APPEND creates a new char
            break;
        case TRANS_TONE:
            addToneToChar(output + trans.target->dest_index,
                          trans.rule->transMethod.tone);
            break;
        case TRANS_MARK:
            addMarkToChar(output + trans.target->dest_index,
                          trans.rule->transMethod.mark);
            break;
        }

        iterator = iterator->next;
    }
}
Ejemplo n.º 2
0
int testAddToneToChar(void) {
    initTestCase ("Add tone to char");

    bgstr target = "a";
    addToneToChar(target, TONE_ACUTE);
    assertStr("á", target);

    // Consonants should not be touched
    bgstrAssign(target, "n");
    addToneToChar(target, TONE_ACUTE);
    assertStr("n", target);

    // Should work with complex vowel
    bgstrAssign(target, "ư");
    addToneToChar(target, TONE_ACUTE);
    assertStr("ứ", target);

    // Should also change tone
    bgstrAssign(target, "ứ");
    addToneToChar(target, TONE_GRAVE);
    assertStr("ừ", target);

    return finishTestCase ();
}