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(value = "string-match")
 public static LispObject stringMatch(
     Environment environment, LispString regexp, LispString string, @Optional LispInteger start) {
   int from = 0;
   if (start != null) {
     from = start.getData();
     if (from < 0 || from >= string.size())
       throw new ArgumentOutOfRange(string.toString(), start.toString());
   }
   LispSymbol s = environment.find("case-fold-search");
   int r =
       string.match(
           environment, regexp, from, (s != null && !s.getValue().equals(LispSymbol.ourNil)));
   if (r == -1) return LispSymbol.ourNil;
   return new LispInteger(r);
 }
Esempio n. 3
0
 @Subroutine("read-from-string")
 public static LispList readFromString(
     LispString string,
     @Optional @Nullable LispObject start,
     @Optional @Nullable LispObject finish) {
   int begin = getInt(start, 0);
   int end = getInt(finish, string.size());
   try {
     String code = string.getData().substring(begin, end);
     ForwardParser forwardParser = new ForwardParser();
     LispObject read = Core.thisOrNil(forwardParser.parseLine(code));
     return LispList.cons(read, new LispInteger(begin + forwardParser.getCurrentIndex()));
   } catch (StringIndexOutOfBoundsException e) {
     throw new ArgumentOutOfRange(string, begin, end);
   }
 }