mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-14 09:39:11 +00:00
refactor(Core/Misc): add braces and impove codestyle (#6402)
This commit is contained in:
@@ -15,19 +15,19 @@ struct B32Impl
|
||||
static constexpr char Encode(uint8 v)
|
||||
{
|
||||
ASSERT(v < 0x20);
|
||||
if (v < 26) return 'A'+v;
|
||||
else return '2' + (v-26);
|
||||
if (v < 26) { return 'A' + v; }
|
||||
else { return '2' + (v - 26); }
|
||||
}
|
||||
|
||||
static constexpr uint8 DECODE_ERROR = 0xff;
|
||||
static constexpr uint8 Decode(uint8 v)
|
||||
{
|
||||
if (v == '0') return Decode('O');
|
||||
if (v == '1') return Decode('l');
|
||||
if (v == '8') return Decode('B');
|
||||
if (('A' <= v) && (v <= 'Z')) return (v-'A');
|
||||
if (('a' <= v) && (v <= 'z')) return (v-'a');
|
||||
if (('2' <= v) && (v <= '7')) return (v-'2')+26;
|
||||
if (v == '0') { return Decode('O'); }
|
||||
if (v == '1') { return Decode('l'); }
|
||||
if (v == '8') { return Decode('B'); }
|
||||
if (('A' <= v) && (v <= 'Z')) { return (v - 'A'); }
|
||||
if (('a' <= v) && (v <= 'z')) { return (v - 'a'); }
|
||||
if (('2' <= v) && (v <= '7')) { return (v - '2') + 26; }
|
||||
return DECODE_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,21 +15,21 @@ struct B64Impl
|
||||
static constexpr char Encode(uint8 v)
|
||||
{
|
||||
ASSERT(v < 0x40);
|
||||
if (v < 26) return 'A' + v;
|
||||
if (v < 52) return 'a' + (v - 26);
|
||||
if (v < 62) return '0' + (v - 52);
|
||||
if (v == 62) return '+';
|
||||
else return '/';
|
||||
if (v < 26) { return 'A' + v; }
|
||||
if (v < 52) { return 'a' + (v - 26); }
|
||||
if (v < 62) { return '0' + (v - 52); }
|
||||
if (v == 62) { return '+'; }
|
||||
else { return '/'; }
|
||||
}
|
||||
|
||||
static constexpr uint8 DECODE_ERROR = 0xff;
|
||||
static constexpr uint8 Decode(uint8 v)
|
||||
{
|
||||
if (('A' <= v) && (v <= 'Z')) return (v - 'A');
|
||||
if (('a' <= v) && (v <= 'z')) return (v - 'a') + 26;
|
||||
if (('0' <= v) && (v <= '9')) return (v - '0') + 52;
|
||||
if (v == '+') return 62;
|
||||
if (v == '/') return 63;
|
||||
if (('A' <= v) && (v <= 'Z')) { return (v - 'A'); }
|
||||
if (('a' <= v) && (v <= 'z')) { return (v - 'a') + 26; }
|
||||
if (('0' <= v) && (v <= '9')) { return (v - '0') + 52; }
|
||||
if (v == '+') { return 62; }
|
||||
if (v == '/') { return 63; }
|
||||
return DECODE_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,7 +29,9 @@ namespace Acore::Impl
|
||||
{
|
||||
size *= 8; // bits in input
|
||||
if (size % PAD_TO) // pad to boundary
|
||||
{
|
||||
size += (PAD_TO - (size % PAD_TO));
|
||||
}
|
||||
return (size / BITS_PER_CHAR);
|
||||
}
|
||||
|
||||
@@ -37,7 +39,9 @@ namespace Acore::Impl
|
||||
{
|
||||
size *= BITS_PER_CHAR; // bits in input
|
||||
if (size % PAD_TO) // pad to boundary
|
||||
{
|
||||
size += (PAD_TO - (size % PAD_TO));
|
||||
}
|
||||
return (size / 8);
|
||||
}
|
||||
|
||||
@@ -45,7 +49,9 @@ namespace Acore::Impl
|
||||
{
|
||||
auto it = data.begin(), end = data.end();
|
||||
if (it == end)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string s;
|
||||
s.reserve(EncodedSize(data.size()));
|
||||
@@ -57,7 +63,7 @@ namespace Acore::Impl
|
||||
if (bitsLeft >= BITS_PER_CHAR)
|
||||
{
|
||||
bitsLeft -= BITS_PER_CHAR;
|
||||
thisC = ((*it >> bitsLeft) & ((1 << BITS_PER_CHAR)-1));
|
||||
thisC = ((*it >> bitsLeft) & ((1 << BITS_PER_CHAR) - 1));
|
||||
if (!bitsLeft)
|
||||
{
|
||||
++it;
|
||||
@@ -69,7 +75,9 @@ namespace Acore::Impl
|
||||
thisC = (*it & ((1 << bitsLeft) - 1)) << (BITS_PER_CHAR - bitsLeft);
|
||||
bitsLeft += (8 - BITS_PER_CHAR);
|
||||
if ((++it) != end)
|
||||
{
|
||||
thisC |= (*it >> bitsLeft);
|
||||
}
|
||||
}
|
||||
s.append(1, Encoding::Encode(thisC));
|
||||
} while (it != end);
|
||||
@@ -77,9 +85,13 @@ namespace Acore::Impl
|
||||
while (bitsLeft != 8)
|
||||
{
|
||||
if (bitsLeft > BITS_PER_CHAR)
|
||||
{
|
||||
bitsLeft -= BITS_PER_CHAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitsLeft += (8 - BITS_PER_CHAR);
|
||||
}
|
||||
s.append(1, PADDING);
|
||||
}
|
||||
|
||||
@@ -90,7 +102,9 @@ namespace Acore::Impl
|
||||
{
|
||||
auto it = data.begin(), end = data.end();
|
||||
if (it == end)
|
||||
{
|
||||
return std::vector<uint8>();
|
||||
}
|
||||
|
||||
std::vector<uint8> v;
|
||||
v.reserve(DecodedSize(data.size()));
|
||||
@@ -126,15 +140,21 @@ namespace Acore::Impl
|
||||
while ((it != end) && (*it == PADDING) && (bitsLeft != 8))
|
||||
{
|
||||
if (bitsLeft > BITS_PER_CHAR)
|
||||
{
|
||||
bitsLeft -= BITS_PER_CHAR;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitsLeft += (8 - BITS_PER_CHAR);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
// ok, all padding should be consumed, and we should be at end of string
|
||||
if (it == end)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
// anything else is an error
|
||||
return {};
|
||||
|
||||
Reference in New Issue
Block a user