Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:54

0001 #include "FWCore/Utilities/interface/Parse.h"
0002 #include "FWCore/Utilities/interface/EDMException.h"
0003 #include "FWCore/Utilities/interface/Algorithms.h"
0004 #include <boost/tokenizer.hpp>
0005 #include <fstream>
0006 #include <iostream>
0007 
0008 namespace edm {
0009 
0010   std::string read_whole_file(std::string const& filename) {
0011     std::string result;
0012     std::ifstream input(filename.c_str());
0013     if (!input) {
0014       throw edm::Exception(errors::Configuration, "MissingFile") << "Cannot read file " << filename;
0015     }
0016     std::string buffer;
0017     while (getline(input, buffer)) {
0018       // getline strips newlines; we have to put them back by hand.
0019       result += buffer;
0020       result += '\n';
0021     }
0022     return result;
0023   }
0024 
0025   void read_from_cin(std::string& output) {
0026     std::string line;
0027     while (getline(std::cin, line)) {
0028       output += line;
0029       output += '\n';
0030     }
0031   }
0032 
0033   std::string withoutQuotes(const std::string& from) {
0034     std::string result = from;
0035     if (!result.empty()) {
0036       // get rid of leading quotes
0037       if (result[0] == '"' || result[0] == '\'') {
0038         result.erase(0, 1);
0039       }
0040     }
0041 
0042     if (!result.empty()) {
0043       // and trailing quotes
0044       int lastpos = result.size() - 1;
0045       if (result[lastpos] == '"' || result[lastpos] == '\'') {
0046         result.erase(lastpos, 1);
0047       }
0048     }
0049     return result;
0050   }
0051 
0052   std::vector<std::string> tokenize(const std::string& input, const std::string& separator) {
0053     typedef boost::char_separator<char> separator_t;
0054     typedef boost::tokenizer<separator_t> tokenizer_t;
0055 
0056     std::vector<std::string> result;
0057     separator_t sep(separator.c_str(), "", boost::keep_empty_tokens);  // separator for elements in path
0058     tokenizer_t tokens(input, sep);
0059     copy_all(tokens, std::back_inserter<std::vector<std::string> >(result));
0060     return result;
0061   }
0062 
0063 }  // namespace edm