static URL parse(String expr) {
        URL url = new URL();
        String host = expr;
        short port = 80;
        String path = "";
        String tokens = "";
        String auth = "";
        String protocol = "http";
        String error = "";
        int pos;
    
        // Expr can be on the form "http://auth@localhost:80/x00112233?token"
    
        // Take out the protocol
        pos = host.indexOf("://");
        if (pos != -1) {
            protocol = host.substring(0, pos);
            protocol = protocol.toLowerCase();
            host = host.substring(pos + 3);
        }
    
        // Take out the auth
        pos = host.indexOf("@");
        if (pos != -1) {
            auth = host.substring(0, pos);
            host = host.substring(pos + 1);
        }
    
        // Take out the token
        pos = host.lastIndexOf("?");
        if (pos != -1) {
            tokens = host.substring(pos + 1);
            host = host.substring(0, pos);
        }

        // Take out the path
        pos = host.indexOf("/");
        if (pos != -1) {
            path = host.substring(pos + 1);
            host = host.substring(0, pos);
        }

        // Take out the port
        pos = host.lastIndexOf(":");
        if (pos != -1) {
            try {
                port = Short.parseShort(host.substring(pos + 1), 10);
            } catch (NumberFormatException e) {
                error = "Could not read the port \"" + host.substring(pos + 1) + "\""; 
            }
    	
            host = host.substring(0, pos);
        }
	
        url.m_path = path;
        url.m_token = tokens;
        url.m_host = host;
        url.m_port = port;
        url.m_auth = auth;
        url.m_protocol = protocol;
        url.m_error = error;
	
        return url;
    }