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
edm::copy_all
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:20
input
static const std::string input
Definition: EdmProvDump.cc:48
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
edm
HLT enums.
Definition: AlignableModifier.h:19
Algorithms.h
edm::tokenize
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
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
EDMException.h
Parse.h
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::withoutQuotes
std::string withoutQuotes(std::string const &from)
Definition: Parse.cc:33
edm::read_from_cin
void read_from_cin(std::string &output)
Definition: Parse.cc:25
edm::separator
static const std::string separator(":")
Exception
Definition: hltDiff.cc:246
mps_fire.result
result
Definition: mps_fire.py:303
mps_splice.line
line
Definition: mps_splice.py:76
edm::errors::Configuration
Definition: EDMException.h:36
edm::read_whole_file
std::string read_whole_file(std::string const &filename)
only does the yacc interpretation
Definition: Parse.cc:10