bool grep_callback(const boost::smatch& what) { // 1、先将what[0]中的内容拷贝到 pUtf8[] 中,再转换成 wstring型的输出 // 1.1、计算在文件中的位置 long mLocation=mPageNum*2*4096+what.position(); // 1.2、取出匹配项 //fs.seekg(mLocation,fstream::beg); //fs.read(pUtf8,(what[0]->second - what[0]->first)); // 1.3、转换成 wstring 型 string mUtf8(pUtf8); mUtf8.assign(what[0]); wstring mUnicode=UTF8ToWide(mUtf8); // 试验 //string strUtf8(what[0].first+7,what[0].second-8); //wstring wstrTitle=UTF8ToWide(strUtf8); // 1.4、输出-wstring转换成string strOut=WstrToStr(mUnicode); // 每次匹配,都修改日志文件名 // pFlogfile[6]=mCount; // int nIndex=mCount-'a'; // strcpy(pLogReturn[nIndex],pFlogfile); // mCount++; //outFile.seekp(0,ios::end); if (bFind==false) { outFile.open(logFile,ofstream::out); outFile<<"结果如下:"<<endl; outFile<<"————————————————————————————"<<endl; strcpy(pLogReturn[mIndex],logFile.c_str()); bFind=true; } // 转换一哈,写入结果 int size=strOut.size(); wchar_t *out=new wchar_t[size]; PreShow(strOut.c_str(),out); string show=WstrToStr(out); outFile<<show<<endl; //outFile<<strOut<<endl; outFile<<endl; outFile<<"————————————————————————————"<<endl; outFile<<endl; //outFile.open(pFlogfile,ofstream::out); //outFile<<strOut; //outFile.close(); delete[] out; return TRUE; }
void process_stream(std::istream& is) { std::string line; int match_found = 0; int linenum = 1; while(std::getline(is, line)) { bool result = boost::regex_search(line, what, re); if(result) { if(print_non_matching_files) return; if(files_only) { std::cout << current_file << std::endl; return; } if(!match_found && !count_only && (file_count > 1)) { std::cout << current_file << ":\n"; } ++match_found; if(!count_only) { if(print_line_numbers) { std::cout << linenum << ":"; } if(print_byte_offset) { std::cout << what.position() << ":"; } std::cout << what[0] << std::endl; } } ++linenum; } if(count_only && match_found) { std::cout << match_found << " matches found in file " << current_file << std::endl; } else if(print_non_matching_files && !match_found) { std::cout << current_file << std::endl; } }
bool grep_callback_tianya(const boost::smatch& what) { // 1、先将what[0]中的内容拷贝到 pUtf8[] 中,再转换成 wstring型的输出 // 1.1、计算在文件中的位置 long mLocation=mPageNum*2*4096+what.position(); // 1.2、取出匹配项 //fs.seekg(mLocation,fstream::beg); //fs.read(pUtf8,(what[0]->second - what[0]->first)); // 1.3、转换成 wstring 型 string mUtf8(pUtf8); mUtf8.assign(what[0]); if (bFind==false) { outFile.open(logFile,ofstream::out); outFile<<"结果如下:"<<endl; outFile<<"————————————————————————————"<<endl; strcpy(pLogReturn[mIndex],logFile.c_str()); bFind=true; } // 转换一哈,写入结果 CString strUtf8(mUtf8.c_str()); string show=CCharacterSetCode::UTF_8toString(strUtf8); outFile<<show<<endl; //outFile<<strOut<<endl; outFile<<endl; outFile<<"————————————————————————————"<<endl; outFile<<endl; //outFile.open(pFlogfile,ofstream::out); //outFile<<strOut; //outFile.close(); //delete[] out; return TRUE; }