yencode: Yet (another urlencode compatible) encoding scheme

View source: R/yencode.R

yencodeR Documentation

Yet (another urlencode compatible) encoding scheme

Description

Encode and decode using an encoding scheme that is a superset of the utils::URLencode() encoding. With default settings, yencode() and ydecode() produce strings that are fully compatible with urlencode encoded strings. However, these functions allow a custom whitelist of symbols that should not be escaped by the encoding process, and a configurable escape character to use in place of the ⁠%⁠ symbol, for example to work with storage layers that do not like the ⁠%⁠ symbol.

The yencoder() and ydecoder() functions are convenience function, which return the corresponding a function with the escape and whitelist already set, allowing easy use in contexts that expect a single-argument function.

Usage

yencode(string, escape = "%", whitelist = c("._~-", "][!$&'()*+,;=:/?@#"))

yencoder(escape = "%", whitelist = c("._~-", "][!$&'()*+,;=:/?@#"))

ydecode(string, escape = "%")

ydecoder(escape = "%")

Arguments

string

The string to process.

escape

The escape character to use.

whitelist

Any characters that should not be escaped. See details.

Details

In addition to the supplied white-list, A-Z, a-z, and 0-9 are always white-listed. There are no restrictions on the white-list, except that the escape character must not be part of it (and will be removed from it with a warning). Of course, it is important that the underlying storage layer handles all white-listed characters gracefully.

Note that any ascii letter or number will work perfectly fine as an escape character, the output will be well-formed and decoded correctly, even if some of them, such as 1 will result in escape sequences that contain the letter itself.

In particular, yencoder("Z", whitelist="") returns a encoder that will encode any string to a pure A-Z, a-z, and 0-9 representation, suitable for extremely limited storage layers (it will encode Z as Z5A).

Value

The processed (encoded or decoded) string.


torfason/zulutils documentation built on Aug. 21, 2023, 5:46 p.m.