Skip to content

Commit 9fef966

Browse files
committed
Using QString instead std::u16string.
1 parent 5e63cba commit 9fef966

File tree

202 files changed

+4284
-3966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+4284
-3966
lines changed

source/base/codec/webm_file_writer.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
namespace base {
3131

3232
//--------------------------------------------------------------------------------------------------
33-
WebmFileWriter::WebmFileWriter(const std::filesystem::path& path, std::u16string_view name)
33+
WebmFileWriter::WebmFileWriter(const std::filesystem::path& path, const QString& name)
3434
: path_(path),
3535
name_(name)
3636
{
@@ -184,7 +184,7 @@ bool WebmFileWriter::init()
184184
SystemTime time = SystemTime::now();
185185
std::ostringstream file_name;
186186

187-
file_name << base::utf8FromUtf16(name_.c_str()) << '-'
187+
file_name << name_.toUtf8().data() << '-'
188188
<< std::setfill('0')
189189
<< std::setw(4) << time.year()
190190
<< std::setw(2) << time.month()

source/base/codec/webm_file_writer.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929
#include <memory>
3030
#include <optional>
3131

32+
#include <QString>
33+
3234
namespace base {
3335

3436
class WebmFileMuxer;
3537

3638
class WebmFileWriter
3739
{
3840
public:
39-
WebmFileWriter(const std::filesystem::path& path, std::u16string_view name);
41+
WebmFileWriter(const std::filesystem::path& path, const QString& name);
4042
~WebmFileWriter();
4143

4244
void addVideoPacket(const proto::VideoPacket& packet);
@@ -47,7 +49,7 @@ class WebmFileWriter
4749
void close();
4850

4951
std::filesystem::path path_;
50-
std::u16string name_;
52+
QString name_;
5153
int file_counter_ = 0;
5254
FILE* file_ = nullptr;
5355

source/base/codec/zstd_compress.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ T compressT(const T& source, int compress_level)
5454
const size_t output_size = ZSTD_compressBound(input_size);
5555

5656
T target;
57-
target.resize(output_size + sizeof(uint32_t));
57+
target.resize(static_cast<T::size_type>(output_size + sizeof(uint32_t)));
5858

5959
source_data_size = EndianUtil::toBig(source_data_size);
6060
memcpy(target.data(), &source_data_size, sizeof(uint32_t));
@@ -116,7 +116,7 @@ T decompressT(const T& source)
116116
}
117117

118118
ZSTD_inBuffer input = { source.data() + sizeof(uint32_t), source.size() - sizeof(uint32_t), 0 };
119-
ZSTD_outBuffer output = { target.data(), target.size(), 0 };
119+
ZSTD_outBuffer output = { target.data(), static_cast<size_t>(target.size()), 0 };
120120

121121
while (input.pos < input.size)
122122
{

source/base/converter.h

+16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <optional>
3030

3131
#include <QByteArray>
32+
#include <QString>
3233

3334
namespace base {
3435

@@ -100,6 +101,21 @@ struct ConverterImpl<QByteArray>
100101
}
101102
};
102103

104+
template <>
105+
struct ConverterImpl<QString>
106+
{
107+
static bool fromString(std::string_view str, QString* value)
108+
{
109+
*value = QString::fromUtf8(str.data(), static_cast<QString::size_type>(str.size()));
110+
return true;
111+
}
112+
113+
static std::string toString(const QString& value)
114+
{
115+
return value.toStdString();
116+
}
117+
};
118+
103119
template <>
104120
struct ConverterImpl<std::filesystem::path>
105121
{

source/base/crypto/password_generator.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
#include <algorithm>
2222
#include <random>
23-
#include <vector>
2423

2524
namespace base {
2625

2726
const uint32_t PasswordGenerator::kDefaultCharacters = UPPER_CASE | LOWER_CASE | DIGITS;
28-
const size_t PasswordGenerator::kDefaultLength = 8;
27+
const QString::size_type PasswordGenerator::kDefaultLength = 8;
2928

3029
//--------------------------------------------------------------------------------------------------
3130
void PasswordGenerator::setCharacters(uint32_t value)
@@ -35,14 +34,14 @@ void PasswordGenerator::setCharacters(uint32_t value)
3534
}
3635

3736
//--------------------------------------------------------------------------------------------------
38-
void PasswordGenerator::setLength(size_t value)
37+
void PasswordGenerator::setLength(QString::size_type value)
3938
{
4039
if (value)
4140
length_ = value;
4241
}
4342

4443
//--------------------------------------------------------------------------------------------------
45-
std::string PasswordGenerator::result() const
44+
QString PasswordGenerator::result() const
4645
{
4746
constexpr std::string_view lower_case = "abcdefghijklmnopqrstuvwxyz";
4847
constexpr std::string_view upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -78,10 +77,10 @@ std::string PasswordGenerator::result() const
7877

7978
std::uniform_int_distribution<> uniform_distance(0, static_cast<int>(table.size() - 1));
8079

81-
std::string result;
80+
QString result;
8281
result.resize(length_);
8382

84-
for (size_t i = 0; i < length_; ++i)
83+
for (QString::size_type i = 0; i < length_; ++i)
8584
result[i] = table[static_cast<size_t>(uniform_distance(engine))];
8685

8786
return result;

source/base/crypto/password_generator.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "base/macros_magic.h"
2323

2424
#include <cstdint>
25-
#include <string>
25+
#include <QString>
2626

2727
namespace base {
2828

@@ -40,19 +40,19 @@ class PasswordGenerator
4040
};
4141

4242
static const uint32_t kDefaultCharacters;
43-
static const size_t kDefaultLength;
43+
static const QString::size_type kDefaultLength;
4444

4545
void setCharacters(uint32_t value);
4646
uint32_t characters() const { return characters_; }
4747

48-
void setLength(size_t value);
49-
size_t length() const { return length_; }
48+
void setLength(QString::size_type value);
49+
QString::size_type length() const { return length_; }
5050

51-
std::string result() const;
51+
QString result() const;
5252

5353
private:
5454
uint32_t characters_ = kDefaultCharacters;
55-
size_t length_ = kDefaultLength;
55+
QString::size_type length_ = kDefaultLength;
5656

5757
DISALLOW_COPY_AND_ASSIGN(PasswordGenerator);
5858
};

source/base/crypto/password_hash.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace {
2828

2929
//--------------------------------------------------------------------------------------------------
3030
template <typename InputT, typename OutputT>
31-
OutputT hashT(PasswordHash::Type type, std::string_view password, InputT salt)
31+
OutputT hashT(PasswordHash::Type type, const QString& password, InputT salt)
3232
{
3333
DCHECK_EQ(type, PasswordHash::Type::SCRYPT);
3434

@@ -48,7 +48,9 @@ OutputT hashT(PasswordHash::Type type, std::string_view password, InputT salt)
4848
OutputT result;
4949
result.resize(PasswordHash::kBytesSize);
5050

51-
int ret = EVP_PBE_scrypt(password.data(), password.size(),
51+
QByteArray password_utf8 = password.toUtf8();
52+
53+
int ret = EVP_PBE_scrypt(password_utf8.data(), password_utf8.size(),
5254
reinterpret_cast<const uint8_t*>(salt.data()), salt.size(),
5355
N, r, p, max_mem,
5456
reinterpret_cast<uint8_t*>(result.data()), result.size());
@@ -61,14 +63,14 @@ OutputT hashT(PasswordHash::Type type, std::string_view password, InputT salt)
6163

6264
//--------------------------------------------------------------------------------------------------
6365
// static
64-
QByteArray PasswordHash::hash(Type type, std::string_view password, const QByteArray& salt)
66+
QByteArray PasswordHash::hash(Type type, const QString& password, const QByteArray& salt)
6567
{
6668
return hashT<const QByteArray, QByteArray>(type, password, salt);
6769
}
6870

6971
//--------------------------------------------------------------------------------------------------
7072
// static
71-
std::string PasswordHash::hash(Type type, std::string_view password, std::string_view salt)
73+
std::string PasswordHash::hash(Type type, const QString& password, std::string_view salt)
7274
{
7375
return hashT<std::string_view, std::string>(type, password, salt);
7476
}

source/base/crypto/password_hash.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class PasswordHash
3434
static const size_t kBitsSize = 256;
3535
static const size_t kBytesSize = kBitsSize / kBitsPerByte;
3636

37-
static QByteArray hash(Type type, std::string_view password, const QByteArray& salt);
38-
static std::string hash(Type type, std::string_view password, std::string_view salt);
37+
static QByteArray hash(Type type, const QString& password, const QByteArray& salt);
38+
static std::string hash(Type type, const QString& password, std::string_view salt);
3939

4040
private:
4141
DISALLOW_COPY_AND_ASSIGN(PasswordHash);

source/base/crypto/srp_math.cc

+16-18
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
#include "base/logging.h"
2222
#include "base/crypto/generic_hash.h"
23-
#include "base/strings/string_util.h"
24-
#include "base/strings/unicode.h"
2523

2624
#include <openssl/opensslv.h>
2725
#include <openssl/bn.h>
@@ -166,33 +164,33 @@ BigNum SrpMath::calc_B(const BigNum& b, const BigNum& N, const BigNum& g, const
166164
//--------------------------------------------------------------------------------------------------
167165
// static
168166
// x = BLAKE2b512(s | BLAKE2b512(I | ":" | p))
169-
BigNum SrpMath::calc_x(const BigNum& s, std::u16string_view I, std::u16string_view p)
167+
BigNum SrpMath::calc_x(const BigNum& s, const QString& I, const QString& p)
170168
{
171-
if (!s.isValid() || I.empty() || p.empty())
169+
if (!s.isValid() || I.isEmpty() || p.isEmpty())
172170
{
173-
LOG(LS_ERROR) << "Invalid arguments (s=" << s.isValid() << " I=" << I.empty()
174-
<< " p=" << p.empty() << ")";
171+
LOG(LS_ERROR) << "Invalid arguments (s=" << s.isValid() << " I=" << I.isEmpty()
172+
<< " p=" << p.isEmpty() << ")";
175173
return BigNum();
176174
}
177175

178-
return calc_x(s, I, QByteArray::fromStdString(utf8FromUtf16(p)));
176+
return calc_x(s, I, p.toUtf8());
179177
}
180178

181179
//--------------------------------------------------------------------------------------------------
182180
// static
183-
BigNum SrpMath::calc_x(const BigNum& s, std::u16string_view I, const QByteArray& p)
181+
BigNum SrpMath::calc_x(const BigNum& s, const QString& I, const QByteArray& p)
184182
{
185-
if (!s.isValid() || I.empty() || p.isEmpty())
183+
if (!s.isValid() || I.isEmpty() || p.isEmpty())
186184
{
187-
LOG(LS_ERROR) << "Invalid arguments (s=" << s.isValid() << " I=" << I.empty()
185+
LOG(LS_ERROR) << "Invalid arguments (s=" << s.isValid() << " I=" << I.isEmpty()
188186
<< " p=" << p.isEmpty() << ")";
189187
return BigNum();
190188
}
191189

192190
GenericHash hash(GenericHash::BLAKE2b512);
193191

194-
hash.addData(utf8FromUtf16(toLower(I)));
195-
hash.addData(std::string_view(":"));
192+
hash.addData(I.toLower().toUtf8());
193+
hash.addData(QByteArray(":"));
196194
hash.addData(p);
197195

198196
QByteArray temp = hash.result();
@@ -408,12 +406,12 @@ bool SrpMath::verify_A_mod_N(const BigNum& A, const BigNum& N)
408406

409407
//--------------------------------------------------------------------------------------------------
410408
// static
411-
BigNum SrpMath::calc_v(std::u16string_view I, std::u16string_view p, const BigNum& s,
409+
BigNum SrpMath::calc_v(const QString& I, const QString& p, const BigNum& s,
412410
const BigNum& N, const BigNum& g)
413411
{
414-
if (I.empty() || p.empty() || !N.isValid() || !g.isValid() || !s.isValid())
412+
if (I.isEmpty() || p.isEmpty() || !N.isValid() || !g.isValid() || !s.isValid())
415413
{
416-
LOG(LS_ERROR) << "Invalid arguments (I=" << I.empty() << " p=" << p.empty()
414+
LOG(LS_ERROR) << "Invalid arguments (I=" << I.isEmpty() << " p=" << p.isEmpty()
417415
<< " N=" << N.isValid() << " g=" << g.isValid() << " s=" << s.isValid() << ")";
418416
return BigNum();
419417
}
@@ -440,12 +438,12 @@ BigNum SrpMath::calc_v(std::u16string_view I, std::u16string_view p, const BigNu
440438

441439
//--------------------------------------------------------------------------------------------------
442440
// static
443-
BigNum SrpMath::calc_v(std::u16string_view I, const QByteArray& p, const BigNum& s,
441+
BigNum SrpMath::calc_v(const QString& I, const QByteArray& p, const BigNum& s,
444442
const BigNum& N, const BigNum& g)
445443
{
446-
if (I.empty() || p.isEmpty() || !N.isValid() || !g.isValid() || !s.isValid())
444+
if (I.isEmpty() || p.isEmpty() || !N.isValid() || !g.isValid() || !s.isValid())
447445
{
448-
LOG(LS_ERROR) << "Invalid arguments (I=" << I.empty() << " p=" << p.isEmpty()
446+
LOG(LS_ERROR) << "Invalid arguments (I=" << I.isEmpty() << " p=" << p.isEmpty()
449447
<< " N=" << N.isValid() << " g=" << g.isValid() << " s=" << s.isValid() << ")";
450448
return BigNum();
451449
}

source/base/crypto/srp_math.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "base/crypto/big_num.h"
2323

2424
#include <QByteArray>
25+
#include <QString>
2526

2627
namespace base {
2728

@@ -43,8 +44,8 @@ class SrpMath
4344

4445
static BigNum calc_u(const BigNum& A, const BigNum& B, const BigNum& N);
4546
static BigNum calc_B(const BigNum& b, const BigNum& N, const BigNum& g, const BigNum& v);
46-
static BigNum calc_x(const BigNum& s, std::u16string_view I, std::u16string_view p);
47-
static BigNum calc_x(const BigNum& s, std::u16string_view I, const QByteArray& p);
47+
static BigNum calc_x(const BigNum& s, const QString& I, const QString& p);
48+
static BigNum calc_x(const BigNum& s, const QString& I, const QByteArray& p);
4849
static BigNum calc_A(const BigNum& a, const BigNum& N, const BigNum& g);
4950

5051
static BigNum calcServerKey(const BigNum& A, const BigNum& v, const BigNum& u, const BigNum& b,
@@ -59,10 +60,10 @@ class SrpMath
5960
// Checks if A % N == 0.
6061
static bool verify_A_mod_N(const BigNum& A, const BigNum& N);
6162

62-
static BigNum calc_v(std::u16string_view I, std::u16string_view p, const BigNum& s,
63+
static BigNum calc_v(const QString& I, const QString& p, const BigNum& s,
6364
const BigNum& N, const BigNum& g);
6465

65-
static BigNum calc_v(const std::u16string_view I, const QByteArray& p, const BigNum& s,
66+
static BigNum calc_v(const QString& I, const QByteArray& p, const BigNum& s,
6667
const BigNum& N, const BigNum& g);
6768

6869
private:

source/base/desktop/win/dxgi_output_duplicator.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ bool DxgiOutputDuplicator::duplicate(
250250
DXGI_OUTDUPL_POINTER_SHAPE_INFO* shape_info = cursor->pointerShapeInfo();
251251
QByteArray* buffer = cursor->pointerShapeBuffer();
252252

253-
if (buffer->capacity() < frame_info.PointerShapeBufferSize)
254-
buffer->reserve(frame_info.PointerShapeBufferSize);
253+
if (buffer->capacity() < static_cast<QByteArray::size_type>(frame_info.PointerShapeBufferSize))
254+
buffer->reserve(static_cast<QByteArray::size_type>(frame_info.PointerShapeBufferSize));
255255

256-
buffer->resize(frame_info.PointerShapeBufferSize);
256+
buffer->resize(static_cast<QByteArray::size_type>(frame_info.PointerShapeBufferSize));
257257

258258
UINT buffer_required;
259259
_com_error hr = duplication_->GetFramePointerShape(frame_info.PointerShapeBufferSize,

0 commit comments

Comments
 (0)