Skip to content

Commit

Permalink
Added evaluation for iOS and fixed a typo in regex in both files
Browse files Browse the repository at this point in the history
  • Loading branch information
phynet committed Sep 13, 2017
1 parent 82bff9c commit 3d3d905
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion android-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function parseWithRegex(data){
}

function regexCardinalVariables(data){
var regex = /\**\d+\w/g;
var regex = /\*\*\d+\w/g;
var numberWithAsterix = data.match(regex);
//return **1s
if (numberWithAsterix){
Expand Down
72 changes: 63 additions & 9 deletions ios-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function parseWildcardsForiOS(data){
function parseWithRegex(data){
data = regexEscapingSymbol(data);
data = regexEscapingSymbolPercentage(data);
data = regexWithCardinalVariables(data);
data = regexCardinalVariables(data);
data = regexEscapingDoubleQuotation(data);
return data;
}
Expand All @@ -126,22 +126,76 @@ function regexWithCardinalVariables(data){
var regex = /\**\d+\w/g;
var numberWithAsterix = data.match(regex);
//return **1s
if (numberWithAsterix){
//var deleteAsterix = /\d+/g;
//var number = String(numberWithAsterix).match(deleteAsterix);
var number = getNumber(data);
var letter = getLetter(data);
console.log("number ios" + number + "letter " + letter);

var newLetter = typeVariable(letter);
data = data.replace("**"+number+letter+"**","%"+number+"$"+newLetter);
}
return data;
}

function regexCardinalVariables(data){
var regex = /\*\*\d+\w/g;
var numberWithAsterix = data.match(regex);
//return **1s

console.log("numberWithAsterix " + numberWithAsterix);

if (numberWithAsterix){

var number = [getNumber(data)];
var letter = [getLetter(data)];
var length = 0;

console.log("number ios " + number + " Letter " + letter);

number = number.toString().split(",").map(Number);
letter = letter.toString().split(",").map(String);

length = number.length;

for (var indx = 0; indx <= length; indx++){
var ast = /\*\*/g;
var argRegEx = new RegExp(number[indx] + letter[indx], 'g');
var newLetter = typeVariable(letter[indx]);

console.log("newLetter " + newLetter);

var replc = "%"+number[indx]+"$"+newLetter;

var rest = data.replace(argRegEx, replc);
data = rest.replace(ast, "");
console.log("final data replacing wildcards ios" + data);
}
}
return data;
}

function getNumber(data){
var regex = /\**\d+\w/g;
var number = "";
var numberWithAsterix = data.match(regex);
if (numberWithAsterix){
var deleteAsterix = /\d+/g;
var number = String(numberWithAsterix).match(deleteAsterix);
//return 1 from **1s
number = String(numberWithAsterix).match(deleteAsterix);
}
return number
}

function getLetter(data){
var regexLetter = /\**\d\w/g;
var letterWithAsterix = data.match(regexLetter);
//return **1s for example
var deleteAsterixLetter = /([a-z])/g;
var letter = String(letterWithAsterix).match(deleteAsterixLetter);
//return s/d/f/ld from **1s
var newLetter = typeVariable(letter);
data = data.replace("**"+number+letter+"**","%"+number+"$"+newLetter);
}
return data;
return String(letterWithAsterix).match(deleteAsterixLetter);
}


function regexEscapingSymbol(data){
//delete symbolic scaping %% that is needed in android but not in iOS
var regexSymbolic = /\%\%/g;
Expand Down

0 comments on commit 3d3d905

Please sign in to comment.