1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 26 public class X509NameTokenizer 27 { 28 private String value; 29 private int index; 30 private char seperator; 31 private StringBuffer buf = new StringBuffer (); 32 33 public X509NameTokenizer( 34 String oid) 35 { 36 this(oid, ','); 37 } 38 39 public X509NameTokenizer( 40 String oid, 41 char seperator) 42 { 43 this.value = oid; 44 this.index = -1; 45 this.seperator = seperator; 46 } 47 48 public boolean hasMoreTokens() 49 { 50 return (index != value.length()); 51 } 52 53 public String nextToken() 54 { 55 if (index == value.length()) 56 { 57 return null; 58 } 59 60 int end = index + 1; 61 boolean quoted = false; 62 boolean escaped = false; 63 64 buf.setLength(0); 65 66 while (end != value.length()) 67 { 68 char c = value.charAt(end); 69 70 if (c == '"') 71 { 72 if (!escaped) 73 { 74 quoted = !quoted; 75 } 76 else 77 { 78 buf.append(c); 79 } 80 escaped = false; 81 } 82 else 83 { 84 if (escaped || quoted) 85 { 86 buf.append(c); 87 escaped = false; 88 } 89 else if (c == '\\') 90 { 91 escaped = true; 92 } 93 else if (c == seperator) 94 { 95 break; 96 } 97 else 98 { 99 buf.append(c); 100 } 101 } 102 end++; 103 } 104 105 index = end; 106 return buf.toString().trim(); 107 } 108 } 109 | Popular Tags |