// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.asn1.x500.style;

public class X500NameTokenizer
{
    private final String value;
    private final char separator;
    private int index;
    
    public X500NameTokenizer(final String s) {
        this(s, ',');
    }
    
    public X500NameTokenizer(final String value, final char separator) {
        if (value == null) {
            throw new NullPointerException();
        }
        if (separator == '\"' || separator == '\\') {
            throw new IllegalArgumentException("reserved separator character");
        }
        this.value = value;
        this.separator = separator;
        this.index = ((value.length() < 1) ? 0 : -1);
    }
    
    public boolean hasMoreTokens() {
        return this.index < this.value.length();
    }
    
    public String nextToken() {
        if (this.index >= this.value.length()) {
            return null;
        }
        boolean b = false;
        int n = 0;
        final int n2 = this.index + 1;
        while (++this.index < this.value.length()) {
            final char char1 = this.value.charAt(this.index);
            if (n != 0) {
                n = 0;
            }
            else if (char1 == '\"') {
                b = !b;
            }
            else {
                if (b) {
                    continue;
                }
                if (char1 == '\\') {
                    n = 1;
                }
                else {
                    if (char1 == this.separator) {
                        return this.value.substring(n2, this.index);
                    }
                    continue;
                }
            }
        }
        if (n != 0 || b) {
            throw new IllegalArgumentException("badly formatted directory string");
        }
        return this.value.substring(n2, this.index);
    }
}
