Browse files

extend nth, count and seq support to CharSequence

  • Loading branch information...
1 parent dc71e66 commit 109b015af4a0ca873412875b6e7705bec067640e @richhickey richhickey committed Mar 19, 2010
Showing with 11 additions and 11 deletions.
  1. +8 −8 src/jvm/clojure/lang/RT.java
  2. +3 −3 src/jvm/clojure/lang/StringSeq.java
View
16 src/jvm/clojure/lang/RT.java
@@ -467,8 +467,8 @@ else if(coll instanceof Iterable)
return IteratorSeq.create(((Iterable) coll).iterator());
else if(coll.getClass().isArray())
return ArraySeq.createFromObject(coll);
- else if(coll instanceof String)
- return StringSeq.create((String) coll);
+ else if(coll instanceof CharSequence)
+ return StringSeq.create((CharSequence) coll);
else if(coll instanceof Map)
return seq(((Map) coll).entrySet());
else {
@@ -508,8 +508,8 @@ else if(o instanceof IPersistentCollection) {
}
return i;
}
- else if(o instanceof String)
- return ((String) o).length();
+ else if(o instanceof CharSequence)
+ return ((CharSequence) o).length();
else if(o instanceof Collection)
return ((Collection) o).size();
else if(o instanceof Map)
@@ -715,8 +715,8 @@ static public Object nth(Object coll, int n){
return ((Indexed) coll).nth(n);
if(coll == null)
return null;
- else if(coll instanceof String)
- return Character.valueOf(((String) coll).charAt(n));
+ else if(coll instanceof CharSequence)
+ return Character.valueOf(((CharSequence) coll).charAt(n));
else if(coll.getClass().isArray())
return Reflector.prepRet(Array.get(coll, n));
else if(coll instanceof RandomAccess)
@@ -759,8 +759,8 @@ else if(coll == null)
else if(n < 0)
return notFound;
- else if(coll instanceof String) {
- String s = (String) coll;
+ else if(coll instanceof CharSequence) {
+ CharSequence s = (CharSequence) coll;
if(n < s.length())
return Character.valueOf(s.charAt(n));
return notFound;
View
6 src/jvm/clojure/lang/StringSeq.java
@@ -13,16 +13,16 @@
package clojure.lang;
public class StringSeq extends ASeq implements IndexedSeq{
-final String s;
+final CharSequence s;
final int i;
-static public StringSeq create(String s){
+static public StringSeq create(CharSequence s){
if(s.length() == 0)
return null;
return new StringSeq(null, s, 0);
}
-StringSeq(IPersistentMap meta, String s, int i){
+StringSeq(IPersistentMap meta, CharSequence s, int i){
super(meta);
this.s = s;
this.i = i;

0 comments on commit 109b015

Please sign in to comment.