From ae56600cde7cc035cf6c5cbeb4fea58adfa2c7a2 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Jan 2014 01:25:53 +0000 Subject: s/check/test/g --- tests/common.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/common.cpp (limited to 'tests/common.cpp') diff --git a/tests/common.cpp b/tests/common.cpp new file mode 100644 index 000000000..31bc60435 --- /dev/null +++ b/tests/common.cpp @@ -0,0 +1,56 @@ +/* +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include +#include +#include + +#include "common.h" + +void strip_comments(std::string& line) + { + if(line.find('#') != std::string::npos) + line = line.erase(line.find('#'), std::string::npos); + } + +void strip_newlines(std::string& line) + { + while(line.find('\n') != std::string::npos) + line = line.erase(line.find('\n'), 1); + } + +/* Strip comments, whitespace, etc */ +void strip(std::string& line) + { + strip_comments(line); + +#if 0 + while(line.find(' ') != std::string::npos) + line = line.erase(line.find(' '), 1); +#endif + + while(line.find('\t') != std::string::npos) + line = line.erase(line.find('\t'), 1); + } + +std::vector parse(const std::string& line) + { + const char DELIMITER = ':'; + std::vector substr; + std::string::size_type start = 0, end = line.find(DELIMITER); + while(end != std::string::npos) + { + substr.push_back(line.substr(start, end-start)); + start = end+1; + end = line.find(DELIMITER, start); + } + if(line.size() > start) + substr.push_back(line.substr(start)); + while(substr.size() <= 4) // at least 5 substr, some possibly empty + substr.push_back(""); + return substr; + } + -- cgit v1.2.3