daandi / nice-url-encode-decode   1.5

GitHub

This helper classes aim to make working with URL decoders and encoders more enjoyable.

Scala versions: 2.12

Nice Encoding and Decoding of String in URL Query Parameters

This library wants to put back the fun in working with URL-Encoded Strings.

Scala CI

Adding to your project

Remarks

  • The Pimp my library pattern is use to make this extension possible. It is implemented using value classes to keep the overhead low.
  • The library is biased towards using %20 to escape instead of +.
  • The library is biased towards utf-8. You can circumvent this though by supplying a different Encoding though as implicit parameter.

Usage

Import the implicits to get your strings pimped:

scala> import biz.neumann.url.NiceURLCodecs._
import biz.neumann.url.NiceURLCodecs._

Encoding

scala> "ˈbalɐˌman".encode
res0: biz.neumann.url.NiceURLCodecs.URLEncodedString = %CB%88bal%C9%90%CB%8Cman

Using some other encoding:

scala> "ˈbalɐˌman".encode("latin1")
res1: biz.neumann.url.NiceURLCodecs.URLEncodedString = %3Fbal%3F%3Fman

Decoding

scala> "ˈbalɐˌman".encode.decode
res1: String = ˈbalɐˌman

scala> "x%20x+x".decode
res3: String = x x x