1 package antlr;
2
3 * <b>SOFTWARE RIGHTS</b>
5 * <p>
6 * ANTLR 2.5.0 MageLang Institute, 1998
7 * <p>
8 * We reserve no legal rights to the ANTLR--it is fully in the
9 * public domain. An individual or company may do whatever
10 * they wish with source code distributed with ANTLR or the
11 * code generated by ANTLR, including the incorporation of
12 * ANTLR, or its output, into commerical software.
13 * <p>
14 * We encourage users to develop software with ANTLR. However,
15 * we do ask that credit is given to us for developing
16 * ANTLR. By "credit", we mean that if you use ANTLR or
17 * incorporate any source code into one of your programs
18 * (commercial product, research project, or otherwise) that
19 * you acknowledge this fact somewhere in the documentation,
20 * research report, etc... If you like ANTLR and have
21 * developed a nice tool with the output, please mention that
22 * you developed it using ANTLR. In addition, we ask that the
23 * headers remain intact in our source code. As long as these
24 * guidelines are kept, we expect to continue enhancing this
25 * system and expect to make other tools available as they are
26 * completed.
27 * <p>
28 * The ANTLR gang:
29 * @version ANTLR 2.5.0 MageLang Institute, 1998
30 * @author Terence Parr, <a href=http://www.MageLang.com>MageLang Institute</a>
31 * @author <br>John Lilley, <a href=http://www.Empathy.com>Empathy Software</a>
32 */
33
36 public class ANTLRStringBuffer {
37 protected char[] buffer = new char[8];
38 protected int length = 0;
40
41 public ANTLRStringBuffer() {}
42 public final void append(char c) {
43 if (length >= buffer.length) {
46 int newSize = buffer.length;
48 while (length >= newSize) {
49 newSize *= 2;
50 }
51 char[] newBuffer = new char[newSize];
53 for (int i = 0; i < length; i++) {
54 newBuffer[i] = buffer[i];
55 }
56 buffer = newBuffer;
57 }
58 buffer[length] = c;
59 length++;
60 }
61 public final void append(String s) {
62 for (int i = 0; i < s.length(); i++) {
63 append(s.charAt(i));
64 }
65 }
66 public final char charAt(int index) { return buffer[index]; }
67 final public char[] getBuffer() { return buffer; }
68 public final int length() { return length; }
69 public final void setCharAt(int index, char ch) { buffer[index] = ch; }
70 public final void setLength(int newLength) {
71 if (newLength < length) {
72 length = newLength;
73 } else {
74 while (newLength > length) {
75 append('\0');
76 }
77 }
78 }
79 public final String toString() {
80 return new String(buffer, 0, length);
81 }
82 }
83