Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / com / stevesoft / pat / StrPos.js
1 Clazz.declarePackage ("com.stevesoft.pat");
2 Clazz.load (null, "com.stevesoft.pat.StrPos", ["com.stevesoft.pat.patInf", "$.patInt"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.s = null;
5 this.$pos = 0;
6 this.esc = '\\';
7 this.c = '\0';
8 this.dontMatch = false;
9 this.$eos = false;
10 Clazz.instantialize (this, arguments);
11 }, com.stevesoft.pat, "StrPos");
12 Clazz.defineMethod (c$, "pos", 
13 function () {
14 return this.$pos;
15 });
16 Clazz.defineMethod (c$, "thisChar", 
17 function () {
18 return this.c;
19 });
20 Clazz.defineMethod (c$, "eos", 
21 function () {
22 return this.$eos;
23 });
24 Clazz.makeConstructor (c$, 
25 function (sp) {
26 this.dup (sp);
27 }, "com.stevesoft.pat.StrPos");
28 Clazz.defineMethod (c$, "dup", 
29 function (sp) {
30 this.s = sp.s;
31 this.$pos = sp.$pos;
32 this.c = sp.c;
33 this.dontMatch = sp.dontMatch;
34 this.$eos = sp.$eos;
35 }, "com.stevesoft.pat.StrPos");
36 Clazz.makeConstructor (c$, 
37 function (s, pos) {
38 this.s = s;
39 this.$pos = pos - 1;
40 this.inc ();
41 }, "~S,~N");
42 Clazz.defineMethod (c$, "inc", 
43 function () {
44 this.$pos++;
45 if (this.$pos >= this.s.length) {
46 this.$eos = true;
47 return this;
48 }this.$eos = false;
49 this.c = this.s.charAt (this.$pos);
50 if (this.c == this.esc && this.$pos + 1 < this.s.length) {
51 this.$pos++;
52 this.c = this.s.charAt (this.$pos);
53 if (this.c != this.esc) {
54 this.dontMatch = true;
55 } else {
56 this.dontMatch = false;
57 }} else {
58 this.dontMatch = false;
59 }return this;
60 });
61 Clazz.defineMethod (c$, "match", 
62 function (ch) {
63 if (this.dontMatch || this.$eos) {
64 return false;
65 }return this.c == ch;
66 }, "~S");
67 Clazz.defineMethod (c$, "escMatch", 
68 function (ch) {
69 if (!this.dontMatch || this.$eos) {
70 return false;
71 }return this.c == ch;
72 }, "~S");
73 Clazz.defineMethod (c$, "escaped", 
74 function () {
75 return this.dontMatch;
76 });
77 Clazz.defineMethod (c$, "incMatch", 
78 function (st) {
79 var sp =  new com.stevesoft.pat.StrPos (this);
80 var i;
81 for (i = 0; i < st.length; i++) {
82 if (!sp.match (st.charAt (i))) {
83 return false;
84 }sp.inc ();
85 }
86 this.dup (sp);
87 return true;
88 }, "~S");
89 Clazz.defineMethod (c$, "getPatInt", 
90 function () {
91 if (this.incMatch ("inf")) {
92 return  new com.stevesoft.pat.patInf ();
93 }var i;
94 var cnt = 0;
95 var sp =  new com.stevesoft.pat.StrPos (this);
96 for (i = 0; !sp.$eos && sp.c >= '0' && sp.c <= '9'; i++) {
97 cnt = 10 * cnt + sp.c.charCodeAt (0) - 48;
98 sp.inc ();
99 }
100 if (i == 0) {
101 return null;
102 }this.dup (sp);
103 return  new com.stevesoft.pat.patInt (cnt);
104 });
105 Clazz.defineMethod (c$, "getString", 
106 function () {
107 return this.s;
108 });
109 });