bool search::index_files(const std::string &filter) { std::ifstream pbo_stream; std::regex txt_regex(filter); if (_active_pbo_list.size() < 1) return false; for (auto & pbo_file_path : _active_pbo_list) { pbo_stream.open(pbo_file_path, std::ios::binary | std::ios::in); if (!pbo_stream.good()) { LOG(ERROR) << "Cannot open file - " << pbo_file_path; continue; } ace::pbo::archive _archive(pbo_stream); for (ace::pbo::entry_p & entry : _archive.entries) { if (entry->filename != "") { if (std::regex_match(entry->filename, txt_regex)) { std::string full_virtual_path = _archive.info->data + "\\" + entry->filename; std::transform(full_virtual_path.begin(), full_virtual_path.end(), full_virtual_path.begin(), ::tolower); _file_pbo_index[full_virtual_path] = pbo_file_path; //LOG(DEBUG) << full_virtual_path << " = " << pbo_file_path; } } } pbo_stream.close(); } LOG(INFO) << "PBO Index complete"; return true; }
int main() { // Simple regular expression matching std::string fnames[] = {"foo.txt", "bar.txt", "baz.dat", "zoidberg"}; std::regex txt_regex("[a-z]+\\.txt"); for (const auto &fname : fnames) { std::cout << fname << ": " << std::regex_match(fname, txt_regex) << '\n'; } // Extraction of a sub-match std::regex base_regex("([a-z]+)\\.txt"); std::smatch base_match; for (const auto &fname : fnames) { if (std::regex_match(fname, base_match, base_regex)) { // The first sub_match is the whole string; the next // sub_match is the first parenthesized expression. if (base_match.size() == 2) { std::ssub_match base_sub_match = base_match[1]; std::string base = base_sub_match.str(); std::cout << fname << " has a base of " << base << '\n'; } } } // Extraction of several sub-matches std::regex pieces_regex("([a-z]+)\\.([a-z]+)"); std::smatch pieces_match; for (const auto &fname : fnames) { if (std::regex_match(fname, pieces_match, pieces_regex)) { std::cout << fname << '\n'; for (size_t i = 0; i < pieces_match.size(); ++i) { std::ssub_match sub_match = pieces_match[i]; std::string piece = sub_match.str(); std::cout << " submatch " << i << ": " << piece << '\n'; } } } }