CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/Fireworks/Core/src/expressionFormatHelpers.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     expressionFormatHelpers
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Fri Aug 22 12:25:04 EDT 2008
00011 // $Id: expressionFormatHelpers.cc,v 1.5 2009/03/23 19:52:17 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include <boost/regex.hpp>
00016 
00017 // user include files
00018 #include "Fireworks/Core/src/expressionFormatHelpers.h"
00019 
00020 
00021 //
00022 // constants, enums and typedefs
00023 //
00024 
00025 namespace fireworks {
00026    namespace expression {
00027       std::string oldToNewFormat(const std::string& iExpression) {
00028          //Backwards compatibility with old format: If find a $. or a () just remove them
00029          const std::string variable;
00030          static boost::regex const reVarName("(\\$\\.)|(\\(\\))");
00031 
00032          return boost::regex_replace(iExpression,reVarName,variable);
00033       }
00034 
00035       long indexFromNewFormatToOldFormat(const std::string& iNewFormat,
00036                                          long iNewFormatIndex,
00037                                          const std::string& iOldFormat)
00038       {
00039          if(iNewFormat.substr(0,iNewFormatIndex) ==
00040             iOldFormat.substr(0,iNewFormatIndex)) {
00041             return iNewFormatIndex;
00042          }
00043          assert(iNewFormat.size()< iOldFormat.size());
00044          std::string::const_iterator itNew = iNewFormat.begin(), itOld = iOldFormat.begin(),
00045                                      itNewEnd = iNewFormat.end();
00046          for(;
00047              itNew != itNewEnd && itNew-iNewFormat.begin() < iNewFormatIndex;
00048              ++itNew, ++itOld) {
00049             while(*itNew != *itOld) {
00050                assert(itOld != iOldFormat.end());
00051                ++itOld;
00052             }
00053          }
00054          return itOld - iOldFormat.begin();
00055       }
00056    }
00057 }