Exemplo n.º 1
0
StringMatrix Pattern::read(string fileName, int xlen, int ylen)
{
    StringMatrix res;
    string val;

    ifstream file(fileName);

    for (int i = 0; i < ylen; ++i)
    {
        res.push_back(vector<string>());
        for (int j = 0; j < xlen; ++j)
        {
            file >> val;
            res[i].push_back(val);
        }
    }
    file.close();
    return res;
}
MatLabUdmTruthTable::StringVectorManager MatLabUdmTruthTable::getStringVectorManager( std::string matrix ) {

	static boost::regex scPattern( "(?<!&#x[0-9A-Fa-f]{2});", boost::regex_constants::perl );
	static boost::regex scCodePattern( "&#x3[Bb];", boost::regex_constants::perl );
	static boost::regex cmPattern( ",", boost::regex_constants::perl );
	static boost::regex cmCodePattern( "&#x2[Cc];", boost::regex_constants::perl );
	static boost::regex labeledStringPattern( "\\s*(\\S+)\\s*:\\s*(.*?)\\s*\\Z", boost::regex_constants::perl | boost::regex_constants::mod_s);

	matrix = matrix.substr( 1, matrix.size() - 2 ); // GET RID OF ENCLOSING {}

	StringMatrix stringMatrix;

	bool scMatch = true;
	boost::match_results< std::string::const_iterator > results;
	while (   scMatch && (  boost::regex_search( matrix, results, scPattern ) || !(scMatch = false)  )   ) {

		std::string row;
		if ( scMatch ) {
			row = results.prefix();
			matrix = results.suffix();
		} else {
			row = matrix;
		}

		row = boost::regex_replace( row, scCodePattern, ";" );

		stringMatrix.push_back(  StringVectorSP( new StringVector )  );
		StringVector &stringVector = *stringMatrix.back();

		bool cmMatch = true;
		while(   cmMatch && (  boost::regex_search( row, results, cmPattern ) || !( cmMatch = false )  )   ) {
			std::string cell;
			if ( cmMatch ) {
				cell = results.prefix();
				row = results.suffix();
			} else {
				cell = row;
			}

			cell = boost::regex_replace( cell, cmCodePattern, "," );
			stringVector.push_back( cell );
		}
	}

	StringVectorMap stringVectorMap;
	for( StringMatrix::iterator stmItr = stringMatrix.begin() ; stmItr != stringMatrix.end() ; ++stmItr ) {
		StringVector &stringVector = **stmItr;

		std::string &labeledString = stringVector[1];
		labeledString = RegexCommon::eliminateContinuations( labeledString );

		if (  boost::regex_search( labeledString, results, labeledStringPattern )  ) {
			std::string key( results[1] );
			std::string condition( results[2] );

			stringVectorMap.insert(  std::make_pair( key, *stmItr )  );
			labeledString = condition;
		}

	}

	return StringVectorManager( stringMatrix, stringVectorMap );
}