Merge pull request 'добавил const для части контейнеров и explicit для конструкторов' (#176) from const_explicit into master
Reviewed-on: https://git.shs.tools/SHS/pip/pulls/176
This commit was merged in pull request #176.
This commit is contained in:
@@ -143,7 +143,8 @@ PIByteArray PIByteArray::toBase64() const {
|
||||
if (isEmpty()) return PIByteArray();
|
||||
base64HelpStruct hs;
|
||||
PIByteArray ret;
|
||||
int sz = (size_s() / 3) * 3, ri = -1;
|
||||
const int sz = (size_s() / 3) * 3;
|
||||
int ri = -1;
|
||||
uchar t[4];
|
||||
ret.resize(((size_s() - 1) / 3 + 1) * 4);
|
||||
for (int i = 0; i < sz; i += 3) {
|
||||
@@ -154,7 +155,7 @@ PIByteArray PIByteArray::toBase64() const {
|
||||
ret[++ri] = (t[2]);
|
||||
ret[++ri] = (t[3]);
|
||||
}
|
||||
int der = size_s() % 3;
|
||||
const int der = size_s() % 3;
|
||||
switch (der) {
|
||||
case 1:
|
||||
hs.setBytes(data(sz), 1);
|
||||
@@ -182,7 +183,8 @@ PIByteArray PIByteArray::fromBase64(const PIByteArray & base64) {
|
||||
if (base64.isEmpty()) return PIByteArray();
|
||||
base64HelpStruct hs;
|
||||
PIByteArray ret;
|
||||
int sz = base64.size_s(), ind = -1;
|
||||
const int sz = base64.size_s();
|
||||
int ind = -1;
|
||||
uchar t[4];
|
||||
ret.resize(sz / 4 * 3);
|
||||
for (int i = 0; i < sz; i += 4) {
|
||||
@@ -206,7 +208,9 @@ PIByteArray PIByteArray::fromBase64(const PIString & base64) {
|
||||
|
||||
PIByteArray & PIByteArray::compressRLE(uchar threshold) {
|
||||
PIByteArray t;
|
||||
uchar fb, clen, mlen = 255 - threshold;
|
||||
uchar fb;
|
||||
uchar clen;
|
||||
const uchar mlen = 255 - threshold;
|
||||
for (uint i = 0; i < size();) {
|
||||
fb = at(i);
|
||||
clen = 1;
|
||||
@@ -232,7 +236,8 @@ PIByteArray & PIByteArray::compressRLE(uchar threshold) {
|
||||
|
||||
PIByteArray & PIByteArray::decompressRLE(uchar threshold) {
|
||||
PIByteArray t;
|
||||
uchar fb, clen;
|
||||
uchar fb;
|
||||
uchar clen;
|
||||
for (uint i = 0; i < size(); ++i) {
|
||||
fb = at(i);
|
||||
if (fb >= threshold) {
|
||||
@@ -263,8 +268,8 @@ PIByteArray & PIByteArray::decompressRLE(uchar threshold) {
|
||||
//! else return sum;
|
||||
//! \endcode
|
||||
uchar PIByteArray::checksumPlain8(bool inverse) const {
|
||||
uchar c = 0;
|
||||
int sz = size_s();
|
||||
uchar c = 0;
|
||||
const int sz = size_s();
|
||||
for (int i = 0; i < sz; ++i)
|
||||
c += at(i);
|
||||
if (inverse) c = ~(c + 1);
|
||||
@@ -299,8 +304,8 @@ uint PIByteArray::checksumCRC32() const {
|
||||
//! else return sum;
|
||||
//! \endcode
|
||||
uint PIByteArray::checksumPlain32(bool inverse) const {
|
||||
uint c = 0;
|
||||
int sz = size_s();
|
||||
uint c = 0;
|
||||
const int sz = size_s();
|
||||
for (int i = 0; i < sz; ++i)
|
||||
c += at(i) * (i + 1);
|
||||
if (inverse) c = ~(c + 1);
|
||||
@@ -315,7 +320,7 @@ uint PIByteArray::hash() const {
|
||||
|
||||
PIString PIByteArray::toString(int base) const {
|
||||
PIString ret;
|
||||
int sz = size_s();
|
||||
const int sz = size_s();
|
||||
for (int i = 0; i < sz; ++i) {
|
||||
if (i > 0) ret += " ";
|
||||
if (base == 2) ret += "b";
|
||||
@@ -343,7 +348,7 @@ PIString PIByteArray::toHex() const {
|
||||
else
|
||||
hexData[i * 2 + 1] = (j + 'a' - 10);
|
||||
}
|
||||
return PIString(hex);
|
||||
return PIString::fromAscii(hex);
|
||||
}
|
||||
|
||||
|
||||
@@ -351,10 +356,10 @@ PIByteArray PIByteArray::fromUserInput(PIString str) {
|
||||
PIByteArray ret;
|
||||
if (str.trim().isEmpty()) return ret;
|
||||
str.replaceAll("\n", " ").replaceAll("\t", " ").replaceAll(" ", " ");
|
||||
PIStringList bl(str.split(" "));
|
||||
const PIStringList bl(str.split(" "));
|
||||
bool ok(false);
|
||||
piForeachC(PIString & b, bl) {
|
||||
int bv = b.toInt(-1, &ok);
|
||||
for (const auto & b: bl) {
|
||||
const int bv = b.toInt(-1, &ok);
|
||||
if (ok) ret << uchar(bv);
|
||||
}
|
||||
return ret;
|
||||
@@ -362,7 +367,7 @@ PIByteArray PIByteArray::fromUserInput(PIString str) {
|
||||
|
||||
|
||||
PIByteArray PIByteArray::fromHex(PIString str) {
|
||||
PIByteArray hexEncoded = str.toByteArray();
|
||||
const PIByteArray hexEncoded = str.toByteArray();
|
||||
PIByteArray res((hexEncoded.size() + 1) / 2);
|
||||
uchar * result = res.data() + res.size();
|
||||
bool odd_digit = true;
|
||||
|
||||
@@ -53,14 +53,14 @@ public:
|
||||
|
||||
//! \~english Constructs copy of byte array "o"
|
||||
//! \~russian Создает копию байтового массива "o"
|
||||
PIByteArray(const PIDeque<uchar> & o): d(o) {}
|
||||
explicit PIByteArray(const PIDeque<uchar> & o): d(o) {}
|
||||
|
||||
PIByteArray(PIByteArray && o): d(std::move(o.d)) {}
|
||||
PIByteArray(PIDeque<uchar> && o): d(std::move(o)) {}
|
||||
|
||||
//! \~english Constructs 0-filled byte array with size "size"
|
||||
//! \~russian Создает заполненный "0" байтовый массив размером "size"
|
||||
PIByteArray(const uint size) { resize(size); }
|
||||
explicit PIByteArray(const uint size) { resize(size); }
|
||||
|
||||
//! \~english Constructs byte array from data "data" and size "size"
|
||||
//! \~russian Создает байтовый массив из данных по указателю "data" размером "size"
|
||||
@@ -784,7 +784,7 @@ public:
|
||||
//! \~english Add to the end data "data" with size "size"
|
||||
//! \~russian Добавляет в конец массива данные по указателю "data" размером "size"
|
||||
PIByteArray & push_back(const void * data_, int size_) {
|
||||
uint ps = size();
|
||||
const uint ps = size();
|
||||
enlarge(size_);
|
||||
memcpy(data(ps), data_, size_);
|
||||
return *this;
|
||||
@@ -1083,7 +1083,7 @@ public:
|
||||
//! \~english Add to the end data "data" with size "size"
|
||||
//! \~russian Добавляет в конец массива данные по указателю "data" размером "size"
|
||||
PIByteArray & append(const void * data_, int size_) {
|
||||
uint ps = size();
|
||||
const uint ps = size();
|
||||
enlarge(size_);
|
||||
memcpy(data(ps), data_, size_);
|
||||
return *this;
|
||||
@@ -1092,7 +1092,7 @@ public:
|
||||
//! \~english Add to the end byte array "data"
|
||||
//! \~russian Добавляет в конец массива содержимое массива "data"
|
||||
PIByteArray & append(const PIByteArray & data_) {
|
||||
uint ps = size();
|
||||
const uint ps = size();
|
||||
enlarge(data_.size_s());
|
||||
memcpy(data(ps), data_.data(), data_.size());
|
||||
return *this;
|
||||
@@ -1176,8 +1176,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
bool binaryStreamTakeImp(void * d_, size_t s) {
|
||||
size_t rs = size();
|
||||
if (rs > s) rs = s;
|
||||
const size_t rs = s < size() ? s : size();
|
||||
memcpy(d_, data(), rs);
|
||||
remove(0, rs);
|
||||
return rs == s;
|
||||
|
||||
Reference in New Issue
Block a user