Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <regex>
  2. #include <fstream>
  3. #include <set>
  4. #include "FileFounder.h"
  5. FileFounder::FileFounder() {
  6. _regex = FileFounder::DEFAULT_REGEX;
  7. }
  8. FileFounder::FileFounder(const std::string& custom_regex)
  9. {
  10. _regex = custom_regex;
  11. }
  12. FileFounder::FileFounder(const FileFounder& orig) {
  13. }
  14.  
  15. FileFounder::~FileFounder() {
  16. }
  17. std::string FileFounder::NameFile(const std::string& filename)
  18. {
  19. std::set<std::string> uniques;
  20. std::ifstream file(filename);
  21. std::string str;
  22. regex re(_regex);
  23. smatch match;
  24.  
  25. while(std::getline(file, str))
  26. {
  27. if (std::regex_search(str, match, re))
  28. {
  29. std::string CFile = "";
  30. if (match.size() > 1)
  31. {
  32. for (auto i = 1; i < match.size()-2; i++)
  33. {
  34. CFile += static_cast<std::string>(match[i]);
  35. }
  36. }
  37. else
  38. {
  39. CFile = static_cast<std::string>(match[0]);
  40. }
  41. uniques.insert(CFile);
  42. }
  43. }
  44. std::string result = "";
  45. for (std::set<std::string>::iterator i=uniques.begin(); i!=uniques.end(); ++i)
  46. {
  47. result = result + *i + '\n';
  48. }
  49. result = result.substr(0,result.length()-1);
  50. return result;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement