Exemplo n.º 1
0
  /**
   * Searches a string in a file.
   *
   * @param path file path
   * @param search codepoints of search string
   * @return success flag
   */
  private static boolean filterContent(final String path, final int[] search) {
    final int cl = search.length;
    if (cl == 0) return true;

    try (final TextInput ti = new TextInput(new IOFile(path))) {
      final IntList il = new IntList(cl - 1);
      int c = 0;
      while (true) {
        if (!il.isEmpty()) {
          if (il.remove(0) == search[c++]) continue;
          c = 0;
        }
        while (true) {
          final int cp = ti.read();
          if (cp == -1 || !XMLToken.valid(cp)) return false;
          final int lc = Token.lc(cp);
          if (c > 0) il.add(lc);
          if (lc == search[c]) {
            if (++c == cl) return true;
          } else {
            c = 0;
            break;
          }
        }
      }
    } catch (final IOException ex) {
      // file may not be accessible
      Util.debug(ex);
      return false;
    }
  }
Exemplo n.º 2
0
  /**
   * Refreshes the view after a file has been saved.
   *
   * @param root root directory
   * @param ctx database context
   * @throws InterruptedException interruption
   */
  void parse(final IOFile root, final Context ctx) throws InterruptedException {
    final long id = ++parseId;
    final HashSet<String> parsed = new HashSet<>();
    final TreeMap<String, InputInfo> errs = new TreeMap<>();

    // collect files to be parsed
    final ProjectCache pc = cache(root);
    final StringList mods = new StringList(), lmods = new StringList();
    for (final String path : pc) {
      final IOFile file = new IOFile(path);
      if (file.hasSuffix(IO.XQSUFFIXES)) (file.hasSuffix(IO.XQMSUFFIX) ? lmods : mods).add(path);
    }
    mods.add(lmods);

    // parse modules
    for (final String path : mods) {
      if (id != parseId) throw new InterruptedException();
      if (parsed.contains(path)) continue;

      final IOFile file = new IOFile(path);
      try (final TextInput ti = new TextInput(file)) {
        // parse query
        try (final QueryContext qc = new QueryContext(ctx)) {
          final String input = ti.cache().toString();
          final boolean lib = QueryProcessor.isLibrary(input);
          qc.parse(input, lib, path, null);
          // parsing was successful: remember path
          parsed.add(path);
          for (final byte[] mod : qc.modParsed) parsed.add(Token.string(mod));
        } catch (final QueryException ex) {
          // parsing failed: remember path
          final InputInfo ii = ex.info();
          errs.put(path, ii);
          parsed.add(ii.path());
        }
      } catch (final IOException ex) {
        // file may not be accessible
        Util.debug(ex);
      }
    }
    errors = errs;
  }