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

io.socket.parseqs.ParseQS Maven / Gradle / Ivy

There is a newer version: 1.1.28
Show newest version
package io.socket.parseqs;


import io.socket.global.Global;

import java.util.HashMap;
import java.util.Map;

public class ParseQS {

    private ParseQS() {}

    public static String encode(Map obj) {
        StringBuilder str = new StringBuilder();
        for (Map.Entry entry : obj.entrySet()) {
            if (str.length() > 0) str.append("&");
            str.append(Global.encodeURIComponent(entry.getKey())).append("=")
                    .append(Global.encodeURIComponent(entry.getValue()));
        }
        return str.toString();
    }

    public static Map decode(String qs) {
        Map qry = new HashMap();
        String[] pairs = qs.split("&");
        for (String _pair : pairs) {
            String[] pair = _pair.split("=");
            qry.put(Global.decodeURIComponent(pair[0]),
                    pair.length > 1 ? Global.decodeURIComponent(pair[1]) : "");
        }
        return qry;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy