17 using std::from_chars;
21 using std::string_view;
26 bool Integer::is(
const string& str) {
29 trimmedStr.empty() ==
false &&
31 trimmedStr.begin() + (trimmedStr[0] ==
'-'?1:0),
34 return isdigit(c) == 0;
36 ) == trimmedStr.end();
42 trimmedStr.empty() ==
false &&
44 trimmedStr.begin() + (trimmedStr[0] ==
'-'?1:0),
47 return isdigit(c) == 0;
49 ) == trimmedStr.end();
54 if (trimmedStr.empty() ==
true)
return 0;
55 if (trimmedStr ==
"-")
return -0;
56 return stoi(trimmedStr);
61 if (trimmedStr.empty() ==
true)
return 0;
62 if (trimmedStr ==
"-")
return -0;
64 from_chars(&trimmedStr[0], &trimmedStr[trimmedStr.size()], result);
70 char encodingCharSet[] =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW-+/*.";
71 for (
auto i = 0; i < 6; i++) {
72 auto charIdx = (decodedInt >> (i * 6)) & 63;
73 encodedString = encodingCharSet[charIdx] + encodedString;
78 char encodingCharSet[] =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW-+/*.";
80 for (
auto i = 0; i < encodedString.length(); i++) {
82 char c = encodedString[encodedString.length() - i - 1];
83 char* codePtr = strchr(encodingCharSet, c);
84 if (codePtr == NULL) {
87 codeIdx = codePtr - encodingCharSet;
89 decodedInt+= codeIdx << (i * 6);
95 char encodingCharSet[] =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW-+/*.";
97 for (
auto i = 0; i < encodedString.length(); i++) {
99 char c = encodedString[encodedString.length() - i - 1];
100 char* codePtr = strchr(encodingCharSet, c);
101 if (codePtr == NULL) {
104 codeIdx = codePtr - encodingCharSet;
106 decodedInt+= codeIdx << (i * 6);
static bool viewIs(const string_view &str)
Check if given string is a integer string.
static const uint32_t viewDecode(const string_view &encodedString)
Decodes an 6 char string representation to a unsigned 32 bit integer.
static int parse(const string &str)
Parse integer.
static const uint32_t decode(const string &encodedString)
Decodes an 6 char string representation to a unsigned 32 bit integer.
static const string encode(const uint32_t decodedInt)
Encodes an 32 bit unsigned integer to a 6 char string representation.
static int viewParse(const string_view &str)
Parse integer.