com.groupbyinc.common.jackson.jq.internal.functions.AtUriFunction Maven / Gradle / Ivy
package net.thisptr.jackson.jq.internal.functions;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import net.thisptr.jackson.jq.exception.JsonQueryException;
import net.thisptr.jackson.jq.internal.BuiltinFunction;
/**
* RFC2396
*
* - unreserved = alphanum | mark
* - mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
*
*/
@BuiltinFunction("@uri/0")
public class AtUriFunction extends AbstractAtFormattingFunction {
@Override
public String convert(final String text) throws JsonQueryException {
try {
return URLEncoder.encode(text, "UTF-8")
.replaceAll("\\+", "%20")
.replaceAll("%21", "!")
.replaceAll("%27", "'")
.replaceAll("%28", "(")
.replaceAll("%29", ")")
.replaceAll("%7E", "~");
} catch (UnsupportedEncodingException e) {
throw new JsonQueryException(e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy