All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.bingads.internal.URLExtensions Maven / Gradle / Ivy

Go to download

The Bing Ads Java SDK is a library improving developer experience when working with the Bing Ads services by providing high-level access to features such as Bulk API, OAuth Authorization and SOAP API.

There is a newer version: 13.0.22.1
Show newest version
package com.microsoft.bingads.internal;

import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.LinkedHashMap;
import java.util.Map;

class URLExtensions {

    public static Map parseQuery(URL url) {
        return parseQueryStringArgs(url.getQuery());
    }

    public static Map parseFragment(URL url) {
        return parseQueryStringArgs(url.getRef());
    }

    public static Map parseQueryStringArgs(String input) {
        try {
            final Map query_pairs = new LinkedHashMap();
            if (input == null || input.length() == 0) {
                return query_pairs;
            }
            final String[] pairs = input.split("&");
            for (String pair : pairs) {
                final int idx = pair.indexOf("=");
                final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair;
                final String value = idx > 0 && pair.length() > idx + 1 ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8") : null;
                query_pairs.put(key, value);
            }
            return query_pairs;
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy