01: /*
02: * AbstractString.java
03: *
04: * Copyright (C) 2004 Peter Graves
05: * $Id: AbstractString.java,v 1.6 2004/08/15 10:57:33 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * 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: public LispObject typep(LispObject type) throws ConditionThrowable {
26: if (type instanceof Symbol) {
27: if (type == Symbol.STRING)
28: return T;
29: if (type == Symbol.BASE_STRING)
30: return T;
31: }
32: if (type == BuiltInClass.STRING)
33: return T;
34: return super .typep(type);
35: }
36:
37: public final LispObject STRINGP() {
38: return T;
39: }
40:
41: public final boolean stringp() {
42: return true;
43: }
44:
45: public LispObject getElementType() {
46: return Symbol.CHARACTER;
47: }
48:
49: public final boolean isSimpleVector() {
50: return false;
51: }
52:
53: public final LispObject STRING() {
54: return this ;
55: }
56:
57: public abstract void fill(char c) throws ConditionThrowable;
58:
59: public abstract char getChar(int index) throws ConditionThrowable;
60:
61: public abstract void setChar(int index, char c)
62: throws ConditionThrowable;
63:
64: public final String writeToString(int beginIndex, int endIndex)
65: throws ConditionThrowable {
66: if (beginIndex < 0)
67: beginIndex = 0;
68: final int limit;
69: limit = length();
70: if (endIndex > limit)
71: endIndex = limit;
72: if (_PRINT_ESCAPE_.symbolValue() != NIL
73: || _PRINT_READABLY_.symbolValue() != NIL) {
74: StringBuffer sb = new StringBuffer();
75: sb.append('"');
76: for (int i = beginIndex; i < endIndex; i++) {
77: char c = getChar(i);
78: if (c == '\"' || c == '\\')
79: sb.append('\\');
80: sb.append(c);
81: }
82: sb.append('"');
83: return sb.toString();
84: } else
85: return getStringValue().substring(beginIndex, endIndex);
86: }
87:
88: public String writeToString() throws ConditionThrowable {
89: return writeToString(0, length());
90: }
91: }
|