Exemple #1
1
 @Override
 public String getHeaderField(final String field) {
   final List<String> values = headers.get(field);
   final StringBuilder sb = new StringBuilder();
   for (final String v : values) sb.append(v).append(';');
   return sb.substring(0, sb.length() - 1);
 }
Exemple #2
0
 /**
  * Parses and returns a number.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return name
  * @throws QueryException query exception
  */
 private String number(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   if (parser.curr() == '-') sb.append(parser.consume());
   while (digit(parser.curr())) sb.append(parser.consume());
   return finish(eoc() || ws(parser.curr()) ? sb : null, cmd);
 }
Exemple #3
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder(COPY + ' ');
   for (final Let t : copies)
     sb.append(t.var).append(' ').append(ASSIGN).append(' ').append(t.expr).append(' ');
   return sb.append(MODIFY + ' ' + expr[0] + ' ' + RETURN + ' ' + expr[1]).toString();
 }
Exemple #4
0
 /**
  * Parses and returns a command. A command is limited to letters.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return name
  * @throws QueryException query exception
  */
 private String command(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (!eoc() && !ws(parser.curr())) {
     sb.append(parser.consume());
   }
   return finish(sb, cmd);
 }
Exemple #5
0
 /**
  * Returns a string representation of all found arguments.
  *
  * @param args array with arguments
  * @return string representation
  */
 static String foundArgs(final Value[] args) {
   // compose found arguments
   final StringBuilder sb = new StringBuilder();
   for (final Value v : args) {
     if (sb.length() != 0) sb.append(", ");
     sb.append(v instanceof Jav ? Util.className(((Jav) v).toJava()) : v.seqType());
   }
   return sb.toString();
 }
Exemple #6
0
 /**
  * Returns an extended error message.
  *
  * @param err error message
  * @return result of check
  */
 private boolean extError(final String err) {
   // will only be evaluated when an error has occurred
   final StringBuilder sb = new StringBuilder();
   if (options.get(MainOptions.QUERYINFO)) {
     sb.append(info()).append(qp.info()).append(NL).append(ERROR).append(COL).append(NL);
   }
   sb.append(err);
   return error(sb.toString());
 }
Exemple #7
0
 /**
  * Parses and returns a glob expression, which extends {@link #name(Cmd)} function with asterisks,
  * question marks and commands.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return glob expression
  * @throws QueryException query exception
  */
 private String glob(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (true) {
     final char ch = parser.curr();
     if (!Databases.validChar(ch) && ch != '*' && ch != '?' && ch != ',') {
       return finish(eoc() || ws(ch) ? sb : null, cmd);
     }
     sb.append(parser.consume());
   }
 }
Exemple #8
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   final int pl = post.length;
   for (int p = 0; p < pl; p++) {
     sb.append(LET).append(" (: post-group :) ").append(post[p]);
     sb.append(' ').append(ASSIGN).append(' ').append(preExpr[p]).append(' ');
   }
   sb.append(GROUP).append(' ').append(BY);
   final int sl = specs.length;
   for (int s = 0; s < sl; s++) sb.append(s == 0 ? " " : SEP).append(specs[s]);
   return sb.toString();
 }
Exemple #9
0
 /**
  * Parses and returns a string, delimited by a semicolon or, optionally, a space. Quotes can be
  * used to include spaces.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @param space stop when encountering space
  * @return string
  * @throws QueryException query exception
  */
 private String string(final Cmd cmd, final boolean space) throws QueryException {
   final StringBuilder sb = new StringBuilder();
   consumeWS();
   boolean q = false;
   while (parser.more()) {
     final char c = parser.curr();
     if (!q && ((space ? c <= ' ' : c < ' ') || eoc())) break;
     if (c == '"') q ^= true;
     else sb.append(c);
     parser.consume();
   }
   return finish(sb, cmd);
 }
Exemple #10
0
 /**
  * Parses and returns the remaining string. Quotes at the beginning and end of the argument will
  * be stripped.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return remaining string
  * @throws QueryException query exception
  */
 private String remaining(final Cmd cmd) throws QueryException {
   if (single) {
     final StringBuilder sb = new StringBuilder();
     consumeWS();
     while (parser.more()) sb.append(parser.consume());
     String arg = finish(sb, cmd);
     if (arg != null) {
       // chop quotes; substrings are faster than replaces...
       if (arg.startsWith("\"")) arg = arg.substring(1);
       if (arg.endsWith("\"")) arg = arg.substring(0, arg.length() - 1);
     }
     return arg;
   }
   return string(cmd, false);
 }
Exemple #11
0
 /**
  * Parses and returns an xquery expression.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return path
  * @throws QueryException query exception
  */
 private String xquery(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   if (!eoc()) {
     final QueryContext qc = new QueryContext(ctx);
     try {
       final QueryParser p = new QueryParser(parser.input, null, qc, null);
       p.pos = parser.pos;
       p.parseMain();
       sb.append(parser.input.substring(parser.pos, p.pos));
       parser.pos = p.pos;
     } finally {
       qc.close();
     }
   }
   return finish(sb, cmd);
 }
Exemple #12
0
 @Override
 StringBuilder toString(final StringBuilder sb, final String ind) {
   final int s = Integer.bitCount(used);
   for (int i = 0, j = 0; i < s; i++, j++) {
     while ((used & 1 << j) == 0) j++;
     final int e = i == s - 1 ? 2 : 0;
     sb.append(ind).append(ENDS[e]).append(String.format("%x", j)).append('\n');
     kids[j].toString(sb, ind + ENDS[e + 1]);
   }
   return sb;
 }
Exemple #13
0
 @Override
 public final String toString() {
   final StringBuilder sb = new StringBuilder();
   if (root != null) sb.append(root);
   for (final Expr s : steps) {
     if (sb.length() != 0) sb.append(s instanceof Bang ? " ! " : "/");
     if (s instanceof Step) sb.append(s);
     else sb.append(s);
   }
   return sb.toString();
 }
Exemple #14
0
 /**
  * Parses and returns a name. A name may contain letters, numbers and any of the special
  * characters <code>!#$%&'()+-=@[]^_`{}~</code>.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return name
  * @throws QueryException query exception
  */
 private String name(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (Databases.validChar(parser.curr())) sb.append(parser.consume());
   return finish(eoc() || ws(parser.curr()) ? sb : null, cmd);
 }
Exemple #15
0
 /**
  * Prints the array with the specified separator.
  *
  * @param sep separator
  * @return string representation
  */
 final String toString(final Object sep) {
   final StringBuilder sb = new StringBuilder();
   final int es = exprs.length;
   for (int e = 0; e < es; e++) sb.append(e == 0 ? "" : sep.toString()).append(exprs[e]);
   return sb.toString();
 }
Exemple #16
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   final boolean str = query instanceof AStr;
   if (!str) sb.append("{ ");
   sb.append(query);
   if (!str) sb.append(" }");
   switch (mode) {
     case ALL:
       sb.append(' ' + ALL);
       break;
     case ALL_WORDS:
       sb.append(' ' + ALL + ' ' + WORDS);
       break;
     case ANY_WORD:
       sb.append(' ' + ANY + ' ' + WORD);
       break;
     case PHRASE:
       sb.append(' ' + PHRASE);
       break;
     default:
   }
   if (occ != null) sb.append(OCCURS + ' ' + occ[0] + ' ' + TO + ' ' + occ[1] + ' ' + TIMES);
   if (ftt != null) sb.append(ftt.opt);
   return sb.toString();
 }
Exemple #17
0
 /**
  * Parses and returns a string result.
  *
  * @param input input string or {@code null} if invalid
  * @param cmd referring command; if specified, the result must not be empty
  * @return string result or {@code null}
  * @throws QueryException query exception
  */
 private String finish(final StringBuilder input, final Cmd cmd) throws QueryException {
   if (input != null && input.length() != 0) return input.toString();
   if (cmd != null) throw help(null, cmd);
   return null;
 }
Exemple #18
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder("try { " + expr + " }");
   for (final Catch c : catches) sb.append(' ').append(c);
   return sb.toString();
 }
Exemple #19
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   for (final Expr e : preds) sb.append('[').append(e).append(']');
   return sb.toString();
 }
Exemple #20
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   for (final UserFunc f : funcs) sb.append(f.toString());
   return sb.toString();
 }