KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > util > StringUtils


1 package rero.util;
2
3 import java.util.*;
4 import text.*;
5
6 public class StringUtils
7 {
8      /** strips the color codes out of the specified text */
9      public static String JavaDoc strip(String JavaDoc text)
10      {
11         return AttributedString.CreateAttributedString(text).getText();
12      }
13    
14      //
15
// iswm = is wildcard match = wildcard matching, pHEER iT!
16
//
17
public static boolean iswm(String JavaDoc a, String JavaDoc b)
18      {
19         int aptr = 0, bptr = 0, cptr;
20
21         while (aptr < a.length())
22         {
23            if (a.charAt(aptr) == '*')
24            {
25               while (a.charAt(aptr) == '*')
26               {
27                  aptr++;
28                  if (aptr == a.length())
29                  {
30                     return true;
31                  }
32               }
33
34               for (cptr = aptr; cptr < a.length() && a.charAt(cptr) != '?' && a.charAt(cptr) != '*'; cptr++);
35
36  // bptr = b.indexOf(a.charAt(aptr), bptr);
37
bptr = b.indexOf(a.substring(aptr, cptr), bptr);
38               if (bptr == -1)
39               {
40 // System.out.println("FP: No index of "+a.charAt(aptr)+" from "+bptr);
41
return false;
42               }
43            }
44            else if (a.charAt(aptr) == '?')
45            {
46               while (a.charAt(aptr) == '?')
47               {
48                  bptr++;
49                  aptr++;
50                  if (aptr == a.length())
51                  {
52   // System.out.println("Possible FP: "+bptr+" == "+b.length());
53
return (bptr == b.length());
54                  }
55               }
56            }
57            else if (a.charAt(aptr) != b.charAt(bptr))
58            {
59     // System.out.println("FP: "+a.charAt(aptr)+" != "+b.charAt(bptr)+" Chars ("+aptr+", "+bptr+")");
60
return false;
61            }
62            aptr++;
63            bptr++;
64         }
65         return true;
66      }
67 }
68
Popular Tags