diff options
author | lloyd <[email protected]> | 2014-01-01 01:25:53 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-01 01:25:53 +0000 |
commit | ae56600cde7cc035cf6c5cbeb4fea58adfa2c7a2 (patch) | |
tree | ea91d4d3c3aaad881a5080ba3d0f7227e16dcc74 /tests/common.cpp | |
parent | 5d40bdeb1b95c051d0655595846acd91cff6160f (diff) |
s/check/test/g
Diffstat (limited to 'tests/common.cpp')
-rw-r--r-- | tests/common.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
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 <iostream> +#include <vector> +#include <string> + +#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<std::string> parse(const std::string& line) + { + const char DELIMITER = ':'; + std::vector<std::string> 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; + } + |