Class URLUTF8Encoder

java.lang.Object
ecmwf.common.text.URLUTF8Encoder

public final class URLUTF8Encoder extends Object
Provides a method to encode any string into a URL-safe form. Non-ASCII characters are first encoded as sequences of two or three bytes, using the UTF-8 algorithm, before being encoded as %HH escapes.
Author:
root
  • Constructor Details

    • URLUTF8Encoder

      public URLUTF8Encoder()
  • Method Details

    • encode

      public static String encode(char c)
      Encode.
      Parameters:
      c - the c
      Returns:
      the string
    • encode

      public static String encode(String s)
      Encode a string to the "x-www-form-urlencoded" form, enhanced with the UTF-8-in-URL proposal. This is what happens:
      • The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the same.

      • The unreserved characters - _ . ! ~ * ' ( ) remain the same.

      • The space character ' ' is converted into a plus sign '+'.

      • All other ASCII characters are converted into the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the character code

      • All non-ASCII characters are encoded in two steps: first to a sequence of 2 or 3 bytes, using the UTF-8 algorithm; secondly each of these bytes is encoded as "%xx".

      Parameters:
      s - The string to be encoded
      Returns:
      The encoded string
    • unescape

      public static String unescape(String s)
      Unescape.
      Parameters:
      s - the s
      Returns:
      the string