Esempio n. 1
0
 @Subroutine("substring-no-properties")
 public static LispString substringNoProperties(
     LispString string, @Optional LispObject from, LispObject to) {
   int length = string.size();
   int start = Predicate.isNil(from) ? 0 : processBound(getInt(from), length);
   int end = Predicate.isNil(to) ? length : processBound(getInt(to), length);
   try {
     return string.substring(start, end, false);
   } catch (IndexOutOfBoundsException e) {
     throw new ArgumentOutOfRange(string, start, end);
   }
 }
Esempio n. 2
0
 @Subroutine("substring")
 public static LispObject substring(
     StringOrVector stringOrVector, LispInteger from, @Optional LispObject to) {
   int length = stringOrVector.size();
   int start = processBound(from, length);
   int end = Predicate.isNil(to) ? length : processBound(getInt(to), length);
   try {
     return stringOrVector.substring(start, end);
   } catch (IndexOutOfBoundsException e) {
     throw new ArgumentOutOfRange(stringOrVector, start, end);
   }
 }
Esempio n. 3
0
 private static int getInt(@Nullable LispObject intOrNil, int defaultValue) {
   if (Predicate.isNil(intOrNil)) return defaultValue;
   if (!(intOrNil instanceof LispInteger))
     throw new WrongTypeArgumentException("integerp", intOrNil);
   return ((LispInteger) intOrNil).getData();
 }