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

#include <config.h>
#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 33 */
    {   int c_test1 = c; /* test, line 35 */
        {   int ret = skip_utf8(p, c, 0, l, + 3); /* hop, line 35 */
            if (ret < 0) return 0;
            c = ret;
        }
        I_x = c; /* setmark x, line 35 */
        c = c_test1;
    }
    if (out_grouping_U(g_v, 97, 248, 1) < 0) return 0; /* goto */ /* grouping v, line 36 */
    {   int ret = in_grouping_U(g_v, 97, 248, 1); /* gopast */ /* non v, line 36 */
        if (ret < 0) return 0;
        c += ret;
    }
    I_p1 = c; /* setmark p1, line 36 */
    /* try, line 37 */
    if (!(I_p1 < I_x)) goto lab0; /* p1 < <integer expression>, line 37 */
    I_p1 = I_x; /* p1 = <integer expression>, line 37 */
lab0:
    return 1;
}

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

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

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

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

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

    {   int m2 = l - c; (void)m2; /* do, line 88 */
        {   int ret = r_main_suffix(); /* call main_suffix, line 88 */
            if (ret == 0) goto lab1;
            if (ret < 0) return ret;
        }
    lab1:
        c = l - m2;
    }
    {   int m3 = l - c; (void)m3; /* do, line 89 */
        {   int ret = r_consonant_pair(); /* call consonant_pair, line 89 */
            if (ret == 0) goto lab2;
            if (ret < 0) return ret;
        }
    lab2:
        c = l - m3;
    }
    {   int m4 = l - c; (void)m4; /* do, line 90 */
        {   int ret = r_other_suffix(); /* call other_suffix, line 90 */
            if (ret == 0) goto lab3;
            if (ret < 0) return ret;
        }
    lab3:
        c = l - m4;
    }
    {   int m5 = l - c; (void)m5; /* do, line 91 */
        {   int ret = r_undouble(); /* call undouble, line 91 */
            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";
}
