Skip to content

Commit

Permalink
More string tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Jul 22, 2023
1 parent 520cc55 commit 66cc203
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 59 deletions.
18 changes: 10 additions & 8 deletions lib/core/include/qx/core/qx-base85.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <QHash>
#include <QSet>

using namespace Qt::Literals::StringLiterals;

namespace Qx
{

Expand Down Expand Up @@ -147,12 +149,12 @@ class QX_CORE_EXPORT Base85ParseError
//-Class Variables------------------------------------------------------------------------------------------------------
private:
static inline const QHash<ParseError, QString> ERROR_STR_MAP{
{NoError, QStringLiteral("No error occurred.")},
{InvalidEncoding, QStringLiteral("The provided encoding is invalid.")},
{PaddingRequired, QStringLiteral("The string makes use of padding, but the specified encoding does not support padding.")},
{NonANSI, QStringLiteral("The string contains characters that are wider than a single byte.")},
{CharacterSetMismatch, QStringLiteral("The string contains characters that are not present in the specified encoding's character set.")},
{ShortcutMidFrame, QStringLiteral("A shortcut character appears in the middle of one of the string's 5-character ASCII frames.")},
{NoError, u"No error occurred."_s},
{InvalidEncoding, u"The provided encoding is invalid."_s},
{PaddingRequired, u"The string makes use of padding, but the specified encoding does not support padding."_s},
{NonANSI, u"The string contains characters that are wider than a single byte."_s},
{CharacterSetMismatch, u"The string contains characters that are not present in the specified encoding's character set."_s},
{ShortcutMidFrame, u"A shortcut character appears in the middle of one of the string's 5-character ASCII frames."_s},
};

//-Instance Variables------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -180,8 +182,8 @@ class QX_CORE_EXPORT Base85
static constexpr char ENCODE_PAD_CHAR = '\0';

// Shortcut Frames
static inline const QByteArray ZERO_GROUP_FRAME = QByteArrayLiteral("\x00\x00\x00\x00");
static inline const QByteArray SPACE_GROUP_FRAME = QByteArrayLiteral("\x20\x20\x20\x20");
static inline const QByteArray ZERO_GROUP_FRAME = "\x00\x00\x00\x00"_ba;
static inline const QByteArray SPACE_GROUP_FRAME = "\x20\x20\x20\x20"_ba;

// Decode
static constexpr quint32 POWERS_OF_85[] = {
Expand Down
12 changes: 7 additions & 5 deletions lib/core/include/qx/core/qx-dsvtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// Intra-component Includes
#include "qx/core/qx-table.h"

using namespace Qt::Literals::StringLiterals;

namespace Qx
{

Expand All @@ -29,11 +31,11 @@ class QX_CORE_EXPORT DsvParseError
//-Class Variables------------------------------------------------------------------------------------------------------
private:
static inline const QHash<ParseError, QString> ERROR_STR_MAP{
{NoError, QStringLiteral("No error occurred.")},
{IllegalEscape, QStringLiteral("Illegal use of an escape character.")},
{UnterminatedField, QStringLiteral("An escaped field was not properly terminated.")},
{UnevenColumns, QStringLiteral("A row contained a different number of fields than the header row.")},
{InternalError, QStringLiteral("An internal parser error occurred.")}
{NoError, u"No error occurred."_s},
{IllegalEscape, u"Illegal use of an escape character."_s},
{UnterminatedField, u"An escaped field was not properly terminated."_s},
{UnevenColumns, u"A row contained a different number of fields than the header row."_s},
{InternalError, u"An internal parser error occurred."_s}
};

//-Instance Variables------------------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/qx-error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Error Error::withSeverity(Severity sv)
QTextStream& operator<<(QTextStream& ts, const Qx::Error& e)
{
// Primary heading
ts << "( " << e.severityString() << " ) " << e.hexCode() << " ";
ts << "( " << e.severityString() << " ) " << e.hexCode() << ' ';
if(!e.mCaption.isEmpty())
ts << e.mCaption;
ts << '\n';
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/qx-system_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace // Anonymous namespace for local only definitions

public:
ProcTraverser() :
mItr("/proc", QDir::Dirs | QDir::NoDotAndDotDot),
mItr(u"/proc"_s, QDir::Dirs | QDir::NoDotAndDotDot),
mAtEnd(false)
{
// Go to first entry
Expand All @@ -59,7 +59,7 @@ namespace // Anonymous namespace for local only definitions

QString readProcString(quint32 pid, QString subFilePath)
{
QFile procFile("/proc/" + QString::number(pid) + subFilePath);
QFile procFile(u"/proc/"_s + QString::number(pid) + subFilePath);
if(procFile.exists())
{
if(procFile.open(QIODevice::ReadOnly))
Expand All @@ -77,7 +77,7 @@ namespace // Anonymous namespace for local only definitions
{
QStringList stats;

QString stat = readProcString(pid, "/stat");
QString stat = readProcString(pid, u"/stat"_s);
if(!stat.isEmpty())
{
// Single out name (can contain all kinds of problematic characters)
Expand Down Expand Up @@ -119,7 +119,7 @@ namespace // Anonymous namespace for local only definitions

QString procNameFromCmdline(quint32 pid)
{
QString cmdline = readProcString(pid, "/cmdline");
QString cmdline = readProcString(pid, u"/cmdline"_s);
if(!cmdline.isEmpty())
{
if(cmdline.front() == '-') // Account for login shells
Expand Down
20 changes: 10 additions & 10 deletions lib/io/include/qx/io/qx-applicationlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ class QX_IO_EXPORT ApplicationLogger
{
//-Class Variables----------------------------------------------------------------------------------------------------
private:
static inline const QString HEADER_TEMPLATE = "[ %1 Execution Log ] (%2) : %3";
static inline const QString HEADER_TEMPLATE = u"[ %1 Execution Log ] (%2) : %3"_s;
// NOTE: Changes to the members of this class might require changes to this pattern
static inline const QRegularExpression HEADER_PATTERN = QRegularExpression(R"(^\[ .* Execution Log \] \(.*\) : .+)",
static inline const QRegularExpression HEADER_PATTERN = QRegularExpression(uR"(^\[ .* Execution Log \] \(.*\) : .+)"_s,
QRegularExpression::MultilineOption);
static inline const QString NO_PARAMS = "*None*";
static inline const QString EVENT_TEMPLATE = " - <%1> [%2] %3";
static inline const QString ERR_TEMPLATE = " - <%1> [%2] %3) %4 - %5";
static inline const QString COMMANDLINE_LABEL = "Arguments:";
static inline const QString EVENTS_LABEL = "Events:";
static inline const QString FINISH_TEMPLATE = "---------- Execution finished %1 (Code %2) ----------";
static inline const QString FINISH_SUCCESS = "successfully";
static inline const QString FINISH_ERR = "prematurely";
static inline const QString NO_PARAMS = u"*None*"_s;
static inline const QString EVENT_TEMPLATE = u" - <%1> [%2] %3"_s;
static inline const QString ERR_TEMPLATE = u" - <%1> [%2] %3) %4 - %5"_s;
static inline const QString COMMANDLINE_LABEL = u"Arguments:"_s;
static inline const QString EVENTS_LABEL = u"Events:"_s;
static inline const QString FINISH_TEMPLATE = u"---------- Execution finished %1 (Code %2) ----------"_s;
static inline const QString FINISH_SUCCESS = u"successfully"_s;
static inline const QString FINISH_ERR = u"prematurely"_s;

//-Instance Variables-------------------------------------------------------------------------------------------------
private:
Expand Down
2 changes: 1 addition & 1 deletion lib/io/include/qx/io/qx-common-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(ReadOptions)
//-Namespace Variables-------------------------------------------------------------------------------------------------
//TODO: Ensure these work in shared build. Don't think they need to be exported since they are defined here
const QChar ENDL = '\n'; //Auto cross platform thanks to QIODevice::OpenMode Text
const QString LIST_ITEM_PREFIX = "- ";
const QString LIST_ITEM_PREFIX = u"- "_s;

//-Namespace Functions-------------------------------------------------------------------------------------------------
QX_IO_EXPORT bool fileIsEmpty(const QFile& file);
Expand Down
6 changes: 3 additions & 3 deletions lib/io/src/qx-applicationlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ IoOpReport ApplicationLogger::openLog()

//-Construct entry start---------------------
// Header
entryStart += HEADER_TEMPLATE.arg(mAppName, mAppVersion, QDateTime::currentDateTime().toString()) + "\n";
entryStart += HEADER_TEMPLATE.arg(mAppName, mAppVersion, QDateTime::currentDateTime().toString()) + '\n';

// Start parameters
entryStart += COMMANDLINE_LABEL + ' ' + (mAppArguments.isEmpty() ? NO_PARAMS : mAppArguments) + '\n';
Expand Down Expand Up @@ -276,9 +276,9 @@ IoOpReport ApplicationLogger::recordErrorEvent(QString src, Error error)
QString timeString = QTime::currentTime().toString();;
QString errorString = ERR_TEMPLATE.arg(timeString, src, error.severityString(), error.hexCode(), error.primary());
if(!error.secondary().isEmpty())
errorString += " " + error.secondary();
errorString += ' ' + error.secondary();
if(!error.details().isEmpty())
errorString += "\n\t" + error.details().replace("\n", "\n\t");
errorString += u"\n\t"_s + error.details().replace('\n', u"\n\t"_s);

mErrorStatus = mTextStreamWriter.writeLine(errorString);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/io/src/qx-common-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ namespace
for(int i = 0; i < *startPos.line(); ++i)
textStream << ENDL;
for(int i = 0; i < *startPos.character(); ++i)
textStream << " ";
textStream << ' ';
}

// Write main text
Expand Down Expand Up @@ -1020,7 +1020,7 @@ namespace
{
int lastLineCharCount = beforeNew.count() - (beforeNew.lastIndexOf(ENDL) + 1);
int charNeeded = std::max(*startPos.character() - lastLineCharCount, 0);
beforeNew += QString(" ").repeated(charNeeded);
beforeNew += QString(' ').repeated(charNeeded);

if(charNeeded > 0)
padded = true;
Expand Down
4 changes: 2 additions & 2 deletions lib/io/src/qx-textstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ QString TextStream::readLineWithBreak(qint64 maxlen)
QString buffer = QTextStream::readLine(maxlen);

if(atEnd() || maxlen > 0)
return precedingBreak() ? buffer + "\n" : buffer;
return precedingBreak() ? buffer + '\n' : buffer;
else
return buffer + "\n";
return buffer + '\n';
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/io/src/qx-textstreamreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ QString TextStreamReader::readAll()
*
* If @a maxlen is 0, the lines can be of any length.
*
* The returned line has no trailing end-of-line characters ("\n" or "\r\n"), so calling
* The returned line has no trailing end-of-line characters ('\n' or "\r\n"), so calling
* QString::trimmed() can be unnecessary.
*
* If the stream has read to the end of the file, readLine() will return a null QString. For strings,
Expand Down Expand Up @@ -214,7 +214,7 @@ QString TextStreamReader::readLine(qint64 maxlen)
*
* If @a maxlen is 0, the lines can be of any length.
*
* The resulting line has no trailing end-of-line characters ("\n" or "\r\n"), so calling
* The resulting line has no trailing end-of-line characters ('\n' or "\r\n"), so calling
* QString::trimmed() can be unnecessary.
*
* If @a line has sufficient capacity for the data that is about to be read, this function may not
Expand Down
6 changes: 3 additions & 3 deletions lib/linux/include/qx/linux/qx-applicationdesktopentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class QX_LINUX_EXPORT ApplicationDesktopEntry : public DesktopEntry
{
//-Class Members-------------------------------------------------------------------------------------------------
private:
static inline const QString TYPE = QStringLiteral("Application");
static inline const QString EXTENSION = QStringLiteral("desktop");
static inline const QString ACTION_HEADER = QStringLiteral("[Desktop Actions %1]");
static inline const QString TYPE = u"Application"_s;
static inline const QString EXTENSION = u"desktop"_s;
static inline const QString ACTION_HEADER = u"[Desktop Actions %1]"_s;

//-Instance Members-------------------------------------------------------------------------------------------------
private:
Expand Down
2 changes: 1 addition & 1 deletion lib/linux/include/qx/linux/qx-desktopentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class QX_LINUX_EXPORT DesktopEntry
{
//-Class Members----------------------------------------------------------------------------------------------------
private:
static inline const QString MAIN_GROUP = QStringLiteral("[Desktop Entry]");
static inline const QString MAIN_GROUP = u"[Desktop Entry]"_s;

//-Instance Members-------------------------------------------------------------------------------------------------
private:
Expand Down
4 changes: 2 additions & 2 deletions lib/linux/include/qx/linux/qx-directorydesktopentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class QX_LINUX_EXPORT DirectoryDesktopEntry : public DesktopEntry
{
//-Class Members-------------------------------------------------------------------------------------------------
private:
static inline const QString TYPE = QStringLiteral("Directory");
static inline const QString EXTENSION = QStringLiteral("directory");
static inline const QString TYPE = u"Directory"_s;
static inline const QString EXTENSION = u"directory"_s;

//-Constructor-----------------------------------------------------------------------------------------------------
public:
Expand Down
4 changes: 2 additions & 2 deletions lib/linux/include/qx/linux/qx-linkdesktopentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class QX_LINUX_EXPORT LinkDesktopEntry : public DesktopEntry
{
//-Class Members-------------------------------------------------------------------------------------------------
private:
static inline const QString TYPE = QStringLiteral("Link");
static inline const QString EXTENSION = QStringLiteral("desktop");
static inline const QString TYPE = u"Link"_s;
static inline const QString EXTENSION = u"desktop"_s;

//-Instance Members-------------------------------------------------------------------------------------------------
private:
Expand Down
2 changes: 1 addition & 1 deletion lib/linux/src/qx-desktopentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ DesktopEntry::DesktopEntry() :
*/
QString DesktopEntry::keyValueString(const QString& key, bool value)
{
return keyValueString(key, (value ? "true" : "false"));
return keyValueString(key, (value ? u"true"_s : u"false"_s));
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion lib/network/src/qx-downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void AsyncDownloadManager::startDownload(DownloadTask task)
if(streamOpen.isFailure())
{
forceFinishProgress(task);
recordFinishedDownload(DownloadOpReport::failedDownload(task, streamOpen.outcome() + ": " + streamOpen.outcomeInfo()));
recordFinishedDownload(DownloadOpReport::failedDownload(task, streamOpen.outcome() + u": "_s + streamOpen.outcomeInfo()));
if(mStopOnError)
stopOnError();
return;
Expand Down
10 changes: 5 additions & 5 deletions lib/network/src/qx-downloadmanagerreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ QString DownloadManagerReport::deriveDetails() const
details.reserve(mDetailsSpecific.size() && mDetailsGeneral.size() + 2);
details.append(mDetailsGeneral);
if(!details.isEmpty())
details.append("\n\n"); // +2
details.append(u"\n\n"_s); // +2
details.append(mDetailsSpecific);

return details;
Expand Down Expand Up @@ -198,21 +198,21 @@ DownloadManagerReport DownloadManagerReport::Builder::build()

if(!errorList.isEmpty())
{
sDetails += ERR_D_SPECIFIC + "\n";
sDetails += "- " + errorList.join("\n- ");
sDetails += ERR_D_SPECIFIC + '\n';
sDetails += u"- "_s + errorList.join(u"\n- "_s);
}

if(skipped || aborted)
{
gDetails += ERR_D_GENERAL + "\n";
gDetails += ERR_D_GENERAL + '\n';

QStringList generalList;
if(skipped)
generalList << ERR_D_SKIP.arg(skipped);
if(aborted)
generalList << ERR_D_ABORT.arg(aborted);

gDetails += "- " + generalList.join("\n- ");
gDetails += u"- "_s + generalList.join(u"\n- "_s);
}

mWorkingReport.mOutcomeString = ERR_P_QUEUE_INCOMPL;
Expand Down
8 changes: 5 additions & 3 deletions lib/widgets/include/qx/widgets/qx-logindialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <QLineEdit>
#include <QDialogButtonBox>

using namespace Qt::Literals::StringLiterals;

namespace Qx
{

Expand All @@ -20,9 +22,9 @@ class QX_WIDGETS_EXPORT LoginDialog : public QDialog

//-Class Members-------------------------------------------------------------------------------------------------------
private:
static inline const QString LABEL_DEF_PRMT= "Login Required";
static inline const QString LABEL_USRNAME = "&Username";
static inline const QString LABEL_PSSWD = "&Password";
static inline const QString LABEL_DEF_PRMT= u"Login Required"_s;
static inline const QString LABEL_USRNAME = u"&Username"_s;
static inline const QString LABEL_PSSWD = u"&Password"_s;

//-Instance Members---------------------------------------------------------------------------------------------------
private:
Expand Down
2 changes: 1 addition & 1 deletion lib/xml/include/qx/xml/qx-common-xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Qx
{

//-Namespace Functions-------------------------------------------------------------------------------------------------------------
QX_XML_EXPORT QString xmlSanitized(QString string);
QX_XML_EXPORT QString xmlSanitized(const QString& string);

}

Expand Down
6 changes: 4 additions & 2 deletions lib/xml/src/qx-common-xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
*
*/

using namespace Qt::Literals::StringLiterals;

namespace Qx
{

namespace // Anonymous namespace for effectively private (to this cpp)
{
//-Unit Variables-----------------------------------------------------------------------------------------------------
const QRegularExpression illegalXmlChar(QStringLiteral(u"[\u0001-\u0008\u000B\u000C\u000E-\u001F\u007f-\u0084\u0086-\u009f\uFDD0-\uFDFF\uFFFF\uC008]"));
const QRegularExpression illegalXmlChar(u"[\u0001-\u0008\u000B\u000C\u000E-\u001F\u007f-\u0084\u0086-\u009f\uFDD0-\uFDFF\uFFFF\uC008]"_s);
}

//-Namespace Functions----------------------------------------------------------------------------------------------------
/*!
* Returns a copy of @a string with all non-legal XML characters removed
*/
QString xmlSanitized(QString string) { return string.remove(illegalXmlChar); }
QString xmlSanitized(const QString& string){ return QString(string).remove(illegalXmlChar); }

}

0 comments on commit 66cc203

Please sign in to comment.