// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 10/2/2001 11:01:03
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/utils/QueryStringParser

package com.macromedia.generator.utils;

import java.util.Hashtable;
import java.util.StringTokenizer;

public class QueryStringParser
{

    public QueryStringParser()
    {
    }

    public Hashtable parse(String s)
    {
        if(s == null)
            throw new IllegalArgumentException();
        Hashtable hashtable = new Hashtable();
        int i = s.indexOf(63);
        if(i > -1)
        {
            String s1 = s.substring(i + 1, s.length());
            StringBuffer stringbuffer = new StringBuffer();
            for(StringTokenizer stringtokenizer = new StringTokenizer(s1, "&"); stringtokenizer.hasMoreTokens();)
            {
                String s2 = stringtokenizer.nextToken();
                int j = s2.indexOf(61);
                if(j > 0)
                {
                    String s3 = _mth017B(s2.substring(0, j), stringbuffer);
                    String s4 = _mth017B(s2.substring(j + 1, s2.length()), stringbuffer);
                    hashtable.put(s3, s4);
                }
            }

        }
        return hashtable;
    }

    private String _mth017B(String s, StringBuffer stringbuffer)
    {
        stringbuffer.setLength(0);
        for(int i = 0; i < s.length(); i++)
        {
            char c = s.charAt(i);
            switch(c)
            {
            case 43: // '+'
                stringbuffer.append(' ');
                break;

            case 37: // '%'
                try
                {
                    stringbuffer.append((char)Integer.parseInt(s.substring(i + 1, i + 3), 16));
                }
                catch(NumberFormatException _ex)
                {
                    throw new IllegalArgumentException();
                }
                i += 2;
                break;

            default:
                stringbuffer.append(c);
                break;
            }
        }

        return stringbuffer.toString();
    }
}