Commit ffe56802 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

в parserHelper добавил operand_str и pCurrPos (иначе каждый раз пересоздавание...

в parserHelper добавил operand_str и pCurrPos (иначе каждый раз пересоздавание объекта было). Переделал prototype = new Object на prototype.{add method}

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@57461 954022d7-b5bf-4e40-9824-e11837661b57
parent a9207adf
...@@ -244,7 +244,7 @@ var rx_operators = /^ *[-+*\/^&%<=>:] */, ...@@ -244,7 +244,7 @@ var rx_operators = /^ *[-+*\/^&%<=>:] */,
rg_validDEC2HEXNumber = /^-?[0-9]{1,12}$/, rg_validDEC2HEXNumber = /^-?[0-9]{1,12}$/,
rg_validHEXNumber = /^[0-9A-Fa-f]{1,10}$/, rg_validHEXNumber = /^[0-9A-Fa-f]{1,10}$/,
rg_validOCTNumber = /^[0-7]{1,10}$/, rg_validOCTNumber = /^[0-7]{1,10}$/,
rg_complex_number = new XRegExp( "^(?<real>[-+]?(?:\\d*(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?))?(?<img>([-+]?(\\d*(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?)?[ij])?)", "g" ) rg_complex_number = new XRegExp( "^(?<real>[-+]?(?:\\d*(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?))?(?<img>([-+]?(\\d*(?:\\.\\d+)?(?:[Ee][+-]?\\d+)?)?[ij])?)", "g" );
/** /**
...@@ -252,348 +252,301 @@ var rx_operators = /^ *[-+*\/^&%<=>:] */, ...@@ -252,348 +252,301 @@ var rx_operators = /^ *[-+*\/^&%<=>:] */,
* @constructor * @constructor
*/ */
function parserHelper() { function parserHelper() {
this.operand_str = null;
this.pCurrPos = null;
} }
parserHelper.prototype = { parserHelper.prototype._reset = function () {
_reset:function () { this.operand_str = null;
delete this.operand_str; this.pCurrPos = null;
delete this.pCurrPos; };
}, parserHelper.prototype.isOperator = function ( formula, start_pos ) {
if (this instanceof parserHelper) {
isOperator:function ( formula, start_pos ) { this._reset();
if ( this instanceof parserHelper ) { }
this._reset();
}
var str = formula.substring( start_pos );
var match = str.match( rx_operators );
if ( match == null || match == undefined )
return false;
else {
var mt = str.match( rx_LG );
if ( mt ) match = mt;
this.operand_str = match[0].replace( rx_space_g, "" );
this.pCurrPos += match[0].length;
return true;
}
return false;
},
isFunc:function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var frml = formula.substring( start_pos );
var match = (frml).match( rg );
if ( match != null && match != undefined ) {
if ( match.length == 2 ) {
this.pCurrPos += match[1].length;
this.operand_str = match[1];
return true;
}
}
// this.operand_str = null;
return false;
},
isArea:function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var subSTR = formula.substring( start_pos );
var match = subSTR.match( rgRange ) || subSTR.match( rgCols ) || subSTR.match( rgRows );
if ( match != null || match != undefined ) {
this.pCurrPos += match[0].length;
this.operand_str = match[0];
return true;
}
// this.operand_str = null;
return false;
},
isRef:function ( formula, start_pos, allRef ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var substr = formula.substring( start_pos );
var match = substr.match( rx_ref );
if ( match != null || match != undefined ) {
var m0 = match[0], m1 = match[1], m2 = match[2];
if ( match.length >= 3 && g_oCellAddressUtils.colstrToColnum( m1.substr( 0, (m1.length - m2.length) ) ) <= gc_nMaxCol && parseInt( m2 ) <= gc_nMaxRow ) {
this.pCurrPos += m0.indexOf( " " ) > -1 ? m0.length - 1 : m1.length;
this.operand_str = m1;
return true;
}
else if ( allRef ) {
match = substr.match( rx_refAll );
if ( (match != null || match != undefined) && match.length >= 3 ) {
var m1 = match[1];
this.pCurrPos += m1.length;
this.operand_str = m1;
return true;
}
}
}
// this.operand_str = null;
return false;
},
is3DRef:function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var subSTR = formula.substring( start_pos );
var match = rx_ref3D_quoted.xexec( subSTR ) || rx_ref3D_non_quoted.xexec( subSTR );
if ( match != null || match != undefined ) {
this.pCurrPos += match[0].length;
this.operand_str = match[1];
return [ true, match["name_from"] ? match["name_from"].replace( /''/g, "'" ) : null, match["name_to"] ? match["name_to"].replace( /''/g, "'" ) : null ];
}
// this.operand_str = null;
return [false, null, null];
},
isNextPtg:function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var subSTR = formula.substring( start_pos );
return (
( subSTR.match( rx_before_operators ) != null || subSTR.match( rx_before_operators ) != undefined ) &&
( subSTR.match( rx_space ) != null || subSTR.match( rx_space ) != undefined )
)
},
isNumber:function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var match = (formula.substring( start_pos )).match( rx_number );
if ( match == null || match == undefined )
return false;
else {
this.operand_str = match[0];
this.pCurrPos += match[0].length;
return true;
}
return false;
},
isLeftParentheses:function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var match = (formula.substring( start_pos )).match( rx_LeftParentheses );
if ( match == null || match == undefined )
return false;
else {
this.operand_str = match[0].replace( rx_space, "" );
this.pCurrPos += match[0].length;
return true;
}
return false;
},
isRightParentheses:function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var match = (formula.substring( start_pos )).match( rx_RightParentheses );
if ( match == null || match == undefined )
return false;
else {
this.operand_str = match[0].replace( rx_space, "" );
this.pCurrPos += match[0].length;
return true;
}
return false;
},
isComma:function ( formula, start_pos ) { var str = formula.substring( start_pos );
if ( this instanceof parserHelper ) { var match = str.match( rx_operators );
this._reset(); if (match != null) {
} var mt = str.match( rx_LG );
if ( mt ) match = mt;
this.operand_str = match[0].replace( rx_space_g, "" );
this.pCurrPos += match[0].length;
return true;
}
return false;
};
parserHelper.prototype.isFunc = function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var match = (formula.substring( start_pos )).match( rx_Comma ); var frml = formula.substring( start_pos );
if ( match == null || match == undefined ) var match = (frml).match( rg );
return false;
else {
this.operand_str = match[0];
this.pCurrPos += match[0].length;
return true;
}
return false;
},
isError:function ( formula, start_pos ) { if (match != null) {
if ( this instanceof parserHelper ) { if ( match.length == 2 ) {
this._reset(); this.pCurrPos += match[1].length;
} this.operand_str = match[1];
return true;
}
}
return false;
};
parserHelper.prototype.isArea = function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var match = (formula.substring( start_pos )).match( rx_error ); var subSTR = formula.substring( start_pos );
if ( match == null || match == undefined ) var match = subSTR.match( rgRange ) || subSTR.match( rgCols ) || subSTR.match( rgRows );
return false; if (match != null) {
else { this.pCurrPos += match[0].length;
this.operand_str = match[0]; this.operand_str = match[0];
this.pCurrPos += match[0].length; return true;
return true; }
} return false;
return false; };
}, parserHelper.prototype.isRef = function ( formula, start_pos, allRef ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var substr = formula.substring( start_pos );
var match = substr.match( rx_ref );
if (match != null) {
var m0 = match[0], m1 = match[1], m2 = match[2];
if ( match.length >= 3 && g_oCellAddressUtils.colstrToColnum( m1.substr( 0, (m1.length - m2.length) ) ) <= gc_nMaxCol && parseInt( m2 ) <= gc_nMaxRow ) {
this.pCurrPos += m0.indexOf( " " ) > -1 ? m0.length - 1 : m1.length;
this.operand_str = m1;
return true;
} else if ( allRef ) {
match = substr.match( rx_refAll );
if ( (match != null || match != undefined) && match.length >= 3 ) {
var m1 = match[1];
this.pCurrPos += m1.length;
this.operand_str = m1;
return true;
}
}
}
isBoolean:function ( formula, start_pos ) { return false;
if ( this instanceof parserHelper ) { };
this._reset(); parserHelper.prototype.is3DRef = function ( formula, start_pos ) {
} if ( this instanceof parserHelper ) {
this._reset();
}
var match = (formula.substring( start_pos )).match( rx_bool ); var subSTR = formula.substring( start_pos );
if ( match == null || match == undefined ) var match = rx_ref3D_quoted.xexec( subSTR ) || rx_ref3D_non_quoted.xexec( subSTR );
return false;
else {
this.operand_str = match[1];
this.pCurrPos += match[1].length;
return true;
}
return false;
},
isString:function ( formula, start_pos ) { if (match != null) {
if ( this instanceof parserHelper ) { this.pCurrPos += match[0].length;
this._reset(); this.operand_str = match[1];
} return [ true, match["name_from"] ? match["name_from"].replace( /''/g, "'" ) : null, match["name_to"] ? match["name_to"].replace( /''/g, "'" ) : null ];
}
return [false, null, null];
};
parserHelper.prototype.isNextPtg = function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var match = (formula.substring( start_pos )).match( rx_string ); var subSTR = formula.substring( start_pos );
if ( match != null || match != undefined ) { return (subSTR.match( rx_before_operators ) != null && subSTR.match( rx_space ) != null);
this.operand_str = match[1].replace( "\"\"", "\"" ); };
this.pCurrPos += match[0].length; parserHelper.prototype.isNumber = function ( formula, start_pos ) {
return true; if ( this instanceof parserHelper ) {
} this._reset();
return false; }
},
isName:function ( formula, start_pos, wb, ws ) { var match = (formula.substring( start_pos )).match( rx_number );
if ( this instanceof parserHelper ) { if (match != null) {
this._reset(); this.operand_str = match[0];
} this.pCurrPos += match[0].length;
return true;
}
return false;
};
parserHelper.prototype.isLeftParentheses = function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var subSTR = formula.substring( start_pos ); var match = (formula.substring( start_pos )).match( rx_LeftParentheses );
var match = rx_name.xexec( subSTR ); if (match != null) {
this.operand_str = match[0].replace( rx_space, "" );
this.pCurrPos += match[0].length;
return true;
}
return false;
};
parserHelper.prototype.isRightParentheses = function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
if ( match != null || match != undefined ) { var match = (formula.substring( start_pos )).match( rx_RightParentheses );
var name = match["name"]; if (match != null) {
if ( name && name.length != 0 && wb.DefinedNames && wb.isDefinedNamesExists( name, ws ? ws.getId() : null ) ) { this.operand_str = match[0].replace( rx_space, "" );
this.pCurrPos += name.length; this.pCurrPos += match[0].length;
this.operand_str = name; return true;
return [ true, name ]; }
} return false;
this.operand_str = name; };
} parserHelper.prototype.isComma = function ( formula, start_pos ) {
return [false]; if ( this instanceof parserHelper ) {
}, this._reset();
}
isArray:function ( formula, start_pos, wb ) { var match = (formula.substring( start_pos )).match( rx_Comma );
if ( this instanceof parserHelper ) { if (match != null) {
this._reset(); this.operand_str = match[0];
} this.pCurrPos += match[0].length;
return true;
}
return false;
};
parserHelper.prototype.isError = function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var subSTR = formula.substring( start_pos ); var match = (formula.substring( start_pos )).match( rx_error );
var match = (formula.substring( start_pos )).match( rx_array ); if (match != null) {
this.operand_str = match[0];
this.pCurrPos += match[0].length;
return true;
}
return false;
};
parserHelper.prototype.isBoolean = function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
if ( match != null || match != undefined ) { var match = (formula.substring( start_pos )).match( rx_bool );
this.operand_str = match[0].substring( 1, match[0].length - 1 ); if (match != null) {
this.pCurrPos += match[0].length; this.operand_str = match[1];
return true; this.pCurrPos += match[1].length;
} return true;
}
return false;
};
parserHelper.prototype.isString = function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
return false; var match = (formula.substring( start_pos )).match( rx_string );
}, if (match != null) {
this.operand_str = match[1].replace( "\"\"", "\"" );
this.pCurrPos += match[0].length;
return true;
}
return false;
};
parserHelper.prototype.isName = function ( formula, start_pos, wb, ws ) {
if ( this instanceof parserHelper ) {
this._reset();
}
isLeftBrace:function ( formula, start_pos ) { var subSTR = formula.substring( start_pos );
if ( this instanceof parserHelper ) { var match = rx_name.xexec( subSTR );
this._reset();
} if (match != null) {
var name = match["name"];
if ( name && name.length != 0 && wb.DefinedNames && wb.isDefinedNamesExists( name, ws ? ws.getId() : null ) ) {
this.pCurrPos += name.length;
this.operand_str = name;
return [ true, name ];
}
this.operand_str = name;
}
return [false];
};
parserHelper.prototype.isArray = function ( formula, start_pos ) {
if ( this instanceof parserHelper ) {
this._reset();
}
var match = (formula.substring( start_pos )).match( rx_LeftBrace ); var match = (formula.substring( start_pos )).match( rx_array );
if ( match == null || match == undefined )
return false;
else {
this.operand_str = match[0].replace( /\s/, "" );
this.pCurrPos += match[0].length;
return true;
}
return false;
},
isRightBrace:function ( formula, start_pos ) { if (match != null) {
if ( this instanceof parserHelper ) { this.operand_str = match[0].substring( 1, match[0].length - 1 );
this._reset(); this.pCurrPos += match[0].length;
} return true;
}
var match = (formula.substring( start_pos )).match( rx_RightBrace ); return false;
if ( match == null || match == undefined ) };
return false; parserHelper.prototype.isLeftBrace = function ( formula, start_pos ) {
else { if ( this instanceof parserHelper ) {
this.operand_str = match[0].replace( rx_space, "" ); this._reset();
this.pCurrPos += match[0].length; }
return true;
}
return false;
},
// Парсим ссылку на диапазон в листе
parse3DRef:function ( formula ) {
// Сначала получаем лист
var is3DRefResult = this.is3DRef( formula, 0 );
if ( is3DRefResult && true === is3DRefResult[0] ) {
// Имя листа в ссылке
var sheetName = is3DRefResult[1];
// Ищем начало range
var indexStartRange = formula.indexOf( "!" ) + 1;
if ( this.isArea( formula, indexStartRange ) ) {
if ( this.operand_str.length == formula.substring( indexStartRange ).length )
return {sheet:sheetName, range:this.operand_str};
else
return null;
}
else if ( this.isRef( formula, indexStartRange ) ) {
if ( this.operand_str.length == formula.substring( indexStartRange ).length )
return {sheet:sheetName, range:this.operand_str};
else
return null;
} var match = (formula.substring( start_pos )).match( rx_LeftBrace );
} if (match != null) {
// Возвращаем ошибку this.operand_str = match[0].replace( /\s/, "" );
return null; this.pCurrPos += match[0].length;
}, return true;
}
// Возвращает ссылку на диапазон с листом (название листа экранируется) return false;
get3DRef: function (sheet, range) { };
sheet = sheet.split(":"); parserHelper.prototype.isRightBrace = function ( formula, start_pos ) {
var wsFrom = sheet[0], if ( this instanceof parserHelper ) {
wsTo = sheet[1] === undefined ? wsFrom : sheet[1]; this._reset();
if ( rx_test_ws_name.test( wsFrom ) && rx_test_ws_name.test( wsTo ) ) { }
return (wsFrom !== wsTo ? wsFrom + ":" + wsTo : wsFrom) + "!" + range;
}
else{
wsFrom = wsFrom.replace( /'/g, "''" );
wsTo = wsTo.replace( /'/g, "''" );
return "'" + (wsFrom !== wsTo ? wsFrom + ":" + wsTo : wsFrom) + "'!" + range;
}
},
// Возвращает экранируемое название листа var match = (formula.substring( start_pos )).match( rx_RightBrace );
getEscapeSheetName: function (sheet) { if (match != null) {
return rx_test_ws_name.test(sheet) ? sheet : "'" + sheet.replace(/'/g, "''") + "'"; this.operand_str = match[0].replace( rx_space, "" );
this.pCurrPos += match[0].length;
return true;
}
return false;
};
// Парсим ссылку на диапазон в листе
parserHelper.prototype.parse3DRef = function ( formula ) {
// Сначала получаем лист
var is3DRefResult = this.is3DRef( formula, 0 );
if ( is3DRefResult && true === is3DRefResult[0] ) {
// Имя листа в ссылке
var sheetName = is3DRefResult[1];
// Ищем начало range
var indexStartRange = formula.indexOf( "!" ) + 1;
if ( this.isArea( formula, indexStartRange ) ) {
if ( this.operand_str.length == formula.substring( indexStartRange ).length )
return {sheet:sheetName, range:this.operand_str};
else
return null;
}
else if ( this.isRef( formula, indexStartRange ) ) {
if ( this.operand_str.length == formula.substring( indexStartRange ).length )
return {sheet:sheetName, range:this.operand_str};
else
return null;
}
} }
// Возвращаем ошибку
return null;
}; };
// Возвращает ссылку на диапазон с листом (название листа экранируется)
parserHelper.prototype.get3DRef = function (sheet, range) {
sheet = sheet.split(":");
var wsFrom = sheet[0],
wsTo = sheet[1] === undefined ? wsFrom : sheet[1];
if ( rx_test_ws_name.test( wsFrom ) && rx_test_ws_name.test( wsTo ) ) {
return (wsFrom !== wsTo ? wsFrom + ":" + wsTo : wsFrom) + "!" + range;
} else {
wsFrom = wsFrom.replace( /'/g, "''" );
wsTo = wsTo.replace( /'/g, "''" );
return "'" + (wsFrom !== wsTo ? wsFrom + ":" + wsTo : wsFrom) + "'!" + range;
}
};
// Возвращает экранируемое название листа
parserHelper.prototype.getEscapeSheetName = function (sheet) {
return rx_test_ws_name.test(sheet) ? sheet : "'" + sheet.replace(/'/g, "''") + "'";
};
var parserHelp = new parserHelper(); var parserHelp = new parserHelper();
\ No newline at end of file
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