CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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")
15  << "Cannot read file " << filename;
16  }
17  std::string buffer;
18  while (getline(input, buffer)) {
19  // getline strips newlines; we have to put them back by hand.
20  result += buffer;
21  result += '\n';
22  }
23  return result;
24  }
25 
26 
29  while (getline(std::cin, line)) {
30  output += line;
31  output += '\n';
32  }
33  }
34 
35 
37  std::string result = from;
38  if(!result.empty()) {
39  // get rid of leading quotes
40  if(result[0] == '"' || result[0] == '\'') {
41  result.erase(0,1);
42  }
43  }
44 
45  if(!result.empty()) {
46  // and trailing quotes
47  int lastpos = result.size()-1;
48  if(result[lastpos] == '"' || result[lastpos] == '\'') {
49  result.erase(lastpos, 1);
50  }
51  }
52  return result;
53  }
54 
55 
56  std::vector<std::string>
58  typedef boost::char_separator<char> separator_t;
59  typedef boost::tokenizer<separator_t> tokenizer_t;
60 
61  std::vector<std::string> result;
62  separator_t sep(separator.c_str(), "", boost::keep_empty_tokens); // separator for elements in path
63  tokenizer_t tokens(input, sep);
64  copy_all(tokens, std::back_inserter<std::vector<std::string> >(result));
65  return result;
66  }
67 
68 } // namespace edm
69 
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:44
tuple result
Definition: mps_fire.py:84
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:57
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
tuple filename
Definition: lut2db_cfg.py:20
static std::string const separator(":")
void read_from_cin(std::string &output)
Definition: Parse.cc:27
std::string withoutQuotes(std::string const &from)
Definition: Parse.cc:36