/* This file was generated automatically by the Snowball to ISO C++ compiler */

#include <limits.h>
#include "danish.h"

#define s_0_0 (s_0_1 + 2)
static const symbol s_pool[] = {
#define s_0_1 0
'e', 't', 'h', 'e', 'd',
#define s_0_2 s_0_4
#define s_0_3 (s_0_0 + 1)
#define s_0_4 5
'e', 'r', 'e', 'd', 'e',
#define s_0_5 (s_0_6 + 2)
#define s_0_6 s_0_20
#define s_0_7 s_0_21
#define s_0_8 s_0_22
#define s_0_9 s_0_2
#define s_0_10 s_0_5
#define s_0_11 s_0_25
#define s_0_12 s_0_6
#define s_0_13 s_0_2
#define s_0_14 10
'h', 'e', 'd', 'e', 'r',
#define s_0_15 15
'e', 'r', 'e', 'r',
#define s_0_16 (s_0_17 + 3)
#define s_0_17 19
'h', 'e', 'd', 's',
#define s_0_18 (s_0_19 + 3)
#define s_0_19 (s_0_20 + 2)
#define s_0_20 23
'e', 'r', 'e', 'n', 'd', 'e', 's',
#define s_0_21 30
'e', 'n', 'e', 's',
#define s_0_22 34
'e', 'r', 'n', 'e', 's',
#define s_0_23 39
'e', 'r', 'e', 's',
#define s_0_24 (s_0_25 + 3)
#define s_0_25 43
'h', 'e', 'd', 'e', 'n', 's',
#define s_0_26 49
'e', 'r', 'e', 'n', 's',
#define s_0_27 54
'e', 'r', 's',
#define s_0_28 (s_0_29 + 2)
#define s_0_29 57
'e', 'r', 'e', 't', 's',
#define s_0_30 s_0_1
#define s_0_31 s_0_29
#define s_1_0 62
'g', 'd',
#define s_1_1 64
'd', 't',
#define s_1_2 66
'g', 't',
#define s_1_3 68
'k', 't',
#define s_2_0 (s_2_1 + 1)
#define s_2_1 (s_2_2 + 1)
#define s_2_2 70
'e', 'l', 'i', 'g',
#define s_2_3 74
'e', 'l', 's',
#define s_2_4 77
'l', 0xC3, 0xB8, 's', 't',
};


static const struct among a_0[32] =
{
/*  0 */ { 3, s_0_0, -1, 1},
/*  1 */ { 5, s_0_1, 0, 1},
/*  2 */ { 4, s_0_2, -1, 1},
/*  3 */ { 1, s_0_3, -1, 1},
/*  4 */ { 5, s_0_4, 3, 1},
/*  5 */ { 4, s_0_5, 3, 1},
/*  6 */ { 6, s_0_6, 5, 1},
/*  7 */ { 3, s_0_7, 3, 1},
/*  8 */ { 4, s_0_8, 3, 1},
/*  9 */ { 3, s_0_9, 3, 1},
/* 10 */ { 2, s_0_10, -1, 1},
/* 11 */ { 5, s_0_11, 10, 1},
/* 12 */ { 4, s_0_12, 10, 1},
/* 13 */ { 2, s_0_13, -1, 1},
/* 14 */ { 5, s_0_14, 13, 1},
/* 15 */ { 4, s_0_15, 13, 1},
/* 16 */ { 1, s_0_16, -1, 2},
/* 17 */ { 4, s_0_17, 16, 1},
/* 18 */ { 2, s_0_18, 16, 1},
/* 19 */ { 5, s_0_19, 18, 1},
/* 20 */ { 7, s_0_20, 19, 1},
/* 21 */ { 4, s_0_21, 18, 1},
/* 22 */ { 5, s_0_22, 18, 1},
/* 23 */ { 4, s_0_23, 18, 1},
/* 24 */ { 3, s_0_24, 16, 1},
/* 25 */ { 6, s_0_25, 24, 1},
/* 26 */ { 5, s_0_26, 24, 1},
/* 27 */ { 3, s_0_27, 16, 1},
/* 28 */ { 3, s_0_28, 16, 1},
/* 29 */ { 5, s_0_29, 28, 1},
/* 30 */ { 2, s_0_30, -1, 1},
/* 31 */ { 4, s_0_31, 30, 1}
};


static const struct among a_1[4] =
{
/*  0 */ { 2, s_1_0, -1, -1},
/*  1 */ { 2, s_1_1, -1, -1},
/*  2 */ { 2, s_1_2, -1, -1},
/*  3 */ { 2, s_1_3, -1, -1}
};


static const struct among a_2[5] =
{
/*  0 */ { 2, s_2_0, -1, 1},
/*  1 */ { 3, s_2_1, 0, 1},
/*  2 */ { 4, s_2_2, 1, 1},
/*  3 */ { 3, s_2_3, -1, 1},
/*  4 */ { 5, s_2_4, -1, 2}
};

static const unsigned char g_v[] = { 17, 65, 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 128 };

static const unsigned char g_s_ending[] = { 239, 254, 42, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16 };

static const symbol s_0[] = { 's', 't' };
static const symbol s_1[] = { 'i', 'g' };
static const symbol s_2[] = { 'l', 0xC3, 0xB8, 's' };

int Xapian::InternalStemDanish::r_mark_regions() { /* forwardmode */
    I_p1 = l; /* p1 = <integer expression>, line 31 */
    {   int c_test1 = c; /* test, line 33 */
        {   int ret = skip_utf8(p, c, 0, l, + 3); /* hop, line 33 */
            if (ret < 0) return 0;
            c = ret;
        }
        I_x = c; /* setmark x, line 33 */
        c = c_test1;
    }
    if (out_grouping_U(g_v, 97, 248, 1) < 0) return 0; /* goto */ /* grouping v, line 34 */
    {   int ret = in_grouping_U(g_v, 97, 248, 1); /* gopast */ /* non v, line 34 */
        if (ret < 0) return 0;
        c += ret;
    }
    I_p1 = c; /* setmark p1, line 34 */
    /* try, line 35 */
    if (!(I_p1 < I_x)) goto lab0; /* p1 < <integer expression>, line 35 */
    I_p1 = I_x; /* p1 = <integer expression>, line 35 */
lab0:
    return 1;
}

int Xapian::InternalStemDanish::r_main_suffix() { /* backwardmode */
    int among_var;
    {   int m1 = l - c; (void)m1; /* setlimit, line 41 */
        int mlimit1;
        if (c < I_p1) return 0;
        c = I_p1; /* tomark, line 41 */
        mlimit1 = lb; lb = c;
        c = l - m1;
        ket = c; /* [, line 41 */
        if (c <= lb || p[c - 1] >> 5 != 3 || !((1851440 >> (p[c - 1] & 0x1f)) & 1)) { lb = mlimit1; return 0; } /* substring, line 41 */
        among_var = find_among_b(s_pool, a_0, 32, 0, 0);
        if (!(among_var)) { lb = mlimit1; return 0; }
        bra = c; /* ], line 41 */
        lb = mlimit1;
    }
    switch(among_var) { /* among, line 42 */
        case 0: return 0;
        case 1:
            if (slice_del() == -1) return -1; /* delete, line 48 */
            break;
        case 2:
            if (in_grouping_b_U(g_s_ending, 97, 229, 0)) return 0; /* grouping s_ending, line 50 */
            if (slice_del() == -1) return -1; /* delete, line 50 */
            break;
    }
    return 1;
}

int Xapian::InternalStemDanish::r_consonant_pair() { /* backwardmode */
    {   int m_test1 = l - c; /* test, line 55 */
        {   int m2 = l - c; (void)m2; /* setlimit, line 56 */
            int mlimit2;
            if (c < I_p1) return 0;
            c = I_p1; /* tomark, line 56 */
            mlimit2 = lb; lb = c;
            c = l - m2;
            ket = c; /* [, line 56 */
            if (c - 1 <= lb || (p[c - 1] != 100 && p[c - 1] != 116)) { lb = mlimit2; return 0; } /* substring, line 56 */
            if (!(find_among_b(s_pool, a_1, 4, 0, 0))) { lb = mlimit2; return 0; }
            bra = c; /* ], line 56 */
            lb = mlimit2;
        }
        c = l - m_test1;
    }
    {   int ret = skip_utf8(p, c, lb, 0, -1);
        if (ret < 0) return 0;
        c = ret; /* next, line 62 */
    }
    bra = c; /* ], line 62 */
    if (slice_del() == -1) return -1; /* delete, line 62 */
    return 1;
}

int Xapian::InternalStemDanish::r_other_suffix() { /* backwardmode */
    int among_var;
    {   int m1 = l - c; (void)m1; /* do, line 66 */
        ket = c; /* [, line 66 */
        if (!(eq_s_b(2, s_0))) goto lab0; /* literal, line 66 */
        bra = c; /* ], line 66 */
        if (!(eq_s_b(2, s_1))) goto lab0; /* literal, line 66 */
        if (slice_del() == -1) return -1; /* delete, line 66 */
    lab0:
        c = l - m1;
    }
    {   int m2 = l - c; (void)m2; /* setlimit, line 67 */
        int mlimit2;
        if (c < I_p1) return 0;
        c = I_p1; /* tomark, line 67 */
        mlimit2 = lb; lb = c;
        c = l - m2;
        ket = c; /* [, line 67 */
        if (c - 1 <= lb || p[c - 1] >> 5 != 3 || !((1572992 >> (p[c - 1] & 0x1f)) & 1)) { lb = mlimit2; return 0; } /* substring, line 67 */
        among_var = find_among_b(s_pool, a_2, 5, 0, 0);
        if (!(among_var)) { lb = mlimit2; return 0; }
        bra = c; /* ], line 67 */
        lb = mlimit2;
    }
    switch(among_var) { /* among, line 68 */
        case 0: return 0;
        case 1:
            if (slice_del() == -1) return -1; /* delete, line 70 */
            {   int m3 = l - c; (void)m3; /* do, line 70 */
                {   int ret = r_consonant_pair(); /* call consonant_pair, line 70 */
                    if (ret == 0) goto lab1;
                    if (ret < 0) return ret;
                }
            lab1:
                c = l - m3;
            }
            break;
        case 2:
            {   int ret = slice_from_s(4, s_2); /* <-, line 72 */
                if (ret < 0) return ret;
            }
            break;
    }
    return 1;
}

int Xapian::InternalStemDanish::r_undouble() { /* backwardmode */
    {   int m1 = l - c; (void)m1; /* setlimit, line 76 */
        int mlimit1;
        if (c < I_p1) return 0;
        c = I_p1; /* tomark, line 76 */
        mlimit1 = lb; lb = c;
        c = l - m1;
        ket = c; /* [, line 76 */
        if (out_grouping_b_U(g_v, 97, 248, 0)) { lb = mlimit1; return 0; } /* non v, line 76 */
        bra = c; /* ], line 76 */
        {   symbol * ret = slice_to(S_ch); /* -> ch, line 76 */
            if (ret == 0) return -1;
            S_ch = ret;
        }
        lb = mlimit1;
    }
    if (!(eq_v_b(S_ch))) return 0; /* name ch, line 77 */
    if (slice_del() == -1) return -1; /* delete, line 78 */
    return 1;
}

int Xapian::InternalStemDanish::stem() { /* forwardmode */
    {   int c1 = c; /* do, line 84 */
        {   int ret = r_mark_regions(); /* call mark_regions, line 84 */
            if (ret == 0) goto lab0;
            if (ret < 0) return ret;
        }
    lab0:
        c = c1;
    }
    lb = c; c = l; /* backwards, line 85 */

    {   int m2 = l - c; (void)m2; /* do, line 86 */
        {   int ret = r_main_suffix(); /* call main_suffix, line 86 */
            if (ret == 0) goto lab1;
            if (ret < 0) return ret;
        }
    lab1:
        c = l - m2;
    }
    {   int m3 = l - c; (void)m3; /* do, line 87 */
        {   int ret = r_consonant_pair(); /* call consonant_pair, line 87 */
            if (ret == 0) goto lab2;
            if (ret < 0) return ret;
        }
    lab2:
        c = l - m3;
    }
    {   int m4 = l - c; (void)m4; /* do, line 88 */
        {   int ret = r_other_suffix(); /* call other_suffix, line 88 */
            if (ret == 0) goto lab3;
            if (ret < 0) return ret;
        }
    lab3:
        c = l - m4;
    }
    {   int m5 = l - c; (void)m5; /* do, line 89 */
        {   int ret = r_undouble(); /* call undouble, line 89 */
            if (ret == 0) goto lab4;
            if (ret < 0) return ret;
        }
    lab4:
        c = l - m5;
    }
    c = lb;
    return 1;
}

Xapian::InternalStemDanish::InternalStemDanish()
    : I_x(0), I_p1(0), S_ch(0)
{
    S_ch = create_s();
}

Xapian::InternalStemDanish::~InternalStemDanish()
{
    lose_s(S_ch);
}

std::string
Xapian::InternalStemDanish::get_description() const
{
    return "danish";
}
