+ {
+ if(with_functions && ptr[start+length]=='(')
+ {
+ string::size_type lparen = i->second.find('(');
+ string::size_type rparen = i->second.rfind(')');
+ if(lparen!=string::npos && rparen!=string::npos)
+ {
+ unsigned level = 1;
+ unsigned j;
+ for(j=start+length+1; (ptr[j] && level); ++j)
+ {
+ level += (ptr[j]=='(');
+ level -= (ptr[j]==')');
+ }
+
+ if(!level)
+ {
+ string subexpr(ptr+start+length, ptr+j);
+ result += i->second.substr(0, lparen);
+ result += replace_identifiers(subexpr.c_str(), replace_map, with_functions);
+ result += i->second.substr(rparen+1);
+ ptr += j;
+ continue;
+ }
+ }
+ }
+