JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / unused / com / stevesoft / pat / wrap / CharArrayWrap.java
1 //
2 // This software is now distributed according to
3 // the Lesser Gnu Public License.  Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
5 // the details.
6 //    -- Happy Computing!
7 //
8 package com.stevesoft.pat.wrap;
9
10 import com.stevesoft.pat.BasicStringBufferLike;
11 import com.stevesoft.pat.StringLike;
12
13 /**
14  * This provides a wrapper for a char array so that it can be searched by Regex.
15  */
16 public class CharArrayWrap implements StringLike
17 {
18   char[] ca;
19
20   public char[] getCharArray()
21   {
22     return ca;
23   }
24
25   public CharArrayWrap(char[] ca)
26   {
27     this.ca = ca;
28   }
29
30   public String toString()
31   {
32     return new String(ca);
33   }
34
35   public char charAt(int i)
36   {
37     return ca[i];
38   }
39
40   public int length()
41   {
42     return ca.length;
43   }
44
45   public String substring(int i1, int i2)
46   {
47     javajs.util.SB sb = new javajs.util.SB();
48     for (int i = i1; i < i2; i++)
49     {
50       sb.appendC(ca[i]);
51     }
52     return sb.toString();
53   }
54
55   public Object unwrap()
56   {
57     return ca;
58   }
59
60   public BasicStringBufferLike newStringBufferLike()
61   {
62     try {
63                         return (BasicStringBufferLike) Class.forName("com.stevesoft.pat.wrap.CharArrayBufferWrap").newInstance();
64                 } catch (Exception e) {
65                         return null;
66                 }
67   }
68
69   public int indexOf(char c)
70   {
71     for (int i = 0; i < ca.length; i++)
72     {
73       if (ca[i] == c)
74       {
75         return i;
76       }
77     }
78     return -1;
79   }
80 }