Logo Search packages:      
Sourcecode: libqalculate version File versions  Download package

string Calculator::unlocalizeExpression ( string  str,
const ParseOptions po = default_parse_options 
) const

Returns an unlocalized expressions. Affects decimal signs and argument separators.

Parameters:
str The expression to unlocalize.
Returns:
An unlocalized expression.

Definition at line 1633 of file Calculator.cc.

References ParseOptions::dot_as_separator.

                                                                                {
      if(DOT_STR == DOT && COMMA_STR == COMMA) return str;
      vector<size_t> q_begin;
      vector<size_t> q_end;
      size_t i3 = 0;
      while(true) {
            i3 = str.find_first_of("\"\'", i3);
            if(i3 == string::npos) {
                  break;
            }
            q_begin.push_back(i3);
            i3 = str.find(str[i3], i3 + 1);
            if(i3 == string::npos) {
                  q_end.push_back(str.length() - 1);
                  break;
            }
            q_end.push_back(i3);
            i3++;
      }
      if(DOT_STR != DOT) {
            if(po.dot_as_separator) {
                  size_t ui = str.find(DOT);
                  while(ui != string::npos) {
                        bool b = false;
                        for(size_t ui2 = 0; ui2 < q_end.size(); ui2++) {
                              if(ui <= q_end[ui2] && ui >= q_begin[ui2]) {
                                    ui = str.find(DOT, q_end[ui2] + 1);
                                    b = true;
                                    break;
                              }
                        }
                        if(!b) {
                              str.replace(ui, strlen(DOT), SPACE);
                              ui = str.find(DOT, ui + strlen(SPACE));
                        }
                  }
            }
            size_t ui = str.find(DOT_STR);
            while(ui != string::npos) {
                  bool b = false;
                  for(size_t ui2 = 0; ui2 < q_end.size(); ui2++) {
                        if(ui <= q_end[ui2] && ui >= q_begin[ui2]) {
                              ui = str.find(DOT_STR, q_end[ui2] + 1);
                              b = true;
                              break;
                        }
                  }
                  if(!b) {
                        str.replace(ui, DOT_STR.length(), DOT);
                        ui = str.find(DOT_STR, ui + strlen(DOT));
                  }
            }
      }
      if(COMMA_STR != COMMA) {
            size_t ui = str.find(COMMA_STR);
            while(ui != string::npos) {
                  bool b = false;
                  for(size_t ui2 = 0; ui2 < q_end.size(); ui2++) {
                        if(ui <= q_end[ui2] && ui >= q_begin[ui2]) {
                              ui = str.find(COMMA_STR, q_end[ui2] + 1);
                              b = true;
                              break;
                        }
                  }
                  if(!b) {
                        str.replace(ui, COMMA_STR.length(), COMMA);
                        ui = str.find(COMMA_STR, ui + strlen(COMMA));
                  }
            }
      }
      return str;
}


Generated by  Doxygen 1.6.0   Back to index