Exemple #1
0
  /**
   * Evaluates the replace function.
   *
   * @param val input value
   * @param ctx query context
   * @return function result
   * @throws QueryException query exception
   */
  private Item replace(final byte[] val, final QueryContext ctx) throws QueryException {
    final byte[] rep = checkStr(expr[2], ctx);
    for (int i = 0; i < rep.length; ++i) {
      if (rep[i] == '\\') {
        if (i + 1 == rep.length || rep[i + 1] != '\\' && rep[i + 1] != '$') FUNREPBS.thrw(info);
        ++i;
      }
      if (rep[i] == '$'
          && (i == 0 || rep[i - 1] != '\\')
          && (i + 1 == rep.length || !digit(rep[i + 1]))) FUNREPDOL.thrw(info);
    }

    final Pattern p = pattern(expr[1], expr.length == 4 ? expr[3] : null, ctx);
    if (p.pattern().isEmpty()) REGROUP.thrw(info);

    String r = string(rep);
    if ((p.flags() & Pattern.LITERAL) != 0) {
      r = SLASH.matcher(BSLASH.matcher(r).replaceAll("\\\\\\\\")).replaceAll("\\\\\\$");
    }

    try {
      return Str.get(p.matcher(string(val)).replaceAll(r));
    } catch (final Exception ex) {
      if (ex.getMessage().contains("No group")) REGROUP.thrw(info);
      throw REGPAT.thrw(info, ex);
    }
  }
Exemple #2
0
 /**
  * Returns a database function for the first node in a node set.
  *
  * @param n node set
  * @param i offset
  * @return function string
  */
 static String openPre(final Nodes n, final int i) {
   return Function._DB_OPEN_PRE.get(Str.get(n.data.meta.name), Int.get(n.pres[i])).toString();
 }
Exemple #3
0
 /**
  * Extracts text entries.
  *
  * @param ctx query context
  * @return text entry
  * @throws QueryException query exception
  */
 private ValueBuilder extractText(final QueryContext ctx) throws QueryException {
   final String enc = encoding(2, ARCH_ENCODING, ctx);
   final ValueBuilder vb = new ValueBuilder();
   for (final byte[] b : extract(ctx)) vb.add(Str.get(encode(b, enc)));
   return vb;
 }