Commit 25acf0df authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

String.prototype.repeat

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@64626 954022d7-b5bf-4e40-9824-e11837661b57
parent 2e73dd84
......@@ -12,6 +12,48 @@ if (typeof String.prototype.endsWith !== 'function') {
};
String.prototype['endsWith'] = String.prototype.endsWith;
}
if (typeof String.prototype.repeat !== 'function') {
String.prototype.repeat = function(count) {
'use strict';
if (this == null) {
throw new TypeError('can\'t convert ' + this + ' to object');
}
var str = '' + this;
count = +count;
if (count != count) {
count = 0;
}
if (count < 0) {
throw new RangeError('repeat count must be non-negative');
}
if (count == Infinity) {
throw new RangeError('repeat count must be less than infinity');
}
count = Math.floor(count);
if (str.length == 0 || count == 0) {
return '';
}
// Обеспечение того, что count является 31-битным целым числом, позволяет нам значительно
// соптимизировать главную часть функции. Впрочем, большинство современных (на август
// 2014 года) браузеров не обрабатывают строки, длиннее 1 << 28 символов, так что:
if (str.length * count >= 1 << 28) {
throw new RangeError('repeat count must not overflow maximum string size');
}
var rpt = '';
for (;;) {
if ((count & 1) == 1) {
rpt += str;
}
count >>>= 1;
if (count == 0) {
break;
}
str += str;
}
return rpt;
}
String.prototype['repeat'] = String.prototype.repeat;
}
var g_oZipChanges = null;
//var g_sMainServiceLocalUrl = "/CanvasService.ashx";
......@@ -782,7 +824,8 @@ var str_namedRanges = "A-Za-z\u005F\u0080-\u0081\u0083\u0085-\u0087\u0089-\u008A
rx_arraySeparatorsDef = /^ *[,;] */,
rx_numberDef = /^ *[+-]?\d*(\d|\.)\d*([eE][+-]?\d+)?/,
rx_CommaDef = /^ *[,;] */,
rx_arrayDef = /^\{(([+-]?\d*(\d|\.)\d*([eE][+-]?\d+)?)?(\"((\"\"|[^\"])*)\")?(#NULL!|#DIV\/0!|#VALUE!|#REF!|#NAME\?|#NUM!|#UNSUPPORTED_FUNCTION!|#N\/A|#GETTING_DATA|FALSE|TRUE)?[,;]?)*\}/i;
rx_arrayDef = /^\{(([+-]?\d*(\d|\.)\d*([eE][+-]?\d+)?)?(\"((\"\"|[^\"])*)\")?(#NULL!|#DIV\/0!|#VALUE!|#REF!|#NAME\?|#NUM!|#UNSUPPORTED_FUNCTION!|#N\/A|#GETTING_DATA|FALSE|TRUE)?[,;]?)*\}/i,
rx_
/**
......
......@@ -384,7 +384,7 @@ function convertFromTo( src, from, to, charLim ) {
else {
charLim = parseInt( charLim );
if ( charLim >= res.length ) {
return new cString( (String.prototype.repeat( '0', charLim - res.length ) + res).toUpperCase() );
return new cString( ( '0'.repeat( charLim - res.length ) + res).toUpperCase() );
}
else {
return new cError( cErrorType.not_numeric );
......@@ -1302,7 +1302,7 @@ cDEC2BIN.prototype.Calculate = function ( arg ) {
if ( validDEC2BINNumber( arg0 ) && arg0 >= -512 && arg0 <= 511 && ( arg1 > 0 && arg1 <= 10 || arg1 == undefined ) ) {
if ( arg0 < 0 ) {
this.value = new cString( '1' + String.prototype.repeat( '0', 9 - (512 + arg0).toString( NumberBase.BIN ).length ) + (512 + arg0).toString( NumberBase.BIN ).toUpperCase() );
this.value = new cString( '1' + '0'.repeat(9 - (512 + arg0).toString( NumberBase.BIN ).length ) + (512 + arg0).toString( NumberBase.BIN ).toUpperCase() );
}
else {
this.value = convertFromTo( arg0, NumberBase.DEC, NumberBase.BIN, arg1 );
......@@ -1663,7 +1663,7 @@ cHEX2BIN.prototype.Calculate = function ( arg ) {
if ( negative ) {
var str = (512 + arg0DEC).toString( NumberBase.BIN );
this.value = new cString( '1' + String.prototype.repeat( '0', 9 - str.length ) + str );
this.value = new cString( '1' + '0'.repeat(9 - str.length ) + str );
}
else {
this.value = convertFromTo( arg0DEC, NumberBase.DEC, NumberBase.BIN, arg1 );
......@@ -2663,7 +2663,7 @@ cOCT2BIN.prototype.Calculate = function ( arg ) {
if ( negative ) {
var str = (512 + arg0DEC).toString( NumberBase.BIN );
this.value = new cString( ('1' + String.prototype.repeat( '0', 9 - str.length ) + str).toUpperCase() );
this.value = new cString( ('1' + '0'.repeat( 9 - str.length ) + str).toUpperCase() );
}
else {
this.value = convertFromTo( arg0DEC, NumberBase.DEC, NumberBase.BIN, arg1 );
......
......@@ -226,14 +226,6 @@ RegExp.escape = function(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
String.prototype.repeat = function ( s, n ) {
var a = [];
while ( a.length < n ) {
a.push( s );
}
return a.join( '' );
};
parserHelp.setDigitSeparator( g_oDefaultCultureInfo.NumberDecimalSeparator );
/** @constructor */
......
......@@ -1295,10 +1295,7 @@ cREPT.prototype.Calculate = function ( arg ) {
if ( arg1.getValue() < 0 ) return this.value = new cError( cErrorType.wrong_value_type );
for ( var i = 0; i < arg1.getValue(); i++ ) {
res = res.concat( arg0.getValue() );
}
return this.value = new cString( res );
return this.value = new cString( arg0.getValue().repeat(arg1.getValue()) );
}
cREPT.prototype.getInfo = function () {
return {
......
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