Use array map instead of find string position.
Test code snippet:
0
1#include <assert.h>
2#include <stdint.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6#include <string>
7
8int main(int argc, const char * argv[]) {
9
10 static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
11 static const int8_t mapBase58[] = {
12 -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
13 -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
14 -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
15 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1,
16 -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1,
17 22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1,
18 -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46,
19 47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1,
20 };
21
22 const std::string b58Str(pszBase58);
23
24 for (size_t i = 0; i < b58Str.length(); i++) {
25 const char *ch = strchr(pszBase58, b58Str[i]);
26 printf("%d - %d\n", ch - pszBase58, mapBase58[(uint8_t)b58Str[i]]);
27 assert(ch - pszBase58 == mapBase58[(uint8_t)b58Str[i]]);
28 }
29
30 assert(mapBase58['1'] == 0);
31 assert(mapBase58['z'] == 57);
32
33 /** All alphanumeric characters except for "0", "I", "O", and "l" */
34 assert(mapBase58['0'] == -1);
35 assert(mapBase58['I'] == -1);
36 assert(mapBase58['O'] == -1);
37 assert(mapBase58['l'] == -1);
38
39 return 0;
40}