CMS 3D CMS Logo

Parse.cc
Go to the documentation of this file.
4 #include <boost/tokenizer.hpp>
5 #include <fstream>
6 #include <iostream>
7 
8 namespace edm {
9 
12  std::ifstream input(filename.c_str());
13  if (!input) {
14  throw edm::Exception(errors::Configuration, "MissingFile") << "Cannot read file " << filename;
15  }
17  while (getline(input, buffer)) {
18  // getline strips newlines; we have to put them back by hand.
19  result += buffer;
20  result += '\n';
21  }
22  return result;
23  }
24 
27  while (getline(std::cin, line)) {
28  output += line;
29  output += '\n';
30  }
31  }
32 
34  std::string result = from;
35  if (!result.empty()) {
36  // get rid of leading quotes
37  if (result[0] == '"' || result[0] == '\'') {
38  result.erase(0, 1);
39  }
40  }
41 
42  if (!result.empty()) {
43  // and trailing quotes
44  int lastpos = result.size() - 1;
45  if (result[lastpos] == '"' || result[lastpos] == '\'') {
46  result.erase(lastpos, 1);
47  }
48  }
49  return result;
50  }
51 
52  std::vector<std::string> tokenize(const std::string& input, const std::string& separator) {
53  typedef boost::char_separator<char> separator_t;
54  typedef boost::tokenizer<separator_t> tokenizer_t;
55 
56  std::vector<std::string> result;
57  separator_t sep(separator.c_str(), "", boost::keep_empty_tokens); // separator for elements in path
58  tokenizer_t tokens(input, sep);
59  copy_all(tokens, std::back_inserter<std::vector<std::string> >(result));
60  return result;
61  }
62 
63 } // namespace edm
std::string read_whole_file(std::string const &filename)
only does the yacc interpretation
Definition: Parse.cc:10
static std::string const input
Definition: EdmProvDump.cc:50
std::vector< std::string > tokenize(std::string const &input, std::string const &separator)
breaks the input string into tokens, delimited by the separator
Definition: Parse.cc:52
HLT enums.
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:20
static std::string const separator(":")
Definition: output.py:1
void read_from_cin(std::string &output)
Definition: Parse.cc:25
std::string withoutQuotes(std::string const &from)
Definition: Parse.cc:33