aboutsummaryrefslogtreecommitdiffstats
path: root/configutil/src/lib/tags.cpp
blob: f887d3a63b9e3e797422b07048640f96280564e5 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "tags.h"
#include <vespa/vespalib/stllike/string.h>

namespace configdefinitions {

vespalib::string upcase(const vespalib::string &orig)
{
    vespalib::string upper(orig);
    for (size_t i = 0; i < orig.size(); ++i) {
        int l = (unsigned char)orig[i];
        upper[i] = (unsigned char)toupper(l);
    }
    return upper;
}

bool tagsContain(const vespalib::string &tags, const vespalib::string &tag)
{
    vespalib::string allupper = upcase(tags);
    vespalib::string tagupper = upcase(tag);

    for (;;) {
        size_t pos = allupper.rfind(' ');
        if (pos == vespalib::string::npos) {
            break;
        }
        if (allupper.substr(pos+1) == tagupper) {
            return true;
        }
        allupper.resize(pos);
    }
    return (allupper == tagupper);
}

}