Add contains method to ValueTokenizer
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
@ -84,6 +85,10 @@ bool ValueTokenizer::has_next() const {
|
|||||||
return current != tokens.cend();
|
return current != tokens.cend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ValueTokenizer::contains(const std::string & value) const {
|
||||||
|
return std::find(tokens.cbegin(), tokens.cend(), value) != tokens.cend();
|
||||||
|
}
|
||||||
|
|
||||||
std::string ValueTokenizer::next_string() {
|
std::string ValueTokenizer::next_string() {
|
||||||
if (has_next()) {
|
if (has_next()) {
|
||||||
std::string value = *current;
|
std::string value = *current;
|
||||||
|
|||||||
@ -91,6 +91,7 @@ public:
|
|||||||
double next_double();
|
double next_double();
|
||||||
|
|
||||||
bool has_next() const;
|
bool has_next() const;
|
||||||
|
bool contains(const std::string & value) const;
|
||||||
void skip(int ntokens);
|
void skip(int ntokens);
|
||||||
|
|
||||||
size_t count() const;
|
size_t count() const;
|
||||||
|
|||||||
@ -112,3 +112,14 @@ TEST(ValueTokenizer, valid_double_with_exponential) {
|
|||||||
ValueTokenizer values("3.14e22");
|
ValueTokenizer values("3.14e22");
|
||||||
ASSERT_DOUBLE_EQ(values.next_double(), 3.14e22);
|
ASSERT_DOUBLE_EQ(values.next_double(), 3.14e22);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ValueTokenizer, contains) {
|
||||||
|
ValueTokenizer values("test word");
|
||||||
|
ASSERT_TRUE(values.contains("test"));
|
||||||
|
ASSERT_TRUE(values.contains("word"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ValueTokenizer, not_contains) {
|
||||||
|
ValueTokenizer values("test word");
|
||||||
|
ASSERT_FALSE(values.contains("test2"));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user