1 /*
2 * (C) 2009 Jack Lloyd
3 *
4 * Distributed under the terms of the Botan license
5 */
6 
7 #include <iostream>
8 #include <vector>
9 #include <string>
10 
11 #include "common.h"
12 
strip_comments(std::string & line)13 void strip_comments(std::string& line)
14    {
15    if(line.find('#') != std::string::npos)
16       line = line.erase(line.find('#'), std::string::npos);
17    }
18 
strip_newlines(std::string & line)19 void strip_newlines(std::string& line)
20    {
21    while(line.find('\n') != std::string::npos)
22       line = line.erase(line.find('\n'), 1);
23    }
24 
25 /* Strip comments, whitespace, etc */
strip(std::string & line)26 void strip(std::string& line)
27    {
28    strip_comments(line);
29 
30 #if 0
31    while(line.find(' ') != std::string::npos)
32       line = line.erase(line.find(' '), 1);
33 #endif
34 
35    while(line.find('\t') != std::string::npos)
36       line = line.erase(line.find('\t'), 1);
37    }
38 
parse(const std::string & line)39 std::vector<std::string> parse(const std::string& line)
40    {
41    const char DELIMITER = ':';
42    std::vector<std::string> substr;
43    std::string::size_type start = 0, end = line.find(DELIMITER);
44    while(end != std::string::npos)
45       {
46       substr.push_back(line.substr(start, end-start));
47       start = end+1;
48       end = line.find(DELIMITER, start);
49       }
50    if(line.size() > start)
51       substr.push_back(line.substr(start));
52    while(substr.size() <= 4) // at least 5 substr, some possibly empty
53       substr.push_back("");
54    return substr;
55    }
56 
57