diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/jau/base_codec.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/include/jau/base_codec.hpp b/include/jau/base_codec.hpp index 62e74c9..d5d9e3c 100644 --- a/include/jau/base_codec.hpp +++ b/include/jau/base_codec.hpp @@ -256,6 +256,45 @@ namespace jau::codec::base { }; /** + * Safe base 38 alphabet with ASCII code-point sorting order. + * + * - Value: `-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_` + * - Padding: `=` + * + * ### Properties + * - 7-bit ASCII + * - Code page 437 compatible + * - Safe URL and filename use + * - Excludes forbidden [v]fat chars: `<>:"/\|?*` + * - Only using upper-case letters for unique filename under vfat + * - Excludes quoting chars: "'$ and space + * - Supporting ASCII code-point sorting. + * - Order: `-` < `0` < `A` < `a` < `z` + */ + class ascii38_alphabet : public alphabet { + private: + static inline constexpr const std::string_view data = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; + + static int s_code_point(const char c) noexcept { + if ('0' <= c && c <= '9') { + return c - '0' + 1; + } else if ('A' <= c && c <= 'Z') { + return c - 'A' + 11; + } else if ('-' == c) { + return 0; + } else if ('_' == c) { + return 37; + } else { + return -1; + } + } + + public: + ascii38_alphabet() noexcept + : alphabet("ascii38", 38, data, '=', s_code_point) {} + }; + + /** * Safe base 64 alphabet with ASCII code-point sorting order. * * - Value: `-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz` |