From 793dc83c9fca000c6aaed0ea2ee335bc64c0045f Mon Sep 17 00:00:00 2001 From: Tim Nieradzik Date: Mon, 8 Jul 2019 17:10:02 +0300 Subject: [PATCH] Manual: Add example for encoding/decoding URI values --- manual/introduction.md | 3 +++ manual/listings.json | 5 +++++ manual/src/main/scala/trail/manual/Listings.scala | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/manual/introduction.md b/manual/introduction.md index 166b4de..16a1dfc 100644 --- a/manual/introduction.md +++ b/manual/introduction.md @@ -39,3 +39,6 @@ Define a custom codec that can be used in arguments, parameters and fragments: Define a custom path element type: + +Encode and decode [URI values](https://en.wikipedia.org/wiki/Percent-encoding): +diff --git a/manual/listings.json b/manual/listings.json index 018d1be..a4a29c0 100644 --- a/manual/listings.json +++ b/manual/listings.json @@ -1,4 +1,9 @@ { + "uri-values" : { + "code" : "val encoded = URI.encode(\"äöü\")\nprintln(encoded)\nprintln(URI.decode(encoded))", + "language" : "scala", + "result" : "%C3%A4%C3%B6%C3%BC\näöü" + }, "map" : { "code" : "println(details.parse(\"/details/42\"))", "language" : "scala", diff --git a/manual/src/main/scala/trail/manual/Listings.scala b/manual/src/main/scala/trail/manual/Listings.scala index ac6d7c1..426834f 100644 --- a/manual/src/main/scala/trail/manual/Listings.scala +++ b/manual/src/main/scala/trail/manual/Listings.scala @@ -65,6 +65,11 @@ object Listings extends App { println((Root / Foo("asdf")).url(())) + listing("uri-values") + val encoded = URI.encode("äöü") + println(encoded) + println(URI.decode(encoded)) + end() write("manual/listings.json") }