summary refs log tree commit diff
path: root/crypto/src/asn1/OidTokenizer.cs
blob: 6e76e8c8bf9e48b7d5047b2928b0019cd31a8c18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace Org.BouncyCastle.Asn1
{
    /**
     * class for breaking up an Oid 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 OidTokenizer
    {
        private string  oid;
        private int     index;

		public OidTokenizer(
            string oid)
        {
            this.oid = oid;
        }

		public bool HasMoreTokens
        {
			get { return index != -1; }
        }

		public string NextToken()
        {
            if (index == -1)
            {
                return null;
            }

            int end = oid.IndexOf('.', index);
            if (end == -1)
            {
                string lastToken = oid.Substring(index);
                index = -1;
                return lastToken;
            }

            string nextToken = oid.Substring(index, end - index);
			index = end + 1;
            return nextToken;
        }
    }
}