2002/03/21 01:19:32
[org.ibex.core.git] / src / org / bouncycastle / asn1 / x509 / X509NameTokenizer.java
diff --git a/src/org/bouncycastle/asn1/x509/X509NameTokenizer.java b/src/org/bouncycastle/asn1/x509/X509NameTokenizer.java
new file mode 100644 (file)
index 0000000..2474027
--- /dev/null
@@ -0,0 +1,48 @@
+package org.bouncycastle.asn1.x509;
+
+/**
+ * class for breaking up an X509 Name into it's component tokens, ala
+ * java.util.StringTokenizer. We need this class as some of the
+ * lightweight Java environment don't support classes like
+ * StringTokenizer.
+ */
+public class X509NameTokenizer
+{
+    private String  oid;
+    private int     index;
+
+    public X509NameTokenizer(
+        String oid)
+    {
+        this.oid = oid;
+        this.index = 0;
+    }
+
+    public boolean hasMoreTokens()
+    {
+        return (index != -1);
+    }
+
+    public String nextToken()
+    {
+        if (index == -1)
+        {
+            return null;
+        }
+
+        String  token;
+        int     end = oid.indexOf(',', index);
+
+        if (end == -1)
+        {
+            token = oid.substring(index);
+            index = -1;
+            return token.trim();
+        }
+
+        token = oid.substring(index, end);
+
+        index = end + 1;
+        return token.trim();
+    }
+}