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

net.thisptr.jackson.jq.internal.functions.AtUriFunction Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package net.thisptr.jackson.jq.internal.functions;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.google.auto.service.AutoService;

import net.thisptr.jackson.jq.BuiltinFunction;
import net.thisptr.jackson.jq.Function;
import net.thisptr.jackson.jq.exception.JsonQueryException;

/**
 * RFC2396
 * 
    *
  • unreserved = alphanum | mark
  • *
  • mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
  • *
*/ @AutoService(Function.class) @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