diff options
author | Amjad Ben Hedhili <amjadhedhili@outlook.com> | 2022-10-09 20:54:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-09 15:54:21 -0400 |
commit | 944e4cf5853ad12f0738900e224109bb321715d0 (patch) | |
tree | c3eec500b2d64e3386859e959059737f437add44 | |
parent | 0c0b086d58baae0ac09dc4bb8b76be8aea666f16 (diff) | |
download | Nim-944e4cf5853ad12f0738900e224109bb321715d0.tar.gz |
Remove unused `base64.encode` overload (#20369)
* Remove unused `base64.encode` overload * [skip ci] Remove commented code * [skip ci] var -> let * [skip ci] Remove mentions of the string overload * Remove `SomeInteger` overload * Fix CI * Fix CI * Deprecate `SomeInteger` overload * [skip ci] Add changelog entry * Revert "Remove `SomeInteger` overload" This reverts commit 79a2963a2154377ee44e9ad5532409baaf5575a6. * Revert "[skip ci] Add changelog entry" This reverts commit 186f17eb3919a593e2a3928e3ac3b462a8323fc1. * Revert "Revert "Remove `SomeInteger` overload"" This reverts commit 8005318ee4fbf8cef726b1af2015e76aaf1e700a. * Update lib/pure/base64.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r-- | changelog.md | 4 | ||||
-rw-r--r-- | lib/pure/base64.nim | 37 |
2 files changed, 13 insertions, 28 deletions
diff --git a/changelog.md b/changelog.md index aed09462a..a95582fad 100644 --- a/changelog.md +++ b/changelog.md @@ -129,6 +129,8 @@ [//]: # "Deprecations:" - Deprecated `selfExe` for Nimscript. - Deprecated `std/sums`. +- Deprecated `std/base64.encode` for collections of arbitrary integer element type. + Now only `byte` and `char` are supported. [//]: # "Removals:" - Removed deprecated module `parseopt2`. @@ -215,7 +217,7 @@ - `nim` can now compile version 1.4.0 as follows: `nim c --lib:lib --stylecheck:off compiler/nim`, without requiring `-d:nimVersion140` which is now a noop. -- `--styleCheck`, `--hintAsError` and `--warningAsError` now only applies to the current package. +- `--styleCheck`, `--hintAsError` and `--warningAsError` now only apply to the current package. - The switch `--nimMainPrefix:prefix` has been added to add a prefix to the names of `NimMain` and related functions produced on the backend. This prevents conflicts with other Nim diff --git a/lib/pure/base64.nim b/lib/pure/base64.nim index bc01a9164..8d19feda4 100644 --- a/lib/pure/base64.nim +++ b/lib/pure/base64.nim @@ -31,7 +31,7 @@ runnableExamples: ## runnableExamples: - let encodedInts = encode([1,2,3]) + let encodedInts = encode([1'u8,2,3]) assert encodedInts == "AQID" let encodedChars = encode(['h','e','y']) assert encodedChars == "aGV5" @@ -84,10 +84,13 @@ template encodeInternal(s, alphabet: typed): untyped = result.setLen(encodeSize(s.len)) + let + padding = s.len mod 3 + inputEnds = s.len - padding + var inputIndex = 0 outputIndex = 0 - inputEnds = s.len - s.len mod 3 n: uint32 b: uint32 @@ -113,7 +116,6 @@ template encodeInternal(s, alphabet: typed): untyped = outputChar(n shr 6) outputChar(n shr 0) - var padding = s.len mod 3 if padding == 1: inputByte(b shl 16) outputChar(n shr 18) @@ -141,12 +143,9 @@ template encodeImpl() {.dirty.} = let lookupTable = if safe: unsafeAddr(cb64safe) else: unsafeAddr(cb64) encodeInternal(s, lookupTable) -proc encode*[T: SomeInteger|char](s: openArray[T], safe = false): string = +proc encode*[T: byte|char](s: openArray[T], safe = false): string = ## Encodes `s` into base64 representation. ## - ## This procedure encodes an openarray (array or sequence) of either integers - ## or characters. - ## ## If `safe` is `true` then it will encode using the ## URL-Safe and Filesystem-safe standard alphabet characters, ## which substitutes `-` instead of `+` and `_` instead of `/`. @@ -154,30 +153,15 @@ proc encode*[T: SomeInteger|char](s: openArray[T], safe = false): string = ## * https://tools.ietf.org/html/rfc4648#page-7 ## ## **See also:** - ## * `encode proc<#encode,string>`_ for encoding a string ## * `decode proc<#decode,string>`_ for decoding a string runnableExamples: + assert encode("Hello World") == "SGVsbG8gV29ybGQ=" assert encode(['n', 'i', 'm']) == "bmlt" assert encode(@['n', 'i', 'm']) == "bmlt" - assert encode([1, 2, 3, 4, 5]) == "AQIDBAU=" + assert encode([1'u8, 2, 3, 4, 5]) == "AQIDBAU=" encodeImpl() -proc encode*(s: string, safe = false): string = - ## Encodes `s` into base64 representation. - ## - ## This procedure encodes a string. - ## - ## If `safe` is `true` then it will encode using the - ## URL-Safe and Filesystem-safe standard alphabet characters, - ## which substitutes `-` instead of `+` and `_` instead of `/`. - ## * https://en.wikipedia.org/wiki/Base64#URL_applications - ## * https://tools.ietf.org/html/rfc4648#page-7 - ## - ## **See also:** - ## * `encode proc<#encode,openArray[T]>`_ for encoding an openarray - ## * `decode proc<#decode,string>`_ for decoding a string - runnableExamples: - assert encode("Hello World") == "SGVsbG8gV29ybGQ=" +proc encode*[T: SomeInteger and not byte](s: openArray[T], safe = false): string {.deprecated: "use `byte` or `char` instead".} = encodeImpl() proc encodeMime*(s: string, lineLen = 75.Positive, newLine = "\r\n"): string = @@ -187,7 +171,7 @@ proc encodeMime*(s: string, lineLen = 75.Positive, newLine = "\r\n"): string = ## This procedure encodes a string according to MIME spec. ## ## **See also:** - ## * `encode proc<#encode,string>`_ for encoding a string + ## * `encode proc<#encode,openArray[T]>`_ for encoding an openArray ## * `decode proc<#decode,string>`_ for decoding a string runnableExamples: assert encodeMime("Hello World", 4, "\n") == "SGVs\nbG8g\nV29y\nbGQ=" @@ -232,7 +216,6 @@ proc decode*(s: string): string = ## ## **See also:** ## * `encode proc<#encode,openArray[T]>`_ for encoding an openarray - ## * `encode proc<#encode,string>`_ for encoding a string runnableExamples: assert decode("SGVsbG8gV29ybGQ=") == "Hello World" assert decode(" SGVsbG8gV29ybGQ=") == "Hello World" |