|
1 | 1 | // |
2 | | -// format-cards.c |
| 2 | +// format-cards.cpp |
3 | 3 | // |
4 | 4 | // Copyright © 2020 by Blockchain Commons, LLC |
5 | 5 | // Licensed under the "BSD-2-Clause Plus Patent License" |
6 | 6 | // |
7 | 7 |
|
8 | | -#include "format-cards.h" |
| 8 | +#include "format-cards.hpp" |
9 | 9 |
|
10 | 10 | #include <strings.h> |
11 | 11 |
|
12 | | -#include "params.h" |
13 | | -#include "utils.h" |
| 12 | +#include "params.hpp" |
| 13 | +#include "utils.hpp" |
14 | 14 |
|
15 | | -static const char* card_suits[] = { "c", "d", "h", "s" }; |
16 | | -static const char* card_ranks[] = { "a", "2", "3", "4", "5", "6", "7", "8", "9", "t", "j", "q", "k"}; |
| 15 | +static const std::string card_suits[] = { "c", "d", "h", "s" }; |
| 16 | +static const std::string card_ranks[] = { "a", "2", "3", "4", "5", "6", "7", "8", "9", "t", "j", "q", "k"}; |
17 | 17 |
|
18 | | -static char* to_card(size_t n) { |
| 18 | +static std::string to_card(size_t n) { |
19 | 19 | if(n > 51) { return NULL; } |
20 | | - char* buf = (char*)malloc(3); |
| 20 | + std::string buf; |
21 | 21 | size_t rank = n % 13; |
22 | 22 | size_t suit = n / 13; |
23 | | - const char* rank_string = card_ranks[rank]; |
24 | | - const char* suit_string = card_suits[suit]; |
25 | | - strcpy(buf, rank_string); |
26 | | - strcat(buf, suit_string); |
| 23 | + buf.append(card_ranks[rank]); |
| 24 | + buf.append(card_suits[suit]); |
27 | 25 | return buf; |
28 | 26 | } |
29 | 27 |
|
30 | | -void format_cards_process_output(format* f, params* p) { |
31 | | - p->output = data_to_alphabet(p->seed, p->seed_len, 52, to_card); |
| 28 | +static void format_cards_process_output(format* f, params* p) { |
| 29 | + p->output = data_to_alphabet(p->seed, 52, to_card); |
32 | 30 | } |
33 | 31 |
|
34 | 32 | static void format_cards_dispose(format* f) { |
|
0 commit comments