Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
// -*- C++ -*-
//
// Package:     Core
// Class  :     expressionFormatHelpers
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Chris Jones
//         Created:  Fri Aug 22 12:25:04 EDT 2008
//

// system include files
#include <boost/regex.hpp>

// user include files
#include "Fireworks/Core/src/expressionFormatHelpers.h"

//
// constants, enums and typedefs
//

namespace fireworks {
  namespace expression {
    std::string oldToNewFormat(const std::string& iExpression) {
      //Backwards compatibility with old format: If find a $. or a () just remove them
      const std::string variable;
      static boost::regex const reVarName("(\\$\\.)|(\\(\\))");

      return boost::regex_replace(iExpression, reVarName, variable);
    }

    long indexFromNewFormatToOldFormat(const std::string& iNewFormat,
                                       long iNewFormatIndex,
                                       const std::string& iOldFormat) {
      if (iNewFormat.substr(0, iNewFormatIndex) == iOldFormat.substr(0, iNewFormatIndex)) {
        return iNewFormatIndex;
      }
      assert(iNewFormat.size() < iOldFormat.size());
      std::string::const_iterator itNew = iNewFormat.begin(), itOld = iOldFormat.begin(), itNewEnd = iNewFormat.end();
      for (; itNew != itNewEnd && itNew - iNewFormat.begin() < iNewFormatIndex; ++itNew, ++itOld) {
        while (*itNew != *itOld) {
          assert(itOld != iOldFormat.end());
          ++itOld;
        }
      }
      return itOld - iOldFormat.begin();
    }
  }  // namespace expression
}  // namespace fireworks