aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary/src/tests/juniper/fakerewriter.cpp
blob: bbaf7079525d0c031af5b16d5e8f0997e620362f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "fakerewriter.h"
#include <vespa/vespalib/util/stringfmt.h>

namespace juniper
{

struct RewriteHandle
{
    RewriteHandle(std::string& in, uint32_t langid)
        : _s(in), _ls(""), _cnt(0), _langid(langid) {}

    std::string& next()
    {
	if (_cnt > 3 || _langid > 4)
            _ls = "";
	else
            _ls = vespalib::make_string("%s%d", _s.c_str(), _cnt++);
	return _ls;
    }
    std::string _s;
    std::string _ls;
    int _cnt;
    uint32_t _langid;
};
} // end namespace juniper

using namespace juniper;

const char* FakeRewriter::Name() const
{
    return _name.c_str();
}


RewriteHandle* FakeRewriter::Rewrite(uint32_t langid, const char* term)
{
    std::string t(term);
    if (langid > 4) return NULL;
    return new RewriteHandle(t, langid);
}

RewriteHandle* FakeRewriter::Rewrite(uint32_t langid, const char* term, size_t length)
{
    std::string t(term, length);
    if (langid > 4) return NULL;
    return new RewriteHandle(t, langid);
}


const char* FakeRewriter::NextTerm(RewriteHandle* exp, size_t& length)
{
    std::string& t = exp->next();
    if (t.size() == 0)
    {
        delete exp;
        return NULL;
    }
    length = t.size();
    return t.c_str();
}