01: package org.bouncycastle.asn1.x509;
02:
03: /**
04: * class for breaking up an X500 Name into it's component tokens, ala
05: * java.util.StringTokenizer. We need this class as some of the
06: * lightweight Java environment don't support classes like
07: * StringTokenizer.
08: */
09: public class X509NameTokenizer {
10: private String value;
11: private int index;
12: private char seperator;
13: private StringBuffer buf = new StringBuffer();
14:
15: public X509NameTokenizer(String oid) {
16: this (oid, ',');
17: }
18:
19: public X509NameTokenizer(String oid, char seperator) {
20: this .value = oid;
21: this .index = -1;
22: this .seperator = seperator;
23: }
24:
25: public boolean hasMoreTokens() {
26: return (index != value.length());
27: }
28:
29: public String nextToken() {
30: if (index == value.length()) {
31: return null;
32: }
33:
34: int end = index + 1;
35: boolean quoted = false;
36: boolean escaped = false;
37:
38: buf.setLength(0);
39:
40: while (end != value.length()) {
41: char c = value.charAt(end);
42:
43: if (c == '"') {
44: if (!escaped) {
45: quoted = !quoted;
46: } else {
47: buf.append(c);
48: }
49: escaped = false;
50: } else {
51: if (escaped || quoted) {
52: buf.append(c);
53: escaped = false;
54: } else if (c == '\\') {
55: escaped = true;
56: } else if (c == seperator) {
57: break;
58: } else {
59: buf.append(c);
60: }
61: }
62: end++;
63: }
64:
65: index = end;
66: return buf.toString().trim();
67: }
68: }
|