diff options
author | Sven Gothel <[email protected]> | 2022-09-06 10:27:32 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-09-06 10:27:32 +0200 |
commit | 43a5fb0dc76adf80dc6e36e7f9ba0341176c7f3b (patch) | |
tree | 449cec3107702b3b0124263000fbef4bb65b8436 /java_base | |
parent | 093c9d20089d273c0789e44594963022e4a94fc3 (diff) |
Add jau::codec::base::ascii38_alphabet: Drop lower case letters suitable for unique vfat filename and use it for temp-dir
Base 38 is still big enough to provide > INT_MAX @ 6 digits.
Diffstat (limited to 'java_base')
-rw-r--r-- | java_base/org/jau/util/BaseCodec.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/java_base/org/jau/util/BaseCodec.java b/java_base/org/jau/util/BaseCodec.java index 500eec7..b7c8f47 100644 --- a/java_base/org/jau/util/BaseCodec.java +++ b/java_base/org/jau/util/BaseCodec.java @@ -246,6 +246,48 @@ public class BaseCodec { } /** + * 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` + * + * @see encodeBase() + * @see decodeBase() + */ + public static class Ascii38Alphabet extends Alphabet { + private static final String data = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; + + @Override + public int code_point(final char c) { + 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 Ascii38Alphabet() { + super("ascii38", 38, data, '='); + } + } + + /** * Safe base 64 alphabet with ASCII code-point sorting order. * * - Value: `-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz` |