source: branches/1.1.x/src/org/armedbear/lisp/CaseFrobStream.java

Last change on this file was 13440, checked in by ehuelsmann, 13 years ago

Rename writeToString() to printObject() since that's what it's being used for.
Additionally, create princToString() for use in error messages, making the

required replacement where appropriate.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1/*
2 * CaseFrobStream.java
3 *
4 * Copyright (C) 2004 Peter Graves
5 * $Id: CaseFrobStream.java 13440 2011-08-05 21:25:10Z ehuelsmann $
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 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36import static org.armedbear.lisp.Lisp.*;
37
38public abstract class CaseFrobStream extends Stream
39{
40    protected final Stream target;
41
42    protected CaseFrobStream(Stream target)
43
44    {
45        super(Symbol.CASE_FROB_STREAM);
46        Debug.assertTrue(target.isCharacterOutputStream());
47        this.target = target;
48    }
49
50    @Override
51    public LispObject getElementType()
52    {
53        return target.getElementType();
54    }
55
56    @Override
57    public LispObject typeOf()
58    {
59        return Symbol.CASE_FROB_STREAM;
60    }
61
62    @Override
63    public LispObject classOf()
64    {
65        return BuiltInClass.CASE_FROB_STREAM;
66    }
67
68    @Override
69    public LispObject typep(LispObject type)
70    {
71        if (type == Symbol.CASE_FROB_STREAM)
72            return T;
73        if (type == BuiltInClass.CASE_FROB_STREAM)
74            return T;
75        return super.typep(type);
76    }
77
78    @Override
79    public boolean isInputStream()
80    {
81        return false;
82    }
83
84    @Override
85    public boolean isOutputStream()
86    {
87        return true;
88    }
89
90    @Override
91    public boolean isCharacterInputStream()
92    {
93        return false;
94    }
95
96    @Override
97    public boolean isBinaryInputStream()
98    {
99        return false;
100    }
101
102    @Override
103    public boolean isCharacterOutputStream()
104    {
105        return true;
106    }
107
108    @Override
109    public boolean isBinaryOutputStream()
110    {
111        return false;
112    }
113
114    @Override
115    public int getCharPos()
116    {
117        return target.getCharPos();
118    }
119
120    @Override
121    public void setCharPos(int n)
122    {
123        target.setCharPos(n);
124    }
125
126    // Returns -1 at end of file.
127    @Override
128    protected int _readChar()
129    {
130        notSupported();
131        // Not reached.
132        return -1;
133    }
134
135    @Override
136    protected void _unreadChar(int n)
137    {
138        notSupported();
139    }
140
141    @Override
142    protected boolean _charReady()
143    {
144        notSupported();
145        // Not reached.
146        return false;
147    }
148
149    @Override
150    public void _writeChars(char[] chars, int start, int end)
151
152    {
153        _writeString(new String(chars, start, end));
154    }
155
156    // Reads an 8-bit byte.
157    @Override
158    public int _readByte()
159    {
160        notSupported();
161        // Not reached.
162        return -1;
163    }
164
165    // Writes an 8-bit byte.
166    @Override
167    public void _writeByte(int n)
168    {
169        notSupported();
170    }
171
172    @Override
173    public void _finishOutput()
174    {
175        target._finishOutput();
176    }
177
178    @Override
179    public void _clearInput()
180    {
181        notSupported();
182    }
183
184    @Override
185    public LispObject close(LispObject abort)
186    {
187        setOpen(false);
188        return T;
189    }
190
191    @Override
192    public LispObject listen()
193    {
194        notSupported();
195        // Not reached.
196        return NIL;
197    }
198
199    @Override
200    public LispObject terpri()
201    {
202        return target.terpri();
203    }
204
205    @Override
206    public LispObject freshLine()
207    {
208        return target.freshLine();
209    }
210
211    @Override
212    public String printObject()
213    {
214        return unreadableString("CASE-FROB-STREAM");
215    }
216
217    private void notSupported()
218    {
219        error(new TypeError("Operation is not supported for streams of type CASE-FROB-STREAM."));
220    }
221
222    // ### make-case-frob-stream target => case-frob-stream
223    private static final Primitive MAKE_CASE_FROB_STREAM =
224        new Primitive("make-case-frob-stream", PACKAGE_SYS, false, "target kind")
225    {
226        @Override
227        public LispObject execute(LispObject first, LispObject second)
228
229        {
230            Stream target = checkCharacterOutputStream(first);
231            if (second == Keyword.UPCASE)
232                return new UpcaseStream(target);
233            if (second == Keyword.DOWNCASE)
234                return new DowncaseStream(target);
235            if (second == Keyword.CAPITALIZE)
236                return new CapitalizeStream(target);
237            if (second == Keyword.CAPITALIZE_FIRST)
238                return new CapitalizeFirstStream(target);
239            return error(new TypeError(
240                "Kind must be :UPCASE, :DOWNCASE, :CAPITALIZE or :CAPITALIZE-FIRST."));
241        }
242    };
243}
Note: See TracBrowser for help on using the repository browser.