Commit 92ddbb5e authored by Alexander.Trofimov's avatar Alexander.Trofimov

refactoring bool values in formulas

parent fb1a6397
......@@ -751,7 +751,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
cString.prototype.tocBool = function () {
var res;
if (parserHelp.isBoolean(this.value, 0)) {
res = new cBool(parserHelp.operand_str.toUpperCase() === cBoolLocal["t"].toUpperCase());
res = new cBool(parserHelp.operand_str.toUpperCase() === cBoolLocal.t);
} else {
res = this;
}
......@@ -769,7 +769,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
var v = false;
switch (val.toString().toUpperCase()) {
case "TRUE":
case cBoolLocal["t"].toUpperCase():
case cBoolLocal.t:
v = true;
}
cBaseType.call(this, v);
......@@ -791,7 +791,7 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
return new cString(this.value ? "TRUE" : "FALSE");
};
cBool.prototype.toLocaleString = function () {
return new cString(this.value ? cBoolLocal["t"].toUpperCase() : cBoolLocal["f"].toUpperCase());
return new cString(this.value ? cBoolLocal.t : cBoolLocal.f);
};
cBool.prototype.tocBool = function () {
return this;
......@@ -881,10 +881,9 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
cError.prototype = Object.create(cBaseType.prototype);
cError.prototype.constructor = cError;
cError.prototype.type = cElementType.error;
cError.prototype.tocNumber =
cError.prototype.tocString = cError.prototype.tocBool = cError.prototype.tocEmpty = function () {
return this;
};
cError.prototype.tocNumber = cError.prototype.tocString = cError.prototype.tocBool = function () {
return this;
};
cError.prototype.toLocaleString = function () {
switch (this.value) {
case cErrorOrigin["value"]:
......@@ -941,9 +940,6 @@ parserHelp.setDigitSeparator(AscCommon.g_oDefaultCultureInfo.NumberDecimalSepara
}
return cErrorLocal["na"];
};
/*cError.prototype.toString = function () {
return new cString( this.value ? cBoolLocal["t"].toUpperCase() : cBoolLocal["f"].toUpperCase() );
};*/
/**
* @constructor
......
......@@ -3092,8 +3092,8 @@ CCellValue.prototype =
var sResult = "";
if(null != this.number)
{
if(CellValueType.Bool == this.type)
sResult = this.number == 1 ? cBoolLocal["t"].toUpperCase() : cBoolLocal["f"].toUpperCase();
if(CellValueType.Bool === this.type)
sResult = this.number == 1 ? cBoolLocal.t : cBoolLocal.f;
else
sResult = this.number.toString();
}
......@@ -3256,11 +3256,11 @@ CCellValue.prototype =
}
}
}
} else if (CellValueType.Bool == this.type) {
} else if (CellValueType.Bool === this.type) {
if (null != this.number) {
sText = (0 != this.number) ? cBoolLocal["t"].toUpperCase() : cBoolLocal["f"].toUpperCase();
sText = (0 != this.number) ? cBoolLocal.t : cBoolLocal.f;
}
} else if (CellValueType.Error == this.type) {
} else if (CellValueType.Error === this.type) {
if (null != this.text) {
sText = this._getValueTypeError(this.text);
}
......@@ -3299,13 +3299,13 @@ CCellValue.prototype =
{
if(null != this.text || null != this.number)
{
if (CellValueType.Bool == this.type && null != this.number)
oValueText = (this.number == 1) ? cBoolLocal["t"].toUpperCase() : cBoolLocal["f"].toUpperCase();
if (CellValueType.Bool === this.type && null != this.number)
oValueText = (this.number == 1) ? cBoolLocal.t : cBoolLocal.f;
else
{
if(null != this.text)
oValueText = this.text;
if(CellValueType.Number == this.type || CellValueType.String == this.type)
if(CellValueType.Number === this.type || CellValueType.String === this.type)
{
var oNumFormat;
if(null != xfs && null != xfs.num)
......@@ -3511,13 +3511,11 @@ CCellValue.prototype =
else
{
var sUpText = val.toUpperCase();
if(cBoolLocal["t"].toUpperCase() == sUpText || cBoolLocal["f"].toUpperCase() == sUpText)
if(cBoolLocal.t === sUpText || cBoolLocal.f === sUpText)
{
this.type = CellValueType.Bool;
this.number = (cBoolLocal["t"].toUpperCase() == sUpText) ? 1 : 0;
this.number = (cBoolLocal.t === sUpText) ? 1 : 0;
}
// else if( "#NULL!" == sUpText || "#DIV/0!" == sUpText || "#NAME?" == sUpText || "#NUM!" == sUpText ||
// "#N/A" == sUpText || "#REF!" == sUpText || "#VALUE!" == sUpText )
else if(checkCellValueTypeError(sUpText))
{
this.type = CellValueType.Error;
......
......@@ -2615,7 +2615,7 @@
for (var f in oFormulaList) {
this.formulasList.push(f);
}
this.arrExcludeFormulas = [cBoolLocal["t"].toUpperCase(), cBoolLocal["f"].toUpperCase()];
this.arrExcludeFormulas = [cBoolLocal.t, cBoolLocal.f];
};
WorkbookView.prototype._setHintsProps = function(bIsHinting, bIsSubpixHinting) {
......
......@@ -792,25 +792,26 @@
columns: 6
};
var cStrucTableLocalColumns = null,
cBoolLocal = {},
cErrorOrigin = {
"nil": "#NULL!",
"div": "#DIV\/0!",
"value": "#VALUE!",
"ref": "#REF!",
"name": "#NAME?",
"num": "#NUM!",
"na": "#N\/A",
"getdata": "#GETTING_DATA",
"uf": "#UNSUPPORTED_FUNCTION!"
},
cErrorLocal = {};
var cStrucTableLocalColumns = null;
var cBoolOrigin = {'t': 'TRUE', 'f': 'FALSE'};
var cBoolLocal = {};
var cErrorOrigin = {
"nil": "#NULL!",
"div": "#DIV\/0!",
"value": "#VALUE!",
"ref": "#REF!",
"name": "#NAME?",
"num": "#NUM!",
"na": "#N\/A",
"getdata": "#GETTING_DATA",
"uf": "#UNSUPPORTED_FUNCTION!"
};
var cErrorLocal = {};
function build_local_rx(data)
{
rx_table_local = build_rx_table(data ? data["StructureTables"] : null);
rx_bool_local = build_rx_bool(data ? data["CONST_TRUE_FALSE"] : null);
rx_bool_local = build_rx_bool((data && data["CONST_TRUE_FALSE"]) || cBoolOrigin);
rx_error_local = build_rx_error(data ? data["CONST_ERROR"] : null);
}
......@@ -858,12 +859,9 @@
function build_rx_bool(local)
{
// ToDo переделать на более правильную реализацию. Не особо правильное копирование
local = local ? local : {"t": "TRUE", "f": "FALSE"};
var t = cBoolLocal['t'] = local['t'];
var f = cBoolLocal['f'] = local['f'];
var t = cBoolLocal.t = local['t'].toUpperCase();
var f = cBoolLocal.f = local['f'].toUpperCase();
build_rx_array_local(local);
return new RegExp("^(" + t + "|" + f + ")([-+*\\/^&%<=>: ;),]|$)", "i");
}
......@@ -902,20 +900,6 @@
cErrorLocal["uf"] + ")", "i");
}
function build_rx_array_local(localBool, digitSepar, localError)
{
var localBool = ( localBool ? localBool : {"t": "TRUE", "f": "FALSE"} );
rx_array_local = build_rx_array(localBool, digitSepar, localError);
}
function build_rx_array(localBool, digitSepar, localError)
{
return new RegExp("^\\{(([+-]?\\d*(\\d|\\" + digitSepar + ")\\d*([eE][+-]?\\d+)?)?(\"((\"\"|[^\"])*)\")?" +
"(#NULL!|#DIV\/0!|#VALUE!|#REF!|#NAME\\?|#NUM!|#UNSUPPORTED_FUNCTION!|#N\/A|#GETTING_DATA|" +
localBool["t"] + "|" + localBool["f"] + ")?[" + FormulaSeparators.arrayRowSeparator + "\\" + FormulaSeparators.arrayColSeparator + "]?)*\\}", "i");
}
var PostMessageType = {
UploadImage: 0,
ExtensionExist: 1
......@@ -1416,7 +1400,7 @@
rx_error = build_rx_error(null),
rx_error_local = build_rx_error(null),
rx_bool = build_rx_bool(null),
rx_bool = build_rx_bool(cBoolOrigin),
rx_bool_local = rx_bool,
rx_string = /^\"((\"\"|[^\"])*)\"/,
rx_test_ws_name = new test_ws_name2(),
......@@ -1430,9 +1414,6 @@
rx_numberDef = /^ *[+-]?\d*(\d|\.)\d*([eE][+-]?\d+)?/,
rx_CommaDef = /^ *[,;] */,
rx_array_local = /^\{(([+-]?\d*(\d|\.)\d*([eE][+-]?\d+)?)?(\"((\"\"|[^\"])*)\")?(#NULL!|#DIV\/0!|#VALUE!|#REF!|#NAME\?|#NUM!|#UNSUPPORTED_FUNCTION!|#N\/A|#GETTING_DATA|FALSE|TRUE)?[,;]?)*\}/i,
rx_array = /^\{(([+-]?\d*(\d|\.)\d*([eE][+-]?\d+)?)?(\"((\"\"|[^\"])*)\")?(#NULL!|#DIV\/0!|#VALUE!|#REF!|#NAME\?|#NUM!|#UNSUPPORTED_FUNCTION!|#N\/A|#GETTING_DATA|FALSE|TRUE)?[,;]?)*\}/i,
rx_ControlSymbols = /^ *[\u0000-\u001F\u007F-\u009F] */,
emailRe = /^(mailto:)?([a-z0-9'\._-]+@[a-z0-9\.-]+\.[a-z0-9]{2,4})([a-яё0-9\._%+-=\? :&]*)/i,
......@@ -1866,7 +1847,7 @@
if (match != null)
{
var name = match["name"];
if (name && name.length != 0 && name != cBoolLocal["t"] && name != cBoolLocal["f"]/*&& wb.DefinedNames && wb.isDefinedNamesExists( name, ws ? ws.getId() : null )*/)
if (name && 0 !== name.length && name.toUpperCase() !== cBoolLocal.t && name.toUpperCase() !== cBoolLocal.f/*&& wb.DefinedNames && wb.isDefinedNamesExists( name, ws ? ws.getId() : null )*/)
{
this.pCurrPos += name.length;
this.operand_str = name;
......@@ -1876,24 +1857,6 @@
}
return [false];
};
parserHelper.prototype.isArray = function (formula, start_pos, digitDelim)
{
if (this instanceof parserHelper)
{
this._reset();
}
var match = (formula.substring(start_pos)).match(digitDelim ? rx_array_local : rx_array);
if (match != null)
{
this.operand_str = match[0].substring(1, match[0].length - 1);
this.pCurrPos += match[0].length;
return true;
}
return false;
};
parserHelper.prototype.isLeftBrace = function (formula, start_pos)
{
if (this instanceof parserHelper)
......@@ -2140,7 +2103,6 @@
FormulaSeparators.functionArgumentSeparator = ";";
rx_number = new RegExp("^ *[+-]?\\d*(\\d|\\" + FormulaSeparators.digitSeparator + ")\\d*([eE][+-]?\\d+)?");
rx_Comma = new RegExp("^ *[" + FormulaSeparators.functionArgumentSeparator + "] *");
// build_rx_array_local( cBoolLocal, digitSeparator, null);
rx_arraySeparators = new RegExp("^ *[" + FormulaSeparators.arrayRowSeparator + "\\" + FormulaSeparators.arrayColSeparator + "] *");
}
else
......@@ -2151,7 +2113,6 @@
FormulaSeparators.functionArgumentSeparator = FormulaSeparators.functionArgumentSeparatorDef;
rx_number = new RegExp("^ *[+-]?\\d*(\\d|\\" + FormulaSeparators.digitSeparatorDef + ")\\d*([eE][+-]?\\d+)?");
rx_Comma = new RegExp("^ *[" + FormulaSeparators.functionArgumentSeparatorDef + "] *");
// build_rx_array_local( cBoolLocal, digitSeparatorDef, null);
rx_arraySeparators = new RegExp("^ *[" + FormulaSeparators.arrayRowSeparatorDef + "\\" + FormulaSeparators.arrayColSeparatorDef + "] *");
}
rx_table_local = build_rx_table_cur();
......
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