Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:35

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     expressionFormatHelpers
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Fri Aug 22 12:25:04 EDT 2008
0011 //
0012 
0013 // system include files
0014 #include <boost/regex.hpp>
0015 
0016 // user include files
0017 #include "Fireworks/Core/src/expressionFormatHelpers.h"
0018 
0019 //
0020 // constants, enums and typedefs
0021 //
0022 
0023 namespace fireworks {
0024   namespace expression {
0025     std::string oldToNewFormat(const std::string& iExpression) {
0026       //Backwards compatibility with old format: If find a $. or a () just remove them
0027       const std::string variable;
0028       static boost::regex const reVarName("(\\$\\.)|(\\(\\))");
0029 
0030       return boost::regex_replace(iExpression, reVarName, variable);
0031     }
0032 
0033     long indexFromNewFormatToOldFormat(const std::string& iNewFormat,
0034                                        long iNewFormatIndex,
0035                                        const std::string& iOldFormat) {
0036       if (iNewFormat.substr(0, iNewFormatIndex) == iOldFormat.substr(0, iNewFormatIndex)) {
0037         return iNewFormatIndex;
0038       }
0039       assert(iNewFormat.size() < iOldFormat.size());
0040       std::string::const_iterator itNew = iNewFormat.begin(), itOld = iOldFormat.begin(), itNewEnd = iNewFormat.end();
0041       for (; itNew != itNewEnd && itNew - iNewFormat.begin() < iNewFormatIndex; ++itNew, ++itOld) {
0042         while (*itNew != *itOld) {
0043           assert(itOld != iOldFormat.end());
0044           ++itOld;
0045         }
0046       }
0047       return itOld - iOldFormat.begin();
0048     }
0049   }  // namespace expression
0050 }  // namespace fireworks