diff --git a/kspread/valuecalc.cpp b/kspread/valuecalc.cpp index 3a1182e54..2f6b4b8dd 100644 --- a/kspread/valuecalc.cpp +++ b/kspread/valuecalc.cpp @@ -433,9 +433,70 @@ bool ValueCalc::approxEqual (const Value &a, const Value &b) return (x < 0.0 ? -x : x) < ((aa < 0.0 ? -aa : aa) * DBL_EPSILON); } -bool ValueCalc::strEqual (const Value &a, const Value &b) +bool ValueCalc::strEqual (const Value &a, const Value &b, bool CS) { - return (converter->asString (a).asString() == converter->asString (b).asString()); + TQString aa = converter->asString(a).asString(); + TQString bb = converter->asString(b).asString(); + if (!CS) { + aa = aa.lower(); + bb = bb.lower(); + } + return (aa == bb); +} + +bool ValueCalc::strGreater (const Value &a, const Value &b, bool CS) +{ + TQString aa = converter->asString(a).asString(); + TQString bb = converter->asString(b).asString(); + if (!CS) { + aa = aa.lower(); + bb = bb.lower(); + } + return (aa > bb); +} + +bool ValueCalc::strGequal (const Value &a, const Value &b, bool CS) +{ + TQString aa = converter->asString(a).asString(); + TQString bb = converter->asString(b).asString(); + if (!CS) { + aa = aa.lower(); + bb = bb.lower(); + } + return (aa >= bb); +} + +bool ValueCalc::strLower (const Value &a, const Value &b, bool CS) +{ + return strGreater (b, a, CS); +} + +bool ValueCalc::naturalEqual (const Value &a, const Value &b, bool CS) +{ + if (a.isNumber() && b.isNumber()) + return approxEqual(a, b); + if (a.allowComparison(b)) + return a.equal(b); + return strEqual(a, b, CS); +} + +bool ValueCalc::naturalGreater (const Value &a, const Value &b, bool CS) +{ + if (a.isNumber() && b.isNumber()) + return greater(a, b); + if (a.allowComparison(b)) + return a.greater(b); + return strGreater(a, b, CS); +} + +bool ValueCalc::naturalGequal (const Value &a, const Value &b, bool CS) +{ + return naturalGreater(a, b, CS) || naturalEqual(a, b, CS); +} + +bool ValueCalc::naturalLower (const Value &a, const Value &b, bool CS) +{ + return naturalGreater(b, a, CS); } bool ValueCalc::greater (const Value &a, const Value &b) diff --git a/kspread/valuecalc.h b/kspread/valuecalc.h index 2d78211b2..5157fa4c6 100644 --- a/kspread/valuecalc.h +++ b/kspread/valuecalc.h @@ -106,7 +106,22 @@ class ValueCalc { /** numerical comparison */ bool lower (const Value &a, const Value &b); /** string comparison */ - bool strEqual (const Value &a, const Value &b); + bool strEqual (const Value &a, const Value &b, bool CS = true); + /** string comparison */ + bool strGreater (const Value &a, const Value &b, bool CS = true); + /** string comparison - greater or equal */ + bool strGequal (const Value &a, const Value &b, bool CS = true); + /** string comparison */ + bool strLower (const Value &a, const Value &b, bool CS = true); + /** string or numerical comparison */ + bool naturalEqual (const Value &a, const Value &b, bool CS = true); + /** string or numerical comparison */ + bool naturalGreater (const Value &a, const Value &b, bool CS = true); + /** string or numerical comparison - greater or equal */ + bool naturalGequal (const Value &a, const Value &b, bool CS = true); + /** string or numerical comparison */ + bool naturalLower (const Value &a, const Value &b, bool CS = true); + int sign (const Value &a); /** rounding */