Exemple #1
1
 /**
  * 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();
 }
Exemple #2
1
 /**
  * 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;
 }
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
 /**
  * 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 #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
 @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 #7
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 #8
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();
 }