Example #1
0
    public Value matchPositions(Value str) {
      PatternMatcher matcher = getMatcher();

      // Do the matching
      PatternMatcherInput jStr = new PatternMatcherInput(string(str));
      Pair result = null;
      Pair prev = null;
      boolean found = false;

      while (matcher.contains(jStr, pattern)) {
        found = true;

        MatchResult matchResult = matcher.getMatch();

        for (int i = 0, length = matchResult.groups(); i < length; i++) {
          Pair m =
              new Pair(
                  Quantity.valueOf(matchResult.beginOffset(i)),
                  Quantity.valueOf(matchResult.endOffset(i)));
          Pair elem = new Pair(m, EMPTYLIST);
          if (result == null) result = prev = elem;
          else {
            prev.setCdr(elem);
            prev = elem;
          }
        }
      }

      if (!found) return FALSE;
      else return result;
    }
 public int read(char[] buffer, int offset, int length) throws IOException {
   return Util.num(
           IOUtils.bridge(
               readString,
               new Value[] {
                 getHost(),
                 new SchemeString(buffer),
                 Quantity.valueOf(offset),
                 Quantity.valueOf(length)
               }))
       .intValue();
 }
Example #3
0
 public Value apply(Value v1) throws ContinuationException {
   switch (id) {
     case DIRECTORYQ:
       return SchemeBoolean.get(fileHandle(v1).isDirectory());
     case FILEQ:
       return SchemeBoolean.get(fileHandle(v1).isFile());
     case HIDDENQ:
       return SchemeBoolean.get(fileHandle(v1).isHidden());
     case READABLE:
       return SchemeBoolean.get(fileHandle(v1).canRead());
     case WRITEABLE:
       return SchemeBoolean.get(fileHandle(v1).canWrite());
     case DIRLIST:
       Pair p = EMPTYLIST;
       String[] contents = fileHandle(v1).list();
       if (contents == null)
         throwPrimException(liMessage(IO.IOB, "nosuchdirectory", SchemeString.asString(v1)));
       for (int i = contents.length - 1; i >= 0; i--)
         p = new Pair(new SchemeString(contents[i]), p);
       return p;
     case LENGTH:
       return Quantity.valueOf(fileHandle(v1).length());
     case LASTMODIFIED:
       return Quantity.valueOf(fileHandle(v1).lastModified());
     case GETPARENTURL:
       try {
         return new SchemeString(fileHandle(v1).getParentFile().toURI().toURL().toString());
       } catch (MalformedURLException m) {
         m.printStackTrace();
       }
       break;
     default:
       throwArgSizeException();
   }
   return VOID;
 }