jaulib v1.3.6
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
base_codec.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef JAU_BASE_CODEC_HPP_
26#define JAU_BASE_CODEC_HPP_
27
28#include <string>
29#include <vector>
30
31#include <jau/int_types.hpp>
32
33/**
34 * Base codecs, i.e. changing the decimal or binary values' base for a different representation.
35 */
37
38 /** @defgroup Codec Codec
39 * Data Stream Encoder and Decoder
40 *
41 * Supported codecs:
42 * - jau::codec::base::alphabet enables variable integer base encode() and fixed binary base-64 encode64().
43 *
44 * @{
45 */
46
47 /**
48 * Base Alphabet Specification providing the alphabet for encode() and decode().
49 *
50 * Implementation delegates static code_point() function.
51 *
52 * @see encode()
53 * @see decode()
54 */
55 class alphabet {
56 public:
57 typedef int (*code_point_func)(const char c) noexcept;
58
59 private:
60 std::string name_;
61 int base_;
62 std::string_view symbols_;
63 char padding64_;
65
66 public:
67 alphabet(std::string _name, int _base, std::string_view _symbols, char _padding64, code_point_func _cpf) noexcept
68 : name_(std::move(_name)), base_(_base), symbols_(_symbols), padding64_(_padding64), cpf(_cpf) {}
69
70 /** Human readable name for this alphabet instance. */
71 constexpr const std::string& name() const noexcept { return name_; }
72
73 /** The fixed base used for this alphabet. */
74 constexpr int base() const noexcept { return base_; }
75
76 /** The string of symbols of this alphabet. */
77 constexpr const std::string_view& symbols() const noexcept { return symbols_; }
78
79 /** Padding symbol for base <= 64 and block encoding only. May return zero for no padding. */
80 constexpr char padding64() const noexcept { return padding64_; }
81
82 /** Returns the code-point of the given character or -1 if not element of this alphabet. */
83 constexpr int code_point(const char c) const noexcept { return cpf(c); }
84
85 /** Retrieve the character at given code-point of this alphabet. */
86 constexpr char operator[]( size_t cp ) const noexcept { return symbols_[cp]; }
87
88 std::string to_string() const noexcept {
89 std::string res("alphabet[");
90 res.append(name());
91 res.append(", base <= "+std::to_string(base())+"]");
92 return res;
93 }
94 };
95
96 inline std::string to_string(const alphabet& v) noexcept { return v.to_string(); }
97
98 inline bool operator!=(const alphabet& lhs, const alphabet& rhs ) noexcept {
99 return lhs.base() != rhs.base() || lhs.name() != rhs.name() || lhs.symbols() != rhs.symbols();
100 }
101
102 inline bool operator==(const alphabet& lhs, const alphabet& rhs ) noexcept {
103 return !( lhs != rhs );
104 }
105
106 /**
107 * Safe canonical `base64` alphabet, without ASCII code-point sorting order.
108 *
109 * Representing the canonical `base64` [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648.html) *Base 64 Alphabet*
110 * including its code-point order `A` < `a` < `0` < `/`.
111 *
112 * - Value: `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`
113 * - Padding: `=`
114 *
115 * ### Properties
116 * - Base 64
117 * - 7-bit ASCII
118 * - Code page 437 compatible
119 * - [`base64` alphabet](https://www.rfc-editor.org/rfc/rfc4648.html), identical order
120 * - Excludes quoting chars: "'$ and space
121 * - Not supporting ASCII code-point sorting.
122 * - Order: `A` < `a` < `0` < `/`
123 */
124 class base64_alphabet : public alphabet {
125 private:
126 static inline constexpr const std::string_view data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
127
128 static int s_code_point(const char c) noexcept {
129 if ('A' <= c && c <= 'Z') {
130 return c - 'A';
131 } else if ('a' <= c && c <= 'z') {
132 return c - 'a' + 26;
133 } else if ('0' <= c && c <= '9') {
134 return c - '0' + 52;
135 } else if ('+' == c) {
136 return 62;
137 } else if ('/' == c) {
138 return 63;
139 } else {
140 return -1;
141 }
142 }
143
144 public:
146 : alphabet("base64", 64, data, '=', s_code_point) {}
147 };
148
149 /**
150 * Safe canonical `base64url` alphabet, without ASCII code-point sorting order.
151 *
152 * Representing the canonical `base64url` [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648.html) `URL and Filename safe` *Base 64 Alphabet*
153 * including its code-point order `A` < `a` < `0` < `_`.
154 *
155 * - Value: `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`
156 * - Padding: `=`
157 *
158 * ### Properties
159 * - Base 64
160 * - 7-bit ASCII
161 * - Code page 437 compatible
162 * - [`base64url` alphabet](https://www.rfc-editor.org/rfc/rfc4648.html), identical order
163 * - Safe URL and filename use
164 * - Excludes forbidden [v]fat chars: `<>:"/\|?*`
165 * - Excludes quoting chars: "'$ and space
166 * - Not supporting ASCII code-point sorting.
167 * - Order: `A` < `a` < `0` < `_`
168 */
170 private:
171 static inline constexpr const std::string_view data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
172
173 static int s_code_point(const char c) noexcept {
174 if ('A' <= c && c <= 'Z') {
175 return c - 'A';
176 } else if ('a' <= c && c <= 'z') {
177 return c - 'a' + 26;
178 } else if ('0' <= c && c <= '9') {
179 return c - '0' + 52;
180 } else if ('-' == c) {
181 return 62;
182 } else if ('_' == c) {
183 return 63;
184 } else {
185 return -1;
186 }
187 }
188
189 public:
191 : alphabet("base64url", 64, data, '=', s_code_point) {}
192 };
193
194 /**
195 * Safe natural base 64 alphabet, both without ASCII code-point sorting order.
196 *
197 * Order is considered a natural extension of decimal symbols, i.e. `0` < `a` < `A` < `_`.
198 *
199 * - Value: `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_`
200 * - Padding: `=`
201 *
202 * ### Properties
203 * - Base 64
204 * - 7-bit ASCII
205 * - Code page 437 compatible
206 * - [`base64url` alphabet](https://www.rfc-editor.org/rfc/rfc4648.html), but different order
207 * - Safe URL and filename use
208 * - Excludes forbidden [v]fat chars: `<>:"/\|?*`
209 * - Excludes quoting chars: "'$ and space
210 * - Not supporting ASCII code-point sorting.
211 * - Order: `0` < `a` < `A` < `_`
212 */
214 private:
215 static inline constexpr const std::string_view data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
216
217 static int s_code_point(const char c) noexcept {
218 if ('0' <= c && c <= '9') {
219 return c - '0';
220 } else if ('a' <= c && c <= 'z') {
221 return c - 'a' + 10;
222 } else if ('A' <= c && c <= 'Z') {
223 return c - 'A' + 36;
224 } else if ('-' == c) {
225 return 62;
226 } else if ('_' == c) {
227 return 63;
228 } else {
229 return -1;
230 }
231 }
232
233 public:
235 : alphabet("natural64", 64, data, '=', s_code_point) {}
236 };
237
238 /**
239 * Natural base 86 alphabet, without ASCII code-point sorting order.
240 *
241 * Order is considered a natural extension of decimal symbols, i.e. `0` < `a` < `A` < `_` < `~`
242 *
243 * - Value: `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_!#%&()+,/:;<=>?@[]^{}~`
244 * - Padding: none
245 *
246 * ### Properties
247 * - Base 86
248 * - 7-bit ASCII
249 * - Code page 437 compatible
250 * - Excludes quoting chars: "'$ and space
251 * - Not supporting ASCII code-point sorting.
252 * - Order: `0` < `a` < `A` < `_` < `~`
253 */
255 private:
256 static inline constexpr const std::string_view data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_!#%&()+,/:;<=>?@[]^{}~";
257
258 static int s_code_point(const char c) noexcept {
259 if ('0' <= c && c <= '9') {
260 return c - '0';
261 } else if ('a' <= c && c <= 'z') {
262 return c - 'a' + 10;
263 } else if ('A' <= c && c <= 'Z') {
264 return c - 'A' + 36;
265 } else {
266 switch( c ) {
267 case '-': return 62;
268 case '_': return 63;
269 case '!': return 64;
270 case '#': return 65;
271 case '%': return 66;
272 case '&': return 67;
273 case '(': return 68;
274 case ')': return 69;
275 case '+': return 70;
276 case ',': return 71;
277 case '/': return 72;
278 case ':': return 73;
279 case ';': return 74;
280 case '<': return 75;
281 case '=': return 76;
282 case '>': return 77;
283 case '?': return 78;
284 case '@': return 79;
285 case '[': return 80;
286 case ']': return 81;
287 case '^': return 82;
288 case '{': return 83;
289 case '}': return 84;
290 case '~': return 85;
291 default: return -1;
292 }
293 }
294 }
295
296 public:
298 : alphabet("natural86", 86, data, 0, s_code_point) {}
299 };
300
301 /**
302 * Safe base 38 alphabet with ASCII code-point sorting order.
303 *
304 * - Value: `-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_`
305 * - Padding: `=`
306 *
307 * ### Properties
308 * - Base 38
309 * - 7-bit ASCII
310 * - Code page 437 compatible
311 * - Safe URL and filename use
312 * - Excludes forbidden [v]fat chars: `<>:"/\|?*`
313 * - Only using upper-case letters for unique filename under vfat
314 * - Excludes quoting chars: "'$ and space
315 * - Supporting ASCII code-point sorting.
316 * - Order: `-` < `0` < `A` < `a` < `z`
317 */
318 class ascii38_alphabet : public alphabet {
319 private:
320 static inline constexpr const std::string_view data = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
321
322 static int s_code_point(const char c) noexcept {
323 if ('0' <= c && c <= '9') {
324 return c - '0' + 1;
325 } else if ('A' <= c && c <= 'Z') {
326 return c - 'A' + 11;
327 } else if ('-' == c) {
328 return 0;
329 } else if ('_' == c) {
330 return 37;
331 } else {
332 return -1;
333 }
334 }
335
336 public:
338 : alphabet("ascii38", 38, data, '=', s_code_point) {}
339 };
340
341 /**
342 * Safe base 64 alphabet with ASCII code-point sorting order.
343 *
344 * - Value: `-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz`
345 * - Padding: `=`
346 *
347 * ### Properties
348 * - Base 64
349 * - 7-bit ASCII
350 * - Code page 437 compatible
351 * - [`base64url` alphabet](https://www.rfc-editor.org/rfc/rfc4648.html), but different order
352 * - Safe URL and filename use
353 * - Excludes forbidden [v]fat chars: `<>:"/\|?*`
354 * - Excludes quoting chars: "'$ and space
355 * - Supporting ASCII code-point sorting.
356 * - Order: `-` < `0` < `A` < `a` < `z`
357 */
358 class ascii64_alphabet : public alphabet {
359 private:
360 static inline constexpr const std::string_view data = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
361
362 static int s_code_point(const char c) noexcept {
363 if ('0' <= c && c <= '9') {
364 return c - '0' + 1;
365 } else if ('A' <= c && c <= 'Z') {
366 return c - 'A' + 11;
367 } else if ('a' <= c && c <= 'z') {
368 return c - 'a' + 38;
369 } else if ('-' == c) {
370 return 0;
371 } else if ('_' == c) {
372 return 37;
373 } else {
374 return -1;
375 }
376 }
377
378 public:
380 : alphabet("ascii64", 64, data, '=', s_code_point) {}
381 };
382
383 /**
384 * Base 86 alphabet with ASCII code-point sorting order.
385 *
386 * - Value: `!#%&()+,-/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{}~`
387 * - Padding: None
388 *
389 * ### Properties
390 * - Base 86
391 * - 7-bit ASCII
392 * - Code page 437 compatible
393 * - Excludes quoting chars: "'$ and space
394 * - Supporting ASCII code-point sorting.
395 * - Order: `!` < `0` < `:` < `A` < `[` < `a` < `{` < `~`
396 */
397 class ascii86_alphabet : public alphabet {
398 private:
399 static inline constexpr const std::string_view data = "!#%&()+,-/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{}~";
400
401 static int s_code_point(const char c) noexcept {
402 if ('0' <= c && c <= '9') {
403 return c - '0' + 10;
404 } else if ('A' <= c && c <= 'Z') {
405 return c - 'A' + 27;
406 } else if ('a' <= c && c <= 'z') {
407 return c - 'a' + 57;
408 } else {
409 switch( c ) {
410 case '!': return 0;
411 case '#': return 1;
412 case '%': return 2;
413 case '&': return 3;
414 case '(': return 4;
415 case ')': return 5;
416 case '+': return 6;
417 case ',': return 7;
418 case '-': return 8;
419 case '/': return 9;
420
421 case ':': return 20;
422 case ';': return 21;
423 case '<': return 22;
424 case '=': return 23;
425 case '>': return 24;
426 case '?': return 25;
427 case '@': return 26;
428
429 case '[': return 53;
430 case ']': return 54;
431 case '^': return 55;
432 case '_': return 56;
433
434 case '{': return 83;
435 case '}': return 84;
436 case '~': return 85;
437 default: return -1;
438 }
439 }
440 }
441
442 public:
444 : alphabet("ascii86", 86, data, 0, s_code_point) {}
445 };
446
447 /**
448 * Encodes a given positive decimal number to a symbolic string representing a given alphabet and its base.
449 *
450 * Besides using a custom alphabet, the following build-in alphabets are provided
451 * - jau::codec::base::base64_alphabet
452 * - jau::codec::base::base64url_alphabet
453 * - jau::codec::base::natural86_alphabet
454 * - jau::codec::base::ascii64_alphabet
455 * - jau::codec::base::ascii86_alphabet
456 *
457 * @param num a positive decimal number
458 * @param aspec the used alphabet specification
459 * @param min_width minimum width of the encoded string, encoded zero is used for padding
460 * @return the encoded string or an empty string if base exceeds alphabet::max_base() or invalid arguments
461 *
462 * @see encodeBase()
463 * @see decodeBase()
464 */
465 std::string encode(int num, const alphabet& aspec, const unsigned int min_width=0) noexcept;
466
467 /**
468 * Encodes a given positive decimal number to a symbolic string representing a given alphabet and its base.
469 *
470 * Besides using a custom alphabet, the following build-in alphabets are provided
471 * - jau::codec::base::base64_alphabet
472 * - jau::codec::base::base64url_alphabet
473 * - jau::codec::base::natural86_alphabet
474 * - jau::codec::base::ascii64_alphabet
475 * - jau::codec::base::ascii86_alphabet
476 *
477 * @param num a positive decimal number
478 * @param aspec the used alphabet specification
479 * @param min_width minimum width of the encoded string, encoded zero is used for padding
480 * @return the encoded string or an empty string if base exceeds alphabet::max_base() or invalid arguments
481 *
482 * @see encodeBase()
483 * @see decodeBase()
484 */
485 std::string encode(int64_t num, const alphabet& aspec, const unsigned int min_width=0) noexcept;
486
487 /**
488 * Decodes a given symbolic string representing a given alphabet and its base to a positive decimal number.
489 *
490 * Besides using a custom alphabet, the following build-in alphabets are provided
491 * - jau::codec::base::base64_alphabet
492 * - jau::codec::base::base64url_alphabet
493 * - jau::codec::base::natural86_alphabet
494 * - jau::codec::base::ascii64_alphabet
495 * - jau::codec::base::ascii86_alphabet
496 *
497 * @param str an encoded string
498 * @param aspec the used alphabet specification
499 * @return the decoded decimal value or -1 if base exceeds alphabet::max_base(), unknown code-point or invalid arguments
500 *
501 * @see encodeBase()
502 */
503 int64_t decode(const std::string_view& str, const alphabet& aspec) noexcept;
504
505 /**
506 * Encodes given octets using the given alphabet and fixed base 64 encoding
507 * according to `base64` [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648.html).
508 *
509 * An error only occurs if in_len > 0 and resulting encoded string is empty.
510 *
511 * @param in_octets pointer to octets start
512 * @param in_len length of octets in bytes
513 * @param aspec the used base 64 alphabet specification
514 * @return the encoded string, empty if base exceeds alphabet::max_base() or invalid arguments
515 */
516 std::string encode64(const void* in_octets, size_t in_len, const alphabet& aspec) noexcept;
517
518 /**
519 * Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets
520 * according to `base64` [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648.html).
521 *
522 * An error only occurs if the encoded string length > 0 and resulting decoded octets size is empty.
523 *
524 * @param str encoded string
525 * @param aspec the used base 64 alphabet specification
526 * @return the decoded octets, empty if base exceeds alphabet::max_base(), unknown code-point or invalid arguments
527 */
528 std::vector<uint8_t> decode64(const std::string_view& str, const alphabet& aspec) noexcept;
529
530 /**
531 * Inserts a line feed (LF) character `\n` (ASCII 0x0a) after every period of characters.
532 *
533 * @param str the input string of characters, which will be mutated.
534 * @param period period of characters after which one LF will be inserted.
535 * @return count of inserted LF characters
536 */
537 size_t insert_lf(std::string& str, const size_t period) noexcept;
538
539 /**
540 * Removes line feed character from str.
541 *
542 * @param str the input string of characters, which will be mutated.
543 * @return count of removed LF characters
544 */
545 size_t remove_lf(std::string& str) noexcept;
546
547 /**
548 * Encodes given octets using the given alphabet and fixed base 64 encoding
549 * according to `base64` [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648.html)
550 * and adds line-feeds every 64 characters as required for PEM.
551 *
552 * An error only occurs if in_len > 0 and resulting encoded string is empty.
553 *
554 * @param in_octets pointer to octets start
555 * @param in_len length of octets in bytes
556 * @param aspec the used base 64 alphabet specification
557 * @return the encoded string, empty if base exceeds alphabet::max_base() or invalid arguments
558 */
559 inline std::string encode64_pem(const void* in_octets, size_t in_len, const alphabet& aspec) noexcept {
560 std::string e = encode64(in_octets, in_len, aspec);
561 (void)insert_lf(e, 64);
562 return e;
563 }
564
565 /**
566 * Encodes given octets using the given alphabet and fixed base 64 encoding
567 * according to `base64` [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648.html)
568 * and adds line-feeds every 76 characters as required for MIME.
569 *
570 * An error only occurs if in_len > 0 and resulting encoded string is empty.
571 *
572 * @param in_octets pointer to octets start
573 * @param in_len length of octets in bytes
574 * @param aspec the used base 64 alphabet specification
575 * @return the encoded string, empty if base exceeds alphabet::max_base() or invalid arguments
576 */
577 inline std::string encode64_mime(const void* in_octets, size_t in_len, const alphabet& aspec) noexcept {
578 std::string e = encode64(in_octets, in_len, aspec);
579 (void)insert_lf(e, 76);
580 return e;
581 }
582
583 /**
584 * Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets
585 * according to `base64` [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648.html)
586 * and removes all linefeeds before decoding as required for PEM and MIME.
587 *
588 * An error only occurs if the encoded string length > 0 and resulting decoded octets size is empty.
589 *
590 * @param str and encoded string, will be copied
591 * @param aspec the used base 64 alphabet specification
592 * @return the decoded octets, empty if base exceeds alphabet::max_base(), unknown code-point or invalid arguments
593 */
594 inline std::vector<uint8_t> decode64_lf(const std::string_view& str, const alphabet& aspec) noexcept {
595 std::string e(str); // costly copy
596 (void)remove_lf(e);
597 return decode64(e, aspec);
598 }
599
600 /**
601 * Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets
602 * according to `base64` [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648.html)
603 * and removes all linefeeds before decoding as required for PEM and MIME.
604 *
605 * An error only occurs if the encoded string length > 0 and resulting decoded octets size is empty.
606 *
607 * @param str and encoded string, no copy, will be mutated
608 * @param aspec the used base 64 alphabet specification
609 * @return the decoded octets, empty if base exceeds alphabet::max_base(), unknown code-point or invalid arguments
610 */
611 inline std::vector<uint8_t> decode64_lf(std::string& str, const alphabet& aspec) noexcept {
612 (void)remove_lf(str);
613 return decode64(str, aspec);
614 }
615
616 /**@}*/
617
618} // namespace jau::codec::base
619
620/** \example test_intdecstring01.cpp
621 * This C++ unit test validates the jau::to_decstring implementation
622 */
623
624#endif /* JAU_BASE_CODEC_HPP_ */
Base Alphabet Specification providing the alphabet for encode() and decode().
constexpr int base() const noexcept
The fixed base used for this alphabet.
std::string to_string() const noexcept
constexpr int code_point(const char c) const noexcept
Returns the code-point of the given character or -1 if not element of this alphabet.
constexpr char operator[](size_t cp) const noexcept
Retrieve the character at given code-point of this alphabet.
constexpr const std::string_view & symbols() const noexcept
The string of symbols of this alphabet.
alphabet(std::string _name, int _base, std::string_view _symbols, char _padding64, code_point_func _cpf) noexcept
constexpr char padding64() const noexcept
Padding symbol for base <= 64 and block encoding only.
int(* code_point_func)(const char c) noexcept
constexpr const std::string & name() const noexcept
Human readable name for this alphabet instance.
size_t insert_lf(std::string &str, const size_t period) noexcept
Inserts a line feed (LF) character \n (ASCII 0x0a) after every period of characters.
std::string encode(int num, const alphabet &aspec, const unsigned int min_width=0) noexcept
Encodes a given positive decimal number to a symbolic string representing a given alphabet and its ba...
std::string encode64_mime(const void *in_octets, size_t in_len, const alphabet &aspec) noexcept
Encodes given octets using the given alphabet and fixed base 64 encoding according to base64 RFC 4648...
std::string encode64(const void *in_octets, size_t in_len, const alphabet &aspec) noexcept
Encodes given octets using the given alphabet and fixed base 64 encoding according to base64 RFC 4648...
std::vector< uint8_t > decode64(const std::string_view &str, const alphabet &aspec) noexcept
Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets accordi...
std::string encode64_pem(const void *in_octets, size_t in_len, const alphabet &aspec) noexcept
Encodes given octets using the given alphabet and fixed base 64 encoding according to base64 RFC 4648...
std::vector< uint8_t > decode64_lf(const std::string_view &str, const alphabet &aspec) noexcept
Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets accordi...
size_t remove_lf(std::string &str) noexcept
Removes line feed character from str.
int64_t decode(const std::string_view &str, const alphabet &aspec) noexcept
Decodes a given symbolic string representing a given alphabet and its base to a positive decimal numb...
bool operator!=(const alphabet &lhs, const alphabet &rhs) noexcept
std::string to_string(const alphabet &v) noexcept
bool operator==(const alphabet &lhs, const alphabet &rhs) noexcept
Base codecs, i.e.
STL namespace.