| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- #include <stdint.h>
- #include <stddef.h>
- #include "pokemon_char_encode.h"
- char pokemon_char_to_encoded(int byte) {
- switch(byte) {
- case 'A':
- return A_;
- case 'B':
- return B_;
- case 'C':
- return C_;
- case 'D':
- return D_;
- case 'E':
- return E_;
- case 'F':
- return F_;
- case 'G':
- return G_;
- case 'H':
- return H_;
- case 'I':
- return I_;
- case 'J':
- return J_;
- case 'K':
- return K_;
- case 'L':
- return L_;
- case 'M':
- return M_;
- case 'N':
- return N_;
- case 'O':
- return O_;
- case 'P':
- return P_;
- case 'Q':
- return Q_;
- case 'R':
- return R_;
- case 'S':
- return S_;
- case 'T':
- return T_;
- case 'U':
- return U_;
- case 'V':
- return V_;
- case 'W':
- return W_;
- case 'X':
- return X_;
- case 'Y':
- return Y_;
- case 'Z':
- return Z_;
- case 'a':
- return a_;
- case 'b':
- return b_;
- case 'c':
- return c_;
- case 'd':
- return d_;
- case 'e':
- return e_;
- case 'f':
- return f_;
- case 'g':
- return g_;
- case 'h':
- return h_;
- case 'i':
- return i_;
- case 'j':
- return j_;
- case 'k':
- return k_;
- case 'l':
- return l_;
- case 'm':
- return m_;
- case 'n':
- return n_;
- case 'o':
- return o_;
- case 'p':
- return p_;
- case 'q':
- return q_;
- case 'r':
- return r_;
- case 's':
- return s_;
- case 't':
- return t_;
- case 'u':
- return u_;
- case 'v':
- return v_;
- case 'w':
- return w_;
- case 'x':
- return x_;
- case 'y':
- return y_;
- case 'z':
- return z_;
- case '-':
- return HYPHEN_;
- case '0':
- return _0_;
- case '1':
- return _1_;
- case '2':
- return _2_;
- case '3':
- return _3_;
- case '4':
- return _4_;
- case '5':
- return _5_;
- case '6':
- return _6_;
- case '7':
- return _7_;
- case '8':
- return _8_;
- case '9':
- return _9_;
- /* This was previously implemented with unicode escape codes, however, that
- * seemed to cause compilation issues. Which is strange because others reported
- * compilation issues with the actual unicode characters. I'm not sure a good
- * universal way to resolve this.
- *
- * Additionally, the ♂/♀ symbols don't render properly on the flipper. Would
- * need to create a custom image/icon somehow, otherwise its nonobvious that
- * the traded pokemon would have this symbol in their name.
- */
- case '\201':
- return MALE_;
- case '\200':
- return FEMALE_;
- default:
- return TERM_;
- }
- }
- int pokemon_encoded_to_char(char byte) {
- switch(byte) {
- case A_:
- return 'A';
- case B_:
- return 'B';
- case C_:
- return 'C';
- case D_:
- return 'D';
- case E_:
- return 'E';
- case F_:
- return 'F';
- case G_:
- return 'G';
- case H_:
- return 'H';
- case I_:
- return 'I';
- case J_:
- return 'J';
- case K_:
- return 'K';
- case L_:
- return 'L';
- case M_:
- return 'M';
- case N_:
- return 'N';
- case O_:
- return 'O';
- case P_:
- return 'P';
- case Q_:
- return 'Q';
- case R_:
- return 'R';
- case S_:
- return 'S';
- case T_:
- return 'T';
- case U_:
- return 'U';
- case V_:
- return 'V';
- case W_:
- return 'W';
- case X_:
- return 'X';
- case Y_:
- return 'Y';
- case Z_:
- return 'Z';
- case a_:
- return 'a';
- case b_:
- return 'b';
- case c_:
- return 'c';
- case d_:
- return 'd';
- case e_:
- return 'e';
- case f_:
- return 'f';
- case g_:
- return 'g';
- case h_:
- return 'h';
- case i_:
- return 'i';
- case j_:
- return 'j';
- case k_:
- return 'k';
- case l_:
- return 'l';
- case m_:
- return 'm';
- case n_:
- return 'n';
- case o_:
- return 'o';
- case p_:
- return 'p';
- case q_:
- return 'q';
- case r_:
- return 'r';
- case s_:
- return 's';
- case t_:
- return 't';
- case u_:
- return 'u';
- case v_:
- return 'v';
- case w_:
- return 'w';
- case x_:
- return 'x';
- case y_:
- return 'y';
- case z_:
- return 'z';
- case HYPHEN_:
- return '-';
- case _0_:
- return '0';
- case _1_:
- return '1';
- case _2_:
- return '2';
- case _3_:
- return '3';
- case _4_:
- return '4';
- case _5_:
- return '5';
- case _6_:
- return '6';
- case _7_:
- return '7';
- case _8_:
- return '8';
- case _9_:
- return '9';
- /* This was previously implemented with unicode escape codes, however, that
- * seemed to cause compilation issues. Which is strange because others reported
- * compilation issues with the actual unicode characters. I'm not sure a good
- * universal way to resolve this.
- *
- * Additionally, the ♂/♀ symbols don't render properly on the flipper. Would
- * need to create a custom image/icon somehow, otherwise its nonobvious that
- * the traded pokemon would have this symbol in their name.
- */
- case MALE_:
- return '\201';
- case FEMALE_:
- return '\200';
- default:
- return '\0';
- }
- }
- /* encode n bytes, any currently noninputtable characters are set with TERM_ */
- void pokemon_str_to_encoded_array(uint8_t* dest, char* src, size_t n) {
- for(; n > 0; n--) {
- *dest = pokemon_char_to_encoded(*src);
- dest++;
- src++;
- }
- }
- /* decode n bytes, any currently noninputtable characters are set with '\0' */
- void pokemon_encoded_array_to_str(char* dest, uint8_t* src, size_t n) {
- for(; n > 0; n--) {
- *dest = pokemon_encoded_to_char(*src);
- dest++;
- src++;
- }
- }
|