aboutsummaryrefslogtreecommitdiff
path: root/src/common.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.js')
-rw-r--r--src/common.js65
1 files changed, 64 insertions, 1 deletions
diff --git a/src/common.js b/src/common.js
index f7d2cca..3c8fcb4 100644
--- a/src/common.js
+++ b/src/common.js
@@ -11,4 +11,67 @@ function appendHtml(el, str) {
}
-const rem_emp = function (e) {return e !== "";}; \ No newline at end of file
+const rem_emp = function (e) {return e !== "";};
+
+function indexs_of(inp,sel){
+ if(sel==''){
+ let fm = []
+ for(let n = 0; n<=inp.length;n++){
+ fm.push(n)
+ }
+ //console.log(fm)
+ return fm
+ }
+ let m = []
+ for(let i = inp.indexOf(sel);i>=0;i=inp.indexOf(sel,i+1)){
+ m.push(i)
+ }
+ return m
+}
+function hrx(inp,match){ //hgx for human (readable) regex, a more user friendly regex
+ //similar to the ones used in command lines
+ for(let x in match){
+ //console.log(match[x])
+ if(match[0]=='*'){
+ m = match.split("")
+ m.splice(0,1)
+ m = m.join("")
+ mm = m.split("*")[0]
+ //m = m.join("")
+
+ if(!inp.includes(mm))
+ return false
+
+ //let zz = inp.indexOf(m)
+ let ava = indexs_of(inp,mm)
+ //console.log(m)
+ for(let a of ava){
+ //console.log(a,m)
+ i = inp.split("")
+ i.splice(0,a)
+ i = i.join("")
+ let test = hrx(i,m)
+ if(test)
+ return true
+
+ }
+ return false
+ //match = m
+ //console.log(m,i)
+ } else {
+ //console.log(inp,match)
+ if(inp[0]==match[0]){
+ i = inp.split("")
+ ma = match.split("")
+ i.splice(0,1)
+ ma.splice(0,1)
+ inp=i.join("")
+ match=ma.join("")
+ } else {
+ return false
+ }
+ }
+ }
+ //console.log(inp,match)
+ return (inp==''&&''==match)
+} \ No newline at end of file