[std/base64] uses runnableExamples (#17882)

* [std/base64] uses runnableExamples
* Update lib/pure/base64.nim

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
flywind 2021-05-01 13:27:50 +08:00 • committed by GitHub
commit 9f75e8abc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,44 +16,42 @@
## Each Base64 digit represents exactly 6 bits of data. Three 8-bit ## Each Base64 digit represents exactly 6 bits of data. Three 8-bit
## bytes (i.e., a total of 24 bits) can therefore be represented by ## bytes (i.e., a total of 24 bits) can therefore be represented by
## four 6-bit Base64 digits. ## four 6-bit Base64 digits.
##
## Basic usage ##[
## =========== # Basic usage
##
## Encoding data ## Encoding data
## ------------- ]##
##
## .. code-block:: Nim runnableExamples:
## import std/base64 let encoded = encode("Hello World")
## let encoded = encode("Hello World") assert encoded == "SGVsbG8gV29ybGQ="
## assert encoded == "SGVsbG8gV29ybGQ="
## ##
## Apart from strings you can also encode lists of integers or characters: ## Apart from strings you can also encode lists of integers or characters:
## ##
## .. code-block:: Nim
## import std/base64 runnableExamples:
## let encodedInts = encode([1,2,3]) let encodedInts = encode([1,2,3])
## assert encodedInts == "AQID" assert encodedInts == "AQID"
## let encodedChars = encode(['h','e','y']) let encodedChars = encode(['h','e','y'])
## assert encodedChars == "aGV5" assert encodedChars == "aGV5"
##
## ##[
## Decoding data ## Decoding data
## ------------- ]##
##
## .. code-block:: Nim runnableExamples:
## import std/base64 let decoded = decode("SGVsbG8gV29ybGQ=")
## let decoded = decode("SGVsbG8gV29ybGQ=") assert decoded == "Hello World"
## assert decoded == "Hello World"
## ##[
## URL Safe Base64 ## URL Safe Base64
## --------------- ]##
##
## .. code-block:: Nim runnableExamples:
## import std/base64 assert encode("c\xf7>", safe = true) == "Y_c-"
## doAssert encode("c\xf7>", safe = true) == "Y_c-" assert encode("c\xf7>", safe = false) == "Y/c+"
## doAssert encode("c\xf7>", safe = false) == "Y/c+"
##
## See also ## See also
## ======== ## ========
## ##