KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > AbstractString


1 /*
2  * AbstractString.java
3  *
4  * Copyright (C) 2004 Peter Graves
5  * $Id: AbstractString.java,v 1.6 2004/08/15 10:57:33 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.lisp;
23
24 public abstract class AbstractString extends AbstractVector
25 {
26     public LispObject typep(LispObject type) throws ConditionThrowable
27     {
28         if (type instanceof Symbol) {
29             if (type == Symbol.STRING)
30                 return T;
31             if (type == Symbol.BASE_STRING)
32                 return T;
33         }
34         if (type == BuiltInClass.STRING)
35             return T;
36         return super.typep(type);
37     }
38
39     public final LispObject STRINGP()
40     {
41         return T;
42     }
43
44     public final boolean stringp()
45     {
46         return true;
47     }
48
49     public LispObject getElementType()
50     {
51         return Symbol.CHARACTER;
52     }
53
54     public final boolean isSimpleVector()
55     {
56         return false;
57     }
58
59     public final LispObject STRING()
60     {
61         return this;
62     }
63
64     public abstract void fill(char c) throws ConditionThrowable;
65
66     public abstract char getChar(int index) throws ConditionThrowable;
67
68     public abstract void setChar(int index, char c) throws ConditionThrowable;
69
70     public final String JavaDoc writeToString(int beginIndex, int endIndex)
71         throws ConditionThrowable
72     {
73         if (beginIndex < 0)
74             beginIndex = 0;
75         final int limit;
76         limit = length();
77         if (endIndex > limit)
78             endIndex = limit;
79         if (_PRINT_ESCAPE_.symbolValue() != NIL || _PRINT_READABLY_.symbolValue() != NIL) {
80             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
81             sb.append('"');
82             for (int i = beginIndex; i < endIndex; i++) {
83                 char c = getChar(i);
84                 if (c == '\"' || c == '\\')
85                     sb.append('\\');
86                 sb.append(c);
87             }
88             sb.append('"');
89             return sb.toString();
90         } else
91             return getStringValue().substring(beginIndex, endIndex);
92     }
93
94     public String JavaDoc writeToString() throws ConditionThrowable
95     {
96         return writeToString(0, length());
97     }
98 }
99
Popular Tags