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