1 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 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 sb = new StringBuffer (); 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 writeToString() throws ConditionThrowable 95 { 96 return writeToString(0, length()); 97 } 98 } 99 | Popular Tags |