Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Replace NULL (or 0) with Q_NULLPTR
Browse files Browse the repository at this point in the history
  • Loading branch information
vitallium authored and ariya committed Jan 16, 2020
1 parent a283cb4 commit cb1b04b
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/childprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ qint64 ChildProcessContext::_write(const QString& chunk, const QString& encoding
QTextCodec* codec = QTextCodec::codecForName(encoding.toLatin1());

// If unavailable, attempt UTF-8 codec
if ((QTextCodec*)NULL == codec) {
if (!codec) {
codec = QTextCodec::codecForName("UTF-8");

// Don't even try to write if UTF-8 codec is unavailable
if ((QTextCodec*)NULL == codec) {
if (!codec) {
return -1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cookiejar.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CookieJar : public QNetworkCookieJar {
Q_PROPERTY(QVariantList cookies READ cookiesToMap WRITE addCookiesFromMap)

public:
CookieJar(QString cookiesFile, QObject* parent = NULL);
CookieJar(QString cookiesFile, QObject* parent = Q_NULLPTR);
virtual ~CookieJar();

bool setCookiesFromUrl(const QList<QNetworkCookie>& cookieList, const QUrl& url);
Expand Down
12 changes: 8 additions & 4 deletions src/encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Encoding::Encoding()
QTextCodec* codec = QTextCodec::codecForName(DEFAULT_CODEC_NAME);

// Fall back to locale codec
if ((QTextCodec*)NULL == codec) {
if (!codec) {
codec = QTextCodec::codecForLocale();
}

Expand All @@ -49,7 +49,11 @@ Encoding::Encoding(const QString& encoding)

Encoding::~Encoding()
{
m_codec = (QTextCodec*)NULL;
if (m_codec) {
// TODO: Encoding class does not inherit QObject, so
// we have to nullifyt m_codec member manually;
m_codec = Q_NULLPTR;
}
}

QString Encoding::decode(const QByteArray& bytes) const
Expand All @@ -73,7 +77,7 @@ void Encoding::setEncoding(const QString& encoding)
if (!encoding.isEmpty()) {
QTextCodec* codec = QTextCodec::codecForName(encoding.toLatin1());

if ((QTextCodec*)NULL != codec) {
if (codec) {
m_codec = codec;
}
}
Expand All @@ -86,7 +90,7 @@ QTextCodec* Encoding::getCodec() const
{
QTextCodec* codec = m_codec;

if ((QTextCodec*)NULL == codec) {
if (!codec) {
codec = QTextCodec::codecForLocale();
}

Expand Down
4 changes: 2 additions & 2 deletions src/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
#include <QString>
#include <QVariantMap>

static Env* env_instance = NULL;
static Env* env_instance = Q_NULLPTR;

Env* Env::instance()
{
if (NULL == env_instance) {
if (!env_instance) {
env_instance = new Env();
}

Expand Down
8 changes: 4 additions & 4 deletions src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void File::close()
if (m_file) {
m_file->close();
delete m_file;
m_file = NULL;
m_file = Q_NULLPTR;
}
deleteLater();
}
Expand All @@ -228,7 +228,7 @@ bool File::setEncoding(const QString& encoding)
}

// "Binary" mode doesn't use/need text codecs
if ((QTextStream*)NULL == m_fileStream) {
if (!m_fileStream) {
// TODO: Should we switch to "text" mode?
return false;
}
Expand All @@ -237,7 +237,7 @@ bool File::setEncoding(const QString& encoding)
// "utf-8"), we need to get the codec in the system first and use its
// canonical name
QTextCodec* codec = QTextCodec::codecForName(encoding.toLatin1());
if ((QTextCodec*)NULL == codec) {
if (!codec) {
return false;
}

Expand All @@ -258,7 +258,7 @@ QString File::getEncoding() const
{
QString encoding;

if ((QTextStream*)NULL != m_fileStream) {
if (m_fileStream) {
encoding = QString(m_fileStream->codec()->name());
}

Expand Down
6 changes: 3 additions & 3 deletions src/networkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const qint64 MAX_REQUEST_POST_BODY_SIZE = 10 * 1000 * 1000;

static const char* toString(QNetworkAccessManager::Operation op)
{
const char* str = 0;
const char* str = Q_NULLPTR;
switch (op) {
case QNetworkAccessManager::HeadOperation:
str = "HEAD";
Expand Down Expand Up @@ -157,7 +157,7 @@ NetworkAccessManager::NetworkAccessManager(QObject* parent, const Config* config
, m_maxAuthAttempts(3)
, m_resourceTimeout(0)
, m_idCounter(0)
, m_networkDiskCache(0)
, m_networkDiskCache(Q_NULLPTR)
, m_sslConfiguration(QSslConfiguration::defaultConfiguration())
{
if (config->diskCacheEnabled()) {
Expand Down Expand Up @@ -242,7 +242,7 @@ void NetworkAccessManager::prepareSslConfiguration(const Config* config)
m_sslConfiguration.setCaCertificates(caCerts);
m_sslConfiguration.setLocalCertificate(clientCert);

QFile* keyFile = NULL;
QFile* keyFile = Q_NULLPTR;
if (config->sslClientKeyFile().isEmpty()) {
keyFile = new QFile(config->sslClientCertificateFile());
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/phantom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#error "This version of QtWebKit is not supported. Please use QtWebKit >= 5.212"
#endif

static Phantom* phantomInstance = NULL;
static Phantom* phantomInstance = Q_NULLPTR;

// private:
Phantom::Phantom(QObject* parent)
Expand Down Expand Up @@ -157,7 +157,7 @@ void Phantom::init()
// public:
Phantom* Phantom::instance()
{
if (NULL == phantomInstance) {
if (!phantomInstance) {
phantomInstance = new Phantom();
phantomInstance->init();
}
Expand Down Expand Up @@ -405,7 +405,7 @@ QString Phantom::proxy()
{
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
if (proxy.hostName().isEmpty()) {
return NULL;
return QString();
}
return proxy.hostName() + ":" + QString::number(proxy.port());
}
Expand Down
2 changes: 1 addition & 1 deletion src/phantom.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public slots:
* @param port The proxy port
* @param proxyType The type of this proxy
*/
void setProxy(const QString& ip, const qint64& port = 80, const QString& proxyType = "http", const QString& user = NULL, const QString& password = NULL);
void setProxy(const QString& ip, const qint64& port = 80, const QString& proxyType = "http", const QString& user = QString(), const QString& password = QString());

QString proxy();

Expand Down
6 changes: 3 additions & 3 deletions src/repl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
// public:
bool REPL::instanceExists()
{
return REPL::getInstance() != NULL;
return REPL::getInstance() != Q_NULLPTR;
}

REPL* REPL::getInstance(QWebFrame* webframe, Phantom* parent)
{
static REPL* singleton = NULL;
static REPL* singleton = Q_NULLPTR;
if (!singleton && webframe && parent) {
// This will create the singleton only when all the parameters are given
singleton = new REPL(webframe, parent);
Expand Down Expand Up @@ -202,7 +202,7 @@ void REPL::startLoop()

// Load REPL history
linenoiseHistoryLoad(m_historyFilepath.data()); //< requires "char *"
while (m_looping && (userInput = linenoise(PROMPT)) != NULL) {
while (m_looping && (userInput = linenoise(PROMPT)) != Q_NULLPTR) {
if (userInput[0] != '\0') {
// Send the user input to the main Phantom frame for evaluation
m_webframe->evaluateJavaScript(
Expand Down
30 changes: 15 additions & 15 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ QString getOSRelease()

System::System(QObject* parent)
: QObject(parent)
, m_stdout((File*)NULL)
, m_stderr((File*)NULL)
, m_stdin((File*)NULL)
, m_stdout(Q_NULLPTR)
, m_stderr(Q_NULLPTR)
, m_stdin(Q_NULLPTR)
{
// Populate "env"
m_env = Env::instance()->asVariantMap();
Expand Down Expand Up @@ -165,17 +165,17 @@ System::System(QObject* parent)
System::~System()
{
// Clean-up standard streams
if ((File*)NULL != m_stdout) {
if (m_stdout) {
delete m_stdout;
m_stdout = (File*)NULL;
m_stdout = Q_NULLPTR;
}
if ((File*)NULL != m_stderr) {
if (m_stderr) {
delete m_stderr;
m_stderr = (File*)NULL;
m_stderr = Q_NULLPTR;
}
if ((File*)NULL != m_stdin) {
if (m_stdin) {
delete m_stdin;
m_stdin = (File*)NULL;
m_stdin = Q_NULLPTR;
}
}

Expand Down Expand Up @@ -211,7 +211,7 @@ bool System::isSSLSupported() const

QObject* System::_stdout()
{
if ((File*)NULL == m_stdout) {
if (!m_stdout) {
QFile* f = new QFile();
f->open(stdout, QIODevice::WriteOnly | QIODevice::Unbuffered);
m_stdout = createFileInstance(f);
Expand All @@ -222,7 +222,7 @@ QObject* System::_stdout()

QObject* System::_stderr()
{
if ((File*)NULL == m_stderr) {
if (!m_stderr) {
QFile* f = new QFile();
f->open(stderr, QIODevice::WriteOnly | QIODevice::Unbuffered);
m_stderr = createFileInstance(f);
Expand All @@ -233,7 +233,7 @@ QObject* System::_stderr()

QObject* System::_stdin()
{
if ((File*)NULL == m_stdin) {
if (!m_stdin) {
QFile* f = new QFile();
f->open(stdin, QIODevice::ReadOnly | QIODevice::Unbuffered);
m_stdin = createFileInstance(f);
Expand All @@ -246,15 +246,15 @@ QObject* System::_stdin()

void System::_onTerminalEncodingChanged(const QString& encoding)
{
if ((File*)NULL != m_stdin) {
if (!m_stdin) {
m_stdin->setEncoding(encoding);
}

if ((File*)NULL != m_stdout) {
if (!m_stdout) {
m_stdout->setEncoding(encoding);
}

if ((File*)NULL != m_stderr) {
if (!m_stderr) {
m_stderr->setEncoding(encoding);
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/webpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CustomPage : public QWebPage {
Q_OBJECT

public:
CustomPage(WebPage* parent = 0)
CustomPage(WebPage* parent = Q_NULLPTR)
: QWebPage(parent)
, m_webPage(parent)
{
Expand Down Expand Up @@ -265,13 +265,13 @@ class WebpageCallbacks : public QObject {
Q_OBJECT

public:
WebpageCallbacks(QObject* parent = 0)
WebpageCallbacks(QObject* parent = Q_NULLPTR)
: QObject(parent)
, m_genericCallback(NULL)
, m_filePickerCallback(NULL)
, m_jsConfirmCallback(NULL)
, m_jsPromptCallback(NULL)
, m_jsInterruptCallback(NULL)
, m_genericCallback(Q_NULLPTR)
, m_filePickerCallback(Q_NULLPTR)
, m_jsConfirmCallback(Q_NULLPTR)
, m_jsPromptCallback(Q_NULLPTR)
, m_jsInterruptCallback(Q_NULLPTR)
{
}

Expand Down Expand Up @@ -1603,7 +1603,7 @@ QObject* WebPage::getPage(const QString& windowName) const
return childPages.at(i);
}
}
return NULL;
return Q_NULLPTR;
}

bool WebPage::ownsPages() const
Expand Down Expand Up @@ -1720,7 +1720,7 @@ void WebPage::switchToMainFrame()

bool WebPage::switchToParentFrame()
{
if (m_currentFrame->parentFrame() != NULL) {
if (m_currentFrame->parentFrame()) {
this->changeCurrentFrame(m_currentFrame->parentFrame());
return true;
}
Expand Down Expand Up @@ -1759,10 +1759,10 @@ static void injectCallbacksObjIntoFrame(QWebFrame* frame, WebpageCallbacks* call

void WebPage::setupFrame(QWebFrame* frame)
{
qDebug() << "WebPage - setupFrame" << (frame == NULL ? "" : frame->frameName());
qDebug() << "WebPage - setupFrame" << (frame == Q_NULLPTR ? "" : frame->frameName());

// Inject the Callbacks object in the main frame
injectCallbacksObjIntoFrame(frame == NULL ? m_mainFrame : frame, m_callbacks);
injectCallbacksObjIntoFrame(frame == Q_NULLPTR ? m_mainFrame : frame, m_callbacks);
}

void WebPage::updateLoadingProgress(int progress)
Expand Down
4 changes: 2 additions & 2 deletions src/webpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public slots:
* @brief getPage
* @param windowName
* @return Returns the page that matches <code>'window.name'</code>,
* or NULL if none is found
* or Q_NULLPTR if none is found
*/
QObject* getPage(const QString& windowName) const;

Expand Down Expand Up @@ -507,7 +507,7 @@ public slots:

private slots:
void finish(bool ok);
void setupFrame(QWebFrame* frame = NULL);
void setupFrame(QWebFrame* frame = Q_NULLPTR);
void updateLoadingProgress(int progress);
void handleRepaintRequested(const QRect& dirtyRect);
void handleUrlChanged(const QUrl& url);
Expand Down
2 changes: 1 addition & 1 deletion src/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool WebServer::listenOnPort(const QString& port, const QVariantMap& opts)
options << "enable_keep_alive"
<< "yes";
}
options << NULL;
options << 0;

// Start the server
m_ctx = mg_start(&callback, this, options.data());
Expand Down

0 comments on commit cb1b04b

Please sign in to comment.