1 19 20 package org.netbeans.modules.xml.xam.ui.search; 21 22 29 public class WildcardStringMatcher { 30 31 34 private WildcardStringMatcher() { 35 } 36 37 44 public static boolean containsWildcards(String query) { 45 return query.contains("*") || query.contains("?"); 46 } 47 48 68 public static boolean match(String text, String query) { 69 int ti; 70 int qi; 71 int tl = text.length(); 72 int ql = query.length(); 73 boolean star = false; 74 75 for (ti = 0, qi = 0; ti < tl; ti++, qi++) { 76 char qc = qi < ql ? query.charAt(qi) : 0; 79 switch (qc) { 80 case '?': 81 break; 83 case '*': 84 star = true; 85 do { 87 qi++; 88 } while (qi < ql && query.charAt(qi) == '*'); 89 if (qi == ql) { 90 return true; 92 } 93 text = text.substring(ti); 95 query = query.substring(qi); 96 tl = text.length(); 97 ql = query.length(); 98 ti = -1; 99 qi = -1; 100 break; 101 default: 102 char tc = text.charAt(ti); 103 if (tc != qc) { 104 if (!star) { 105 return false; 107 } 108 text = text.substring(1); 110 tl--; 111 ti = -1; 112 qi = -1; 113 } 114 break; 115 } 116 } 117 while (qi < ql && query.charAt(qi) == '*') { 119 qi++; 120 } 121 return ti >= tl && qi >= ql; 123 } 124 } 125 | Popular Tags |