/** * Returns a map with variable bindings. * * @param opts main options * @return bindings */ public static HashMap<String, String> bindings(final MainOptions opts) { final HashMap<String, String> bindings = new HashMap<>(); final String bind = opts.get(MainOptions.BINDINGS).trim(); final StringBuilder key = new StringBuilder(); final StringBuilder val = new StringBuilder(); boolean first = true; final int sl = bind.length(); for (int s = 0; s < sl; s++) { final char ch = bind.charAt(s); if (first) { if (ch == '=') { first = false; } else { key.append(ch); } } else { if (ch == ',') { if (s + 1 == sl || bind.charAt(s + 1) != ',') { bindings.put(key.toString().trim(), val.toString()); key.setLength(0); val.setLength(0); first = true; continue; } // literal commas are escaped by a second comma s++; } val.append(ch); } } if (key.length() != 0) bindings.put(key.toString().trim(), val.toString()); return bindings; }
/** * Removes comments from the specified string and returns the first characters of a query. * * @param qu query string * @param max maximum length of string to return * @return result */ public static String removeComments(final String qu, final int max) { final StringBuilder sb = new StringBuilder(); int m = 0; boolean s = false; final int cl = qu.length(); for (int c = 0; c < cl && sb.length() < max; ++c) { final char ch = qu.charAt(c); if (ch == 0x0d) continue; if (ch == '(' && c + 1 < cl && qu.charAt(c + 1) == ':') { if (m == 0 && !s) { sb.append(' '); s = true; } ++m; ++c; } else if (m != 0 && ch == ':' && c + 1 < cl && qu.charAt(c + 1) == ')') { --m; ++c; } else if (m == 0) { if (ch > ' ') sb.append(ch); else if (!s) sb.append(' '); s = ch <= ' '; } } if (sb.length() >= max) sb.append("..."); return sb.toString().trim(); }
@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(); }
/** * 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(); }
@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 ? " ! " : "/"); sb.append(s); } return sb.toString(); }
@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(); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); for (final UserFunc f : funcs) sb.append(f.toString()); return sb.toString(); }
/** * 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(); }