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