Compare View

switch
from
...
to
 
Commits (3)
include/cbutils.h
... ... @@ -26,8 +26,15 @@
26 26 #include <cassert>
27 27 #include <chrono>
28 28 #include <iomanip>
29   -#include <experimental/filesystem>
30 29 #include <regex>
  30 +
  31 +#if __GNUC__ == 8
  32 +#if __GNUC_MINOR__ == 2
  33 +#include <filesystem>
  34 +#else
  35 +#include <experimental/filesystem>
  36 +#endif
  37 +#endif
31 38 namespace cbutils
32 39 {
33 40 // ----------------- String manipulation ---------------------------------------
... ... @@ -68,19 +75,19 @@ bool contains(std::string s, std::vector&lt;std::string&gt; patterns)
68 75 }
69 76 } //end ns string
70 77 // ----------------- System calls ----------------------------------------------
71   -namespace system{
  78 + namespace system{
72 79 // Runs the command sending it to the OS and returns a string wit its output
73   -std::string call(const std::string& command)
74   -{
75   - std::string tmp_filename{std::tmpnam(nullptr)};
76   - std::stringstream command_redirect{command+" > "+tmp_filename};
77   - std::system(command_redirect.str().c_str());
78   - std::stringstream command_output;
79   - command_output << std::ifstream(tmp_filename).rdbuf();
80   - std::remove(tmp_filename.c_str());
81   - return command_output.str();
82   -}
83   -} //end ns system
  80 + std::string call(const std::string& command)
  81 + {
  82 + std::string tmp_filename{std::tmpnam(nullptr)};
  83 + std::stringstream command_redirect{command+" > "+tmp_filename};
  84 + std::system(command_redirect.str().c_str());
  85 + std::stringstream command_output;
  86 + command_output << std::ifstream(tmp_filename).rdbuf();
  87 + std::remove(tmp_filename.c_str());
  88 + return command_output.str();
  89 + }
  90 + } //end ns system
84 91 // ----------------- File IO ---------------------------------------------------
85 92 namespace file
86 93 {
... ... @@ -130,7 +137,9 @@ std::vector&lt;std::string&gt; list_files(const std::string&amp; dir,
130 137 fname << p;
131 138 if(std::regex_search(fname.str(), regex_pattern))
132 139 {
133   - result.emplace_back(fname.str());
  140 + auto clean_fname = fname.str();
  141 + boost::algorithm::erase_all(clean_fname, "\"");
  142 + result.emplace_back(clean_fname);
134 143 }
135 144 }
136 145  
... ... @@ -206,5 +215,13 @@ std::string now_str()
206 215 return result.str();
207 216 }
208 217 }// end ns misc
  218 +namespace operators{
  219 +// Print the contents of a vector of printable things
  220 +template<typename T>
  221 +std::ostream& operator <<(std::ostream& stream, const std::vector<T> vec){
  222 + for(const auto& t : vec) stream << t << " ";
  223 + return stream;
  224 +}
  225 +} // end ns operators
209 226 }//end ns cbutils
210 227 #endif
... ...