本文整理汇总了C++中boost::regex::str方法的典型用法代码示例。如果您正苦于以下问题:C++ regex::str方法的具体用法?C++ regex::str怎么用?C++ regex::str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::regex
的用法示例。
在下文中一共展示了regex::str方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stringToList
/**
* Generic tokenizer.
* Splits source into tokens and tries to lexically cast them to TARGET.
* If that fails, boost::bad_lexical_cast is thrown.
* \param source the source string to be split up
* \param separator regular expression to delimit the tokens (defaults to \\s+)
* \param prefix regular expression for text to be removed from the string before it is split up
* ("^" if not given, will be added at the beginning)
* \param postfix regular expression for text to be removed from the string before it is split up
* ("$" if not given, will be added at the end)
* \returns a list of the casted tokens
*/
template<typename TARGET> std::list<TARGET> stringToList(
std::string source, const boost::regex &separator,
boost::regex prefix, boost::regex postfix )
{
std::list<TARGET> ret;
assert( ! separator.empty() );
if ( ! prefix.empty() ) {
if ( prefix.str()[0] != '^' )
prefix = boost::regex( std::string( "^" ) + prefix.str(), prefix.flags() );
source = boost::regex_replace( source, prefix, "", boost::format_first_only | boost::match_default );
}
if ( ! postfix.empty() ) {
if ( postfix.str()[postfix.size() - 1] != '$' )
postfix = boost::regex( postfix.str() + "$", postfix.flags() );
source = boost::regex_replace( source, postfix, "", boost::format_first_only | boost::match_default );
}
boost::sregex_token_iterator i = boost::make_regex_token_iterator( source, separator, -1 );
const boost::sregex_token_iterator token_end;
while ( i != token_end ) {
ret.push_back( boost::lexical_cast<TARGET>( ( i++ )->str() ) );
}
return ret;
}
示例2: match
int ChessEngineGnu::match(const string &str,
boost::regex &re,
vector<string> &matches)
{
boost::cmatch what;
matches.clear();
GC_TRACE("match(): %s\n", re.str().c_str());
if( boost::regex_match(str.c_str(), what, re) )
{
// what[0] is the whole string
for(size_t i=1; i<what.size(); ++i)
{
GC_TRACE(" \"%s\"\n", what[i].str().c_str());
matches.push_back(what[i].str());
}
}
GC_TRACE(" %zu matches\n", matches.size());
return (int)matches.size();
}
示例3: expr
TestCaseReader::TestCaseReader(const boost::filesystem::path & testCaseDir)
{
const boost::regex expr("(\\d{3,4})-(.*)\\.xml");
for (boost::filesystem::directory_iterator it = boost::filesystem::directory_iterator(testCaseDir);
it != boost::filesystem::directory_iterator(); ++it)
{
const boost::filesystem::path path = it->path();
//ignore files that don't end in ".xml"
if (path.extension() != ".xml")
{
continue;
}
#if defined (BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION == 3
const std::string filename = path.filename().string();
#else
const std::string filename = path.filename();
#endif
boost::smatch matchResults;
if (boost::regex_match(filename,matchResults,expr))
{
//std::wcout << "Found testcase " << matchResults[1].str().c_str() << " brief description '" << matchResults[2].str().c_str()<< "'" << std::endl;
const size_t tc = boost::lexical_cast<size_t>(matchResults[1]);
if (m_testCases.size() < (tc + 1))
{
m_testCases.resize(tc + 1);
}
if (m_testCases[tc] != NULL)
{
std::wcerr << "There appears to be two test cases with number " << tc << std::endl;
exit(1);
}
std::ostringstream xml;
xml << boost::filesystem::ifstream(path).rdbuf();
//std::wcout << "Read xml (" << xml.str().size() << " bytes) '" << xml.str().c_str() << "'" << std::endl;
try
{
m_testCases[tc] = boost::dynamic_pointer_cast<DoseTest::Items::TestCase>
(Safir::Dob::Typesystem::Serialization::ToObject(Safir::Dob::Typesystem::Utilities::ToWstring(xml.str())));
}
catch (const std::exception & exc)
{
std::wcerr << "Failed to read file '" << path.string().c_str() << "' due to exception with message" << std::endl
<<exc.what() << std::endl;
exit(2);
}
}
else
{
std::wcerr << "File '"
<< path.filename().c_str()
<< "' did not match the pattern for test case files: '"
<< expr.str().c_str()
<< "'" << std::endl;
}
}
}
示例4: write
void write( const string& sourceFilepath,
pwiz::identdata::IdentDataFile::Format outputFormat,
const string& filenameSuffix,
const string& searchEngineName,
const string& searchEngineVersion,
const string& searchEngineURI,
const string& searchDatabase,
boost::regex cleavageAgentRegex,
const string& decoyPrefix,
const RunTimeVariableMap& vars ) const
{
using namespace pwiz::identdata;
namespace msdata = pwiz::msdata;
namespace proteome = pwiz::proteome;
IdentData mzid;
mzid.id = sourceFilepath + " " + searchDatabase + " " + searchEngineName + " " + searchEngineVersion;
mzid.creationDate = GetDateTime();
// add default CVs
mzid.cvs = defaultCVList();
// add the SpectrumIdentificationProtocol
SpectrumIdentificationProtocolPtr sipPtr(new SpectrumIdentificationProtocol("SIP"));
mzid.analysisProtocolCollection.spectrumIdentificationProtocol.push_back(sipPtr);
CVTranslator cvTranslator;
CVID searchEngineCVID = cvTranslator.translate(searchEngineName);
// add analysis software
sipPtr->analysisSoftwarePtr.reset(new AnalysisSoftware("AS"));
mzid.analysisSoftwareList.push_back(sipPtr->analysisSoftwarePtr);
// set software name
if (searchEngineCVID != CVID_Unknown)
sipPtr->analysisSoftwarePtr->softwareName.set(searchEngineCVID);
else
sipPtr->analysisSoftwarePtr->softwareName.set(MS_custom_unreleased_software_tool, searchEngineName);
// set version and URI
sipPtr->analysisSoftwarePtr->version = searchEngineVersion;
sipPtr->analysisSoftwarePtr->URI = searchEngineURI;
// set search type
sipPtr->searchType.cvid = MS_ms_ms_search;
// add a mass table for all MS levels
MassTablePtr massTable(new MassTable("MT"));
massTable->msLevel.push_back(1);
massTable->msLevel.push_back(2);
massTable->msLevel.push_back(3);
sipPtr->massTable.push_back(massTable);
// specify amino acid masses used
const char* residueSymbols = "ACDEFGHIKLMNPQRSTUVWY";
for (int i=0; i < 21; ++i)
{
const AminoAcid::Info::Record& record = AminoAcid::Info::record(residueSymbols[i]);
ResiduePtr rp(new Residue);
rp->code = record.symbol;
rp->mass = record.residueFormula.monoisotopicMass();
massTable->residues.push_back(rp);
}
// add the SpectrumIdentificationList
SpectrumIdentificationListPtr silPtr(new SpectrumIdentificationList("SIL"));
mzid.dataCollection.analysisData.spectrumIdentificationList.push_back(silPtr);
if (vars.count("SearchStats: Overall"))
{
string searchStats = vars.find("SearchStats: Overall")->second;
silPtr->numSequencesSearched = lexical_cast<int>(searchStats.substr(0, searchStats.find_first_of(' ')));
}
// add the SpectrumIdentification
SpectrumIdentificationPtr siPtr(new SpectrumIdentification("SI"));
siPtr->spectrumIdentificationListPtr = silPtr;
siPtr->spectrumIdentificationProtocolPtr = sipPtr;
siPtr->activityDate = mzid.creationDate;
mzid.analysisCollection.spectrumIdentification.push_back(siPtr);
// add search database
SearchDatabasePtr sdb(new SearchDatabase("SDB"));
sdb->fileFormat.cvid = MS_FASTA_format;
sdb->location = searchDatabase;
sdb->name = bfs::path(searchDatabase).filename();
sdb->set(MS_database_type_amino_acid);
sdb->databaseName.userParams.push_back(UserParam("database name", sdb->name, "xsd:string"));
mzid.dataCollection.inputs.searchDatabase.push_back(sdb);
mzid.analysisCollection.spectrumIdentification[0]->searchDatabase.push_back(sdb);
// add source file
SpectraDataPtr spectraData(new SpectraData("SD"));
spectraData->location = sourceFilepath;
spectraData->name = bfs::path(spectraData->location).filename();
mzid.dataCollection.inputs.spectraData.push_back(spectraData);
mzid.analysisCollection.spectrumIdentification[0]->inputSpectra.push_back(spectraData);
// set source file format (required for a semantically valid mzIdentML file)
//.........这里部分代码省略.........