< prev index next >

src/java.naming/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java

Print this page




 531                 sb.append("\\28");
 532                 break;
 533             case ')':
 534                 sb.append("\\29");
 535                 break;
 536             case '\\':
 537                 sb.append("\\5c");
 538                 break;
 539             case 0:
 540                 sb.append("\\00");
 541                 break;
 542             default:
 543                 sb.append(ch);
 544             }
 545         }
 546         return sb.toString();
 547     }
 548 
 549 
 550     /**
 551       * Finds the first occurrence of <tt>ch</tt> in <tt>val</tt> starting
 552       * from position <tt>start</tt>. It doesn't count if <tt>ch</tt>
 553       * has been escaped by a backslash (\)
 554       */
 555     public static int findUnescaped(char ch, String val, int start) {
 556         int len = val.length();
 557 
 558         while (start < len) {
 559             int where = val.indexOf(ch, start);
 560             // if at start of string, or not there at all, or if not escaped
 561             if (where == start || where == -1 || val.charAt(where-1) != '\\')
 562                 return where;
 563 
 564             // start search after escaped star
 565             start = where + 1;
 566         }
 567         return -1;
 568     }
 569 
 570     /**
 571      * Formats the expression <tt>expr</tt> using arguments from the array
 572      * <tt>args</tt>.
 573      *
 574      * <code>{i}</code> specifies the <code>i</code>'th element from
 575      * the array <code>args</code> is to be substituted for the
 576      * string "<code>{i}</code>".
 577      *
 578      * To escape '{' or '}' (or any other character), use '\'.
 579      *
 580      * Uses getEncodedStringRep() to do encoding.
 581      */
 582 
 583     public static String format(String expr, Object[] args)
 584         throws NamingException {
 585 
 586          int param;
 587          int where = 0, start = 0;
 588          StringBuilder answer = new StringBuilder(expr.length());
 589 
 590          while ((where = findUnescaped('{', expr, start)) >= 0) {
 591              int pstart = where + 1; // skip '{'
 592              int pend = expr.indexOf('}', pstart);




 531                 sb.append("\\28");
 532                 break;
 533             case ')':
 534                 sb.append("\\29");
 535                 break;
 536             case '\\':
 537                 sb.append("\\5c");
 538                 break;
 539             case 0:
 540                 sb.append("\\00");
 541                 break;
 542             default:
 543                 sb.append(ch);
 544             }
 545         }
 546         return sb.toString();
 547     }
 548 
 549 
 550     /**
 551       * Finds the first occurrence of {@code ch} in {@code val} starting
 552       * from position {@code start}. It doesn't count if {@code ch}
 553       * has been escaped by a backslash (\)
 554       */
 555     public static int findUnescaped(char ch, String val, int start) {
 556         int len = val.length();
 557 
 558         while (start < len) {
 559             int where = val.indexOf(ch, start);
 560             // if at start of string, or not there at all, or if not escaped
 561             if (where == start || where == -1 || val.charAt(where-1) != '\\')
 562                 return where;
 563 
 564             // start search after escaped star
 565             start = where + 1;
 566         }
 567         return -1;
 568     }
 569 
 570     /**
 571      * Formats the expression {@code expr} using arguments from the array
 572      * {@code args}.
 573      *
 574      * <code>{i}</code> specifies the <code>i</code>'th element from
 575      * the array <code>args</code> is to be substituted for the
 576      * string "<code>{i}</code>".
 577      *
 578      * To escape '{' or '}' (or any other character), use '\'.
 579      *
 580      * Uses getEncodedStringRep() to do encoding.
 581      */
 582 
 583     public static String format(String expr, Object[] args)
 584         throws NamingException {
 585 
 586          int param;
 587          int where = 0, start = 0;
 588          StringBuilder answer = new StringBuilder(expr.length());
 589 
 590          while ((where = findUnescaped('{', expr, start)) >= 0) {
 591              int pstart = where + 1; // skip '{'
 592              int pend = expr.indexOf('}', pstart);


< prev index next >