예제 #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();
 }
예제 #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;
 }
예제 #3
0
파일: Transform.java 프로젝트: nikhi/basex
 @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();
 }
예제 #4
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();
 }
예제 #5
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();
 }
예제 #6
0
파일: Path.java 프로젝트: nikhi/basex
 @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();
 }
예제 #7
0
파일: FTWords.java 프로젝트: jefferya/basex
 @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();
 }
예제 #8
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   for (final UserFunc f : funcs) sb.append(f.toString());
   return sb.toString();
 }
예제 #9
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();
 }