diff options
Diffstat (limited to 'configutil/src/lib/tags.cpp')
-rw-r--r-- | configutil/src/lib/tags.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/configutil/src/lib/tags.cpp b/configutil/src/lib/tags.cpp new file mode 100644 index 00000000000..50b01c80ba2 --- /dev/null +++ b/configutil/src/lib/tags.cpp @@ -0,0 +1,39 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/fastos/fastos.h> + +#include <vespa/vespalib/stllike/string.h> + +#include "tags.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); +} + +} |