Skip to content

Commit

Permalink
fix maximum call stack
Browse files Browse the repository at this point in the history
  • Loading branch information
siarheidudko committed Jul 24, 2019
1 parent 32a45b1 commit 327596d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 47 deletions.
86 changes: 40 additions & 46 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,62 +53,56 @@ let Parser = function(){
charArr = string.split('');
}
if(charArr.length > 0){
let parseSymbol = function(s){
if(s < charArr.length){
switch(charArr[s]){
case '{':
self.LeftBrace++;
self.StringBuffer = self.StringBuffer + charArr[s];
break;
case '}':
self.RightBrace++;
self.StringBuffer = self.StringBuffer + charArr[s];
break;
case '\0':
// case '\a':
case '\b':
case '\t':
case '\n':
case '\v':
case '\f':
case '\r':
// case '\e':
if(self.OpenQuotes && (self.LeftBrace !== 0)){ self.StringBuffer = self.StringBuffer + charArr[s]; }
break;
case '"':
if(self.OpenQuotes){ self.OpenQuotes = false; } else if (self.LeftBrace !== 0) {
self.OpenQuotes = true;
}
default:
if(self.LeftBrace !== 0) { self.StringBuffer = self.StringBuffer + charArr[s]; }
break;
}
if((self.LeftBrace !== 0) && (self.LeftBrace === self.RightBrace)){
try{
let _object = JSON.parse(self.StringBuffer);
self.Transform.push(_object);
} catch(err){
error.push(err);
} finally {
self.clear();
parseSymbol(++s);
for(let s = 0; s < charArr.length; s++){
switch(charArr[s]){
case '{':
self.LeftBrace++;
self.StringBuffer = self.StringBuffer + charArr[s];
break;
case '}':
self.RightBrace++;
self.StringBuffer = self.StringBuffer + charArr[s];
break;
case '\0':
// case '\a':
case '\b':
case '\t':
case '\n':
case '\v':
case '\f':
case '\r':
// case '\e':
if(self.OpenQuotes && (self.LeftBrace !== 0)){ self.StringBuffer = self.StringBuffer + charArr[s]; }
break;
case '"':
if(self.OpenQuotes){ self.OpenQuotes = false; } else if (self.LeftBrace !== 0) {
self.OpenQuotes = true;
}
} else if(self.LeftBrace < self.RightBrace){
default:
if(self.LeftBrace !== 0) { self.StringBuffer = self.StringBuffer + charArr[s]; }
break;
}
if((self.LeftBrace !== 0) && (self.LeftBrace === self.RightBrace)){
try{
let _object = JSON.parse(self.StringBuffer);
self.Transform.push(_object);
} catch(err){
error.push(err);
} finally {
self.clear();
error.push(new Error('Parsing error, clear buffer!'));
parseSymbol(++s);
} else {
parseSymbol(++s);
}
} else {
} else if(self.LeftBrace < self.RightBrace){
self.clear();
error.push(new Error('Parsing error, clear buffer!'));
}
if(s === (charArr.length -1)){
if(error.length > 0){
return callback(error);
} else {
return callback();
}
}
};
parseSymbol(0);
} else {
return callback(new Error('Incoming data type is '+typeof(charArr)+', require data type is String or Buffer!'));
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sergdudko/objectstream",
"version": "0.0.2",
"version": "0.0.3",
"description": "Creates a stream to convert json from string or convert json to drain. The stream is based on the incoming object stream.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 327596d

Please sign in to comment.