JAL-1807 test
[jalviewjs.git] / bin / com / stevesoft / pat / RegexTokenizer.js
1 Clazz.declarePackage ("com.stevesoft.pat");
2 Clazz.load (["java.util.Enumeration", "$.Vector"], "com.stevesoft.pat.RegexTokenizer", ["com.stevesoft.pat.Regex"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.toParse = null;
5 this.r = null;
6 this.count = 0;
7 this.v = null;
8 this.vi = null;
9 this.pos = 0;
10 this.offset = 1;
11 Clazz.instantialize (this, arguments);
12 }, com.stevesoft.pat, "RegexTokenizer", null, java.util.Enumeration);
13 Clazz.prepareFields (c$, function () {
14 this.v =  new java.util.Vector ();
15 this.vi =  new java.util.Vector ();
16 });
17 Clazz.defineMethod (c$, "getMore", 
18 function () {
19 var s = this.r.right ();
20 if (this.r.searchFrom (this.toParse, this.pos)) {
21 this.v.addElement (this.r.left ().substring (this.pos));
22 this.vi.addElement ( new Integer (this.r.matchFrom () + this.r.charsMatched ()));
23 for (var i = 0; i < this.r.numSubs (); i++) {
24 if (this.r.substring () != null) {
25 this.v.addElement (this.r.substringI (i + this.offset));
26 this.vi.addElement ( new Integer (this.r.matchFromI (i + this.offset) + this.r.charsMatchedI (i + this.offset)));
27 }}
28 this.pos = this.r.matchFrom () + this.r.charsMatched ();
29 } else if (s != null) {
30 this.v.addElement (s);
31 }});
32 Clazz.makeConstructor (c$, 
33 function (txt, ptrn) {
34 this.toParse = txt;
35 this.r =  new com.stevesoft.pat.Regex (ptrn, "");
36 this.offset = com.stevesoft.pat.Regex.BackRefOffset;
37 this.getMore ();
38 }, "~S,~S");
39 Clazz.makeConstructor (c$, 
40 function (txt, r) {
41 this.toParse = txt;
42 this.r = r;
43 this.offset = com.stevesoft.pat.Regex.BackRefOffset;
44 this.getMore ();
45 }, "~S,com.stevesoft.pat.Regex");
46 Clazz.overrideMethod (c$, "nextElement", 
47 function () {
48 if (this.count >= this.v.size ()) {
49 this.getMore ();
50 }return this.v.elementAt (this.count++);
51 });
52 Clazz.defineMethod (c$, "nextToken", 
53 function () {
54 return this.nextElement ();
55 });
56 Clazz.defineMethod (c$, "nextToken", 
57 function (newpat) {
58 try {
59 this.r.compile (newpat);
60 } catch (r_) {
61 if (Clazz.exceptionOf (r_, com.stevesoft.pat.RegSyntax)) {
62 } else {
63 throw r_;
64 }
65 }
66 return this.nextToken (this.r);
67 }, "~S");
68 Clazz.defineMethod (c$, "nextToken", 
69 function (nr) {
70 this.r = nr;
71 if (this.vi.size () > this.count) {
72 this.pos = (this.vi.elementAt (this.count)).intValue ();
73 this.v.setSize (this.count);
74 this.vi.setSize (this.count);
75 }this.getMore ();
76 return this.nextToken ();
77 }, "com.stevesoft.pat.Regex");
78 Clazz.overrideMethod (c$, "hasMoreElements", 
79 function () {
80 if (this.count >= this.v.size ()) {
81 this.getMore ();
82 }return this.count < this.v.size ();
83 });
84 Clazz.defineMethod (c$, "hasMoreTokens", 
85 function () {
86 return this.hasMoreElements ();
87 });
88 Clazz.defineMethod (c$, "countTokens", 
89 function () {
90 var _count = this.count;
91 while (this.hasMoreTokens ()) {
92 this.nextToken ();
93 }
94 this.count = _count;
95 return this.v.size () - this.count;
96 });
97 Clazz.defineMethod (c$, "allTokens", 
98 function () {
99 this.countTokens ();
100 var ret =  new Array (this.v.size ());
101 this.v.copyInto (ret);
102 return ret;
103 });
104 });