Commit 7fe0a878 authored by GoshaZotov's avatar GoshaZotov

modify matchingValue/matching functions

parent 527168b2
......@@ -51,9 +51,9 @@
return false;
}
condition = condition.getValue();
//condition = condition.getValue();
if("" === condition){
if("" === condition.value){
res = true;
}else{
var conditionObj = AscCommonExcel.matchingValue(condition);
......
......@@ -4464,7 +4464,7 @@
return this.value = new cError(cErrorType.wrong_value_type);
}
matchingInfo = AscCommonExcel.matchingValue(arg1.toString());
matchingInfo = AscCommonExcel.matchingValue(arg1);
if (cElementType.cellsRange === arg0.type) {
var arg0Matrix = arg0.getMatrix(), arg2Matrix = arg2.getMatrix(), valMatrix2;
for (var i = 0; i < arg0Matrix.length; i++) {
......@@ -4539,7 +4539,7 @@
return this.value = new cError(cErrorType.wrong_value_type);
}
matchingInfo = AscCommonExcel.matchingValue(arg2.toString());
matchingInfo = AscCommonExcel.matchingValue(arg2);
var arg1Matrix = arg1.getMatrix();
if (arg0Matrix.length !== arg1Matrix.length) {
......
......@@ -5778,26 +5778,36 @@ function parseNum( str ) {
var matchingOperators = new RegExp("^ *[<=> ]+ *");
function matchingValue(val) {
var search, op;
var match = val.match(matchingOperators);
if (match) {
search = val.substr(match[0].length);
op = match[0].replace(/\s/g, "");
function matchingValue(oVal) {
var res;
if(cElementType.string === oVal.type){
var search, op;
var val = oVal.getValue();
var match = val.match(matchingOperators);
if (match) {
search = val.substr(match[0].length);
op = match[0].replace(/\s/g, "");
} else {
search = val;
op = null;
}
var parseRes = AscCommon.g_oFormatParser.parse(search);
res = {val: parseRes ? new cNumber(parseRes.value) : new cString(search), op: op};
} else {
search = val;
op = null;
res = {val: oVal, op: null};
}
var parseRes = AscCommon.g_oFormatParser.parse(search);
return {val: parseRes ? new cNumber(parseRes.value) : new cString(search), op: op};
return res;
}
function matching(x, matchingInfo) {
var y = matchingInfo.val;
var operator = matchingInfo.op;
var res = false, rS;
if (cElementType.string === y.type) {
if ('<' === operator || '>' === operator || '<=' === operator || '>=' === operator) {
if (cElementType.number === y.type && ('<' === operator || '>' === operator || '<=' === operator || '>=' === operator)) {
var _funcVal = _func[x.type][y.type](x, y, operator);
if(cElementType.error === _funcVal.type){
return false;
......@@ -5823,7 +5833,7 @@ function parseNum( str ) {
res = rS;
break;
}
} else {
} else if(cElementType.number === y.type) {
rS = (x.type === y.type);
switch (operator) {
case "<>":
......@@ -5843,9 +5853,20 @@ function parseNum( str ) {
break;
case "=":
default:
if(cElementType.string === x.type){
x = x.tocNumber();
}
res = (x.value === y.value);
break;
}
} else if(cElementType.bool === y.type) {
if(y.type === x.type && x.value === y.value){
res = true;
}
} else if(cElementType.error === y.type) {
if(y.type === x.type && x.value === y.value){
res = true;
}
}
return res;
}
......
......@@ -1597,11 +1597,10 @@
return this.value = new cError(cErrorType.wrong_value_type);
}
arg1 = arg1.toString();
var r = arg0.getRange();
var r2 = arg2.getRange();
ws = arg0.getWS();
matchingInfo = AscCommonExcel.matchingValue(arg1.toString());
matchingInfo = AscCommonExcel.matchingValue(arg1);
if (cElementType.cellsRange === arg0.type) {
arg0.foreach2(function (v, cell) {
if (matching(v, matchingInfo)) {
......@@ -1678,7 +1677,7 @@
if (cElementType.string !== arg2.type) {
return this.value = new cError(cErrorType.wrong_value_type);
}
matchingInfo = AscCommonExcel.matchingValue(arg2.toString());
matchingInfo = AscCommonExcel.matchingValue(arg2);
var arg1Matrix = arg1.getMatrix();
if (arg0Matrix.length !== arg1Matrix.length) {
......@@ -2686,31 +2685,20 @@
return this.value = new cError(cErrorType.wrong_value_type);
}*/
var compareValues = function(val, matchingInfo){
var res;
if(val.type === arg1.type && val.value === arg1.value){
return true;
}
res = matching(val, matchingInfo);
return res;
};
var val;
matchingInfo = AscCommonExcel.matchingValue(arg1.toString());
matchingInfo = AscCommonExcel.matchingValue(arg1);
if (cElementType.cellsRange === arg0.type) {
arg0.foreach2(function (_val) {
_count += compareValues(_val, matchingInfo);
_count += matching(_val, matchingInfo);
})
} else if (cElementType.cellsRange3D === arg0.type) {
val = arg0.getValue();
for (var i = 0; i < val.length; i++) {
_count += compareValues(val[i], matchingInfo);
_count += matching(val[i], matchingInfo);
}
} else {
val = arg0.getValue();
_count += compareValues(val, matchingInfo);
_count += matching(val, matchingInfo);
}
return this.value = new cNumber(_count);
......@@ -2752,7 +2740,7 @@
return this.value = new cError(cErrorType.wrong_value_type);
}
matchingInfo = AscCommonExcel.matchingValue(arg1.toString());
matchingInfo = AscCommonExcel.matchingValue(arg1);
arg1Matrix = arg0.getMatrix();
if (cElementType.cellsRange3D === arg0.type) {
arg1Matrix = arg1Matrix[0];
......@@ -5136,7 +5124,7 @@
return this.value = new cError(cErrorType.wrong_value_type);
}
matchingInfo = AscCommonExcel.matchingValue(arg2.toString());
matchingInfo = AscCommonExcel.matchingValue(arg2);
var arg1Matrix = arg1.getMatrix();
if (arg0Matrix.length !== arg1Matrix.length) {
......@@ -5241,7 +5229,7 @@
return this.value = new cError(cErrorType.wrong_value_type);
}
matchingInfo = AscCommonExcel.matchingValue(arg2.toString());
matchingInfo = AscCommonExcel.matchingValue(arg2);
var arg1Matrix = arg1.getMatrix();
if (arg0Matrix.length !== arg1Matrix.length) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment