1 19 package org.netbeans.tax.io; 20 21 26 public final class StringUtil { 27 28 public static boolean isWS (char ch) { 29 return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'; 30 } 31 32 36 public static int skipDelimited (String text, int pos, char del1, char del2, String nest) { 37 char ch = text.charAt (pos); 38 if ( ch != del1) return -1; 39 do { 40 pos++; 41 ch = text.charAt (pos); 42 if (nest.indexOf (ch) >= 0) { 43 pos = skipDelimited (text, pos, ch, ch, ""); 44 ch = text.charAt (pos); 45 } 46 } while (ch != del2); 47 return pos + 1; 48 } 49 50 public static int skipDelimited (String text, int pos, String del1, String del2) { 51 if (text.startsWith (del1, pos)) { 52 int match = text.indexOf (del2, pos + del1.length ()); 53 if (match == -1) return -1; 54 return match + del2.length (); 55 } else { 56 return -1; 57 } 58 } 59 60 public static int skipWS (String text, int pos) { 61 if (isWS (text.charAt (pos))) { 62 return pos + 1; 63 } else { 64 return -1; 65 } 66 } 67 68 69 72 public static void main (String args[]) { 73 74 String idtd = " <!-- klfh --> <!hjk \"fdsf\" ''>]>"; 75 int pos = 0; 76 int now = 0; 77 int last = -1; 78 79 System.err.println ("SkipWs" + skipWS (" k", pos)); 80 81 System.err.println ("SkipDelinitedchar" + skipDelimited ("< ' > '>", 0, '<', '>' ,"\"'")); 82 83 System.err.println ("SkipDelinitedchar" + skipDelimited ("<!-- ' > '-->", 0, "<!--", "-->")); 84 85 while (idtd.substring (pos).startsWith ("]>") == false && last != pos) { 86 87 last = pos; 88 89 for (now = 0; now != -1; now = skipWS (idtd, pos)) pos = now; 90 91 for (now = 0; now != -1; now = skipDelimited (idtd, pos, "<!--", "-->")) { 92 pos = now; 93 for (now = 0; now != -1; now = skipWS (idtd, pos)) pos = now; 94 } 95 96 for (now = 0; now != -1; now = skipDelimited (idtd, pos, '<', '>' , "\"'")) pos = now; 97 98 101 } 103 104 } 105 106 } 107 | Popular Tags |