CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
expressionFormatHelpers.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : expressionFormatHelpers
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Fri Aug 22 12:25:04 EDT 2008
11 // $Id: expressionFormatHelpers.cc,v 1.5 2009/03/23 19:52:17 amraktad Exp $
12 //
13 
14 // system include files
15 #include <boost/regex.hpp>
16 
17 // user include files
19 
20 
21 //
22 // constants, enums and typedefs
23 //
24 
25 namespace fireworks {
26  namespace expression {
27  std::string oldToNewFormat(const std::string& iExpression) {
28  //Backwards compatibility with old format: If find a $. or a () just remove them
29  const std::string variable;
30  static boost::regex const reVarName("(\\$\\.)|(\\(\\))");
31 
32  return boost::regex_replace(iExpression,reVarName,variable);
33  }
34 
35  long indexFromNewFormatToOldFormat(const std::string& iNewFormat,
36  long iNewFormatIndex,
37  const std::string& iOldFormat)
38  {
39  if(iNewFormat.substr(0,iNewFormatIndex) ==
40  iOldFormat.substr(0,iNewFormatIndex)) {
41  return iNewFormatIndex;
42  }
43  assert(iNewFormat.size()< iOldFormat.size());
44  std::string::const_iterator itNew = iNewFormat.begin(), itOld = iOldFormat.begin(),
45  itNewEnd = iNewFormat.end();
46  for(;
47  itNew != itNewEnd && itNew-iNewFormat.begin() < iNewFormatIndex;
48  ++itNew, ++itOld) {
49  while(*itNew != *itOld) {
50  assert(itOld != iOldFormat.end());
51  ++itOld;
52  }
53  }
54  return itOld - iOldFormat.begin();
55  }
56  }
57 }
long indexFromNewFormatToOldFormat(const std::string &iNewFormat, long iNewFormatIndex, const std::string &iOldFormat)
std::string oldToNewFormat(const std::string &iExpression)