[rb-general] BUILD_PATH_PREFIX_MAP code examples and test cases

Ximin Luo infinity0 at debian.org
Mon Jan 30 17:24:00 CET 2017


Hi all,

Code and test cases are now available here:

https://github.com/infinity0/rb-prefix-map/tree/master/consume/

I made some minor changes on top of the proposal from last time; the mapping is now:

% -> %p
= -> %e
: -> %c

in other words, the first letter of the name of the symbol in English. (Yes it's English-centric, but so are programming languages in general.)

I'll next write up the English descriptions of the code, including what to do under various error conditions, why this was chosen, what circumstances you'd want to use this in, etc etc.

In the meantime people can feel free to review my C (I checked it through ASAN already) and/or submit PRs for other languages.

--

I made the change because one of the aims is to make decode() easy to implement both in C as well as higher-level languages. The previous mapping had one major issue:

% -> %%
= -> %+
: -> %;

This means that "the easy way" of doing it in C (single-pass left-to-right parsing) gives different results from "the easy way" of doing it in higher-level languages, for the string sequence "%%+". This is not a possible output of a good encoder; however I don't want to take chances and even "invalid" encodings should still be decoded in the same way by all implementations.

single-pass l2r               : %%+ decodes to %+
.replace(%+, =).replace(%%, %): %%+ decodes to %=
.replace(%%, %).replace(%+, =): %%+ decodes to =

I couldn't think of a suitable symbol to map % to, so I then picked letters instead.

X

-- 
GPG: ed25519/56034877E1F87C35
GPG: rsa4096/1318EFAC5FBBDBCE
https://github.com/infinity0/pubkeys.git


More information about the rb-general mailing list