Skip to content
Snippets Groups Projects
Commit d59a71cc authored by Millicent Billette's avatar Millicent Billette
Browse files

FEAT: advensed dictionaryBuilder finished exept escape chr

parent cddd1d65
No related branches found
No related tags found
No related merge requests found
...@@ -46,20 +46,12 @@ function regLikeVariants(theString,allStrings) { ...@@ -46,20 +46,12 @@ function regLikeVariants(theString,allStrings) {
return `(${res.join('|')})`; return `(${res.join('|')})`;
}; };
theString = theString.replace(/([^\)]){([^}]+)}/g,qtyApply); theString = theString.replace(/([^\)]){([^}]+)}/g,qtyApply);
theString = theString.replace(/^(.*)\(([^)]*)\)\{([^}]+)\}(.*)$/,(all,before,choices,qty,after)=> before+qtyApply('',`(${choices})`,qty)+after );
// handle (|) // handle (|)
let multiString = theString.replace(/^(.*)\(([^)]*)\)(.*)$/,(all,before,choices,after)=>choices.split('|').map(c=>{ let multiString = theString.replace(/^(.*)\(([^)]*)\)(.*)$/,(all,before,choices,after)=>choices.split('|').map(c=> before+c+after).join('=$##$=') ).split('=$##$=');
if(after.indexOf('{')!==0) return before+c+after;
else {
console.log(c);
const end = after.slice(1).split('}');
const qty = end.shift();
const afterQty = end.join('}');
return before+qtyApply('',c,qty)+afterQty;
}
}).join('=$##$=') ).split('=$##$=');
console.log(multiString); console.log(multiString);
multiString = [].concat(...multiString.map(str => (str.indexOf('(')!== -1)?regLikeVariants(str,allStrings):str)); multiString = [].concat(...multiString.map(str => (str.indexOf('(')!== -1)?regLikeVariants(str,allStrings):str));
return multiString; return dedup(multiString);
} }
...@@ -36,10 +36,10 @@ describe('dictionaryBuilder', () => { ...@@ -36,10 +36,10 @@ describe('dictionaryBuilder', () => {
expect(app.regLikeVariants("b{3,5}")).toEqual(["bbb","bbbb","bbbbb"]); expect(app.regLikeVariants("b{3,5}")).toEqual(["bbb","bbbb","bbbbb"]);
}); });
it('regLikeVariants handle (string){qty}', () => { it('regLikeVariants handle (string){qty}', () => {
expect(app.regLikeVariants("(toto|tata){0,2}")).toEqual(["","toto","tata","totototo","tototata","tatatoto","tatatata"]); expect(app.regLikeVariants("(toto|tata){0,2}")).toEqual(["","toto","totototo","tata","tatatoto","tototata","tatatata"]);
}); });
xit('regLikeVariants handle nested ([a-f]|<ref>){0,1}', () => { it('regLikeVariants handle nested ([a-f]|<ref>){0,1}', () => {
expect(app.regLikeVariants("autre mot")).toEqual(["autre mot","Autre Mot","AUTRE MOT"]); expect(app.regLikeVariants("([B-D]|<ref>){0,1}",["ref::plop"])).toEqual(["","B","plop","C","D"]);
}); });
xit('regLikeVariants handle plop:\\:', () => { xit('regLikeVariants handle plop:\\:', () => {
expect(app.regLikeVariants("autre mot")).toEqual(["autre mot","Autre Mot","AUTRE MOT"]); expect(app.regLikeVariants("autre mot")).toEqual(["autre mot","Autre Mot","AUTRE MOT"]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment