/* Generated from russian.sbl by Snowball 3.1.1 - https://snowballstem.org/ */

#include <xapian/stem.h>

#define SNOWBALL_RUNTIME_THROW_EXCEPTIONS
#include "languages/snowball_runtime.h"

namespace Xapian::Internal::Snowball {

class Russian : public Xapian::StemImplementation {
  public:
    struct SN_local {
        struct SN_env z;
    };

  private:
    SN_local zlocal = {};

    void close_env() {
        struct SN_env * z = &(zlocal.z);
        lose_s(z->p);
    }

    static int stem(struct SN_env * z);

  public:
    Russian() {
        struct SN_env * z = &(zlocal.z);
        z->p = create_s();
    }

    ~Russian() {
        close_env();
    }

    std::string operator()(const std::string& word) override {
        struct SN_env* z = &(zlocal.z);
        const symbol* s = reinterpret_cast<const symbol*>(word.data());
        int s_size = word.size() > INT_MAX ? INT_MAX : word.size();
        replace_s(z, 0, z->l, s_size, s);
        z->c = 0;
        Xapian::Internal::Snowball::Russian::stem(z);
        return std::string(reinterpret_cast<const char*>(z->p), SIZE(z->p));
    }

    std::string get_description() const override {
        return "russian";
    }
};

}
