Skip to content

Commit e536351

Browse files
jseterSergi Almacellas Abellana
authored andcommitted
Refactor substr calls to substring calls. (#725)
1 parent e0b474d commit e536351

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

papaparse.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ License: MIT
699699
if (contentRange === null) { // no content range, then finish!
700700
return -1;
701701
}
702-
return parseInt(contentRange.substr(contentRange.lastIndexOf('/') + 1));
702+
return parseInt(contentRange.substring(contentRange.lastIndexOf('/') + 1));
703703
}
704704
}
705705
NetworkStreamer.prototype = Object.create(ChunkStreamer.prototype);
@@ -788,8 +788,14 @@ License: MIT
788788
{
789789
if (this._finished) return;
790790
var size = this._config.chunkSize;
791-
var chunk = size ? remaining.substr(0, size) : remaining;
792-
remaining = size ? remaining.substr(size) : '';
791+
var chunk;
792+
if(size) {
793+
chunk = remaining.substring(0, size);
794+
remaining = remaining.substring(size);
795+
} else {
796+
chunk = remaining;
797+
remaining = '';
798+
}
793799
this._finished = !remaining;
794800
return this.parseChunk(chunk);
795801
};
@@ -1094,7 +1100,7 @@ License: MIT
10941100
{
10951101
_paused = true;
10961102
_parser.abort();
1097-
_input = _input.substr(_parser.getCharIndex());
1103+
_input = _input.substring(_parser.getCharIndex());
10981104
};
10991105

11001106
this.resume = function()
@@ -1332,7 +1338,7 @@ License: MIT
13321338

13331339
function guessLineEndings(input, quoteChar)
13341340
{
1335-
input = input.substr(0, 1024 * 1024); // max length 1 MB
1341+
input = input.substring(0, 1024 * 1024); // max length 1 MB
13361342
// Replace all the text inside quotes
13371343
var re = new RegExp(escapeRegExp(quoteChar) + '([^]*?)' + escapeRegExp(quoteChar), 'gm');
13381344
input = input.replace(re, '');
@@ -1450,7 +1456,7 @@ License: MIT
14501456
cursor += newline.length;
14511457
else if (ignoreLastRow)
14521458
return returnable();
1453-
if (comments && row.substr(0, commentsLen) === comments)
1459+
if (comments && row.substring(0, commentsLen) === comments)
14541460
continue;
14551461
if (stepIsFunction)
14561462
{
@@ -1553,7 +1559,7 @@ License: MIT
15531559
var spacesBetweenQuoteAndNewLine = extraSpaces(nextNewline);
15541560

15551561
// Closing quote followed by newline or 'unnecessary spaces + newLine'
1556-
if (input.substr(quoteSearch + 1 + spacesBetweenQuoteAndNewLine, newlineLen) === newline)
1562+
if (input.substring(quoteSearch + 1 + spacesBetweenQuoteAndNewLine, quoteSearch + 1 + spacesBetweenQuoteAndNewLine + newlineLen) === newline)
15571563
{
15581564
row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
15591565
saveRow(quoteSearch + 1 + spacesBetweenQuoteAndNewLine + newlineLen);
@@ -1592,7 +1598,7 @@ License: MIT
15921598
}
15931599

15941600
// Comment found at start of new line
1595-
if (comments && row.length === 0 && input.substr(cursor, commentsLen) === comments)
1601+
if (comments && row.length === 0 && input.substring(cursor, cursor + commentsLen) === comments)
15961602
{
15971603
if (nextNewline === -1) // Comment ends at EOF
15981604
return returnable();
@@ -1684,7 +1690,7 @@ License: MIT
16841690
if (ignoreLastRow)
16851691
return returnable();
16861692
if (typeof value === 'undefined')
1687-
value = input.substr(cursor);
1693+
value = input.substring(cursor);
16881694
row.push(value);
16891695
cursor = inputLen; // important in case parsing is paused
16901696
pushRow(row);

0 commit comments

Comments
 (0)