~qalculate/libqalculate/trunk

« back to all changes in this revision

Viewing changes to libqalculate/Calculator-parse.cc

  • Committer: Hanna K
  • Date: 2020-06-23 14:57:12 UTC
  • Revision ID: git-v1:75d3b5c0c1ac2f9d0eeac8b09a985b5713082537
Fix plus-minus sign in misplaced character/operators error messages

Show diffs side-by-side

added added

removed removed

Lines of Context:
530
530
 
531
531
}
532
532
 
 
533
void replace_internal_operators(string &str) {
 
534
        gsub("\a", " xor ", str);
 
535
        gsub("\b", SIGN_PLUSMINUS, str);
 
536
        gsub("\x1c", "∠", str);
 
537
        remove_blank_ends(str);
 
538
}
 
539
 
533
540
void Calculator::parse(MathStructure *mstruct, string str, const ParseOptions &parseoptions) {
534
541
 
535
542
        ParseOptions po = parseoptions;
1774
1781
 
1775
1782
        // check that string contains characters other than operators and whitespace
1776
1783
        if(str.find_first_not_of(OPERATORS "\a%\x1c" SPACE) == string::npos && (po.base != BASE_ROMAN_NUMERALS || str.find("|") == string::npos)) {
1777
 
                gsub("\a", str.find_first_of("%" OPERATORS) != string::npos ? " xor " : "xor", str);
1778
 
                gsub("\x1c", "∠", str);
 
1784
                replace_internal_operators(str);
1779
1785
                error(false, _("Misplaced operator(s) \"%s\" ignored"), str.c_str(), NULL);
1780
1786
                return false;
1781
1787
        }
3033
3039
                while(i != string::npos && i + 1 != str.length()) {
3034
3040
                        if(i < 1) {
3035
3041
                                if(i < 1 && str.find_first_not_of(MULTIPLICATION_2 OPERATORS INTERNAL_OPERATORS EXPS) == string::npos) {
3036
 
                                        gsub("\a", str.find_first_of(OPERATORS "%") != string::npos ? " xor " : "xor", str);
 
3042
                                        replace_internal_operators(str);
3037
3043
                                        error(false, _("Misplaced operator(s) \"%s\" ignored"), str.c_str(), NULL);
3038
3044
                                        return b;
3039
3045
                                }
3199
3205
 
3200
3206
        // Check if only operators are left
3201
3207
        if(str.find_first_not_of(OPERATORS INTERNAL_OPERATORS SPACE) == string::npos && (po.base != BASE_ROMAN_NUMERALS || str.find_first_of("(|)") == string::npos)) {
3202
 
                gsub("\a", str.find_first_of(OPERATORS "%") != string::npos ? " xor " : "xor", str);
3203
 
                gsub("\x1c", "∠", str);
 
3208
                replace_internal_operators(str);
3204
3209
                error(false, _("Misplaced operator(s) \"%s\" ignored"), str.c_str(), NULL);
3205
3210
                return false;
3206
3211
        }
3224
3229
                        break;
3225
3230
                } else if(is_in(OPERATORS INTERNAL_OPERATORS, str[i]) && (po.base != BASE_ROMAN_NUMERALS || (str[i] != '(' && str[i] != ')' && str[i] != '|'))) {
3226
3231
                        if(str[i] == '\a') error(false, _("Misplaced operator(s) \"%s\" ignored"), "xor", NULL);
 
3232
                        else if(str[i] == '\b') error(false, _("Misplaced operator(s) \"%s\" ignored"), SIGN_PLUSMINUS, NULL);
3227
3233
                        else if(str[i] == '\x1c') error(false, _("Misplaced operator(s) \"%s\" ignored"), "∠", NULL);
3228
3234
                        else error(false, _("Misplaced '%c' ignored"), str[i], NULL);
3229
3235
                        str.erase(i, 1);