2002/03/21 01:19:32
[org.ibex.core.git] / src / org / bouncycastle / asn1 / x509 / X509NameTokenizer.java
1 package org.bouncycastle.asn1.x509;
2
3 /**
4  * class for breaking up an X509 Name into it's component tokens, ala
5  * java.util.StringTokenizer. We need this class as some of the
6  * lightweight Java environment don't support classes like
7  * StringTokenizer.
8  */
9 public class X509NameTokenizer
10 {
11     private String  oid;
12     private int     index;
13
14     public X509NameTokenizer(
15         String oid)
16     {
17         this.oid = oid;
18         this.index = 0;
19     }
20
21     public boolean hasMoreTokens()
22     {
23         return (index != -1);
24     }
25
26     public String nextToken()
27     {
28         if (index == -1)
29         {
30             return null;
31         }
32
33         String  token;
34         int     end = oid.indexOf(',', index);
35
36         if (end == -1)
37         {
38             token = oid.substring(index);
39             index = -1;
40             return token.trim();
41         }
42
43         token = oid.substring(index, end);
44
45         index = end + 1;
46         return token.trim();
47     }
48 }