Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <regex>
- #include <fstream>
- #include <set>
- #include "FileFounder.h"
- FileFounder::FileFounder() {
- _regex = FileFounder::DEFAULT_REGEX;
- }
- FileFounder::FileFounder(const std::string& custom_regex)
- {
- _regex = custom_regex;
- }
- FileFounder::FileFounder(const FileFounder& orig) {
- }
- FileFounder::~FileFounder() {
- }
- std::string FileFounder::NameFile(const std::string& filename)
- {
- std::set<std::string> uniques;
- std::ifstream file(filename);
- std::string str;
- regex re(_regex);
- smatch match;
- while(std::getline(file, str))
- {
- if (std::regex_search(str, match, re))
- {
- std::string CFile = "";
- if (match.size() > 1)
- {
- for (auto i = 1; i < match.size()-2; i++)
- {
- CFile += static_cast<std::string>(match[i]);
- }
- }
- else
- {
- CFile = static_cast<std::string>(match[0]);
- }
- uniques.insert(CFile);
- }
- }
- std::string result = "";
- for (std::set<std::string>::iterator i=uniques.begin(); i!=uniques.end(); ++i)
- {
- result = result + *i + '\n';
- }
- result = result.substr(0,result.length()-1);
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement