X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Futil.cpp;h=3e8a3755608a48314a097e865f88051c4e8d5185;hb=refs%2Fheads%2Fmaster;hp=33f6b4dfe375d861782bb6140d201c439af4eb81;hpb=bb631d7ca67c86dd758428fb0e18b905514a16e3;p=evaf
diff --git a/src/libs/Common/util.cpp b/src/libs/Common/util.cpp
index 33f6b4d..3e8a375 100644
--- a/src/libs/Common/util.cpp
+++ b/src/libs/Common/util.cpp
@@ -3,7 +3,7 @@
* @brief Global utility functions for eVaf
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
@@ -33,30 +33,27 @@ QVariant eVaf::Common::toVariant(QString const & value, QVariant const & default
switch (defaultValue.type()) {
case QVariant::UInt: {
bool ok;
- uint v = value.toUInt(&ok, 0);
+ uint const v = value.toUInt(&ok, 0);
if (ok)
return QVariant(v);
else
return defaultValue;
- break;
}
case QVariant::Int: {
bool ok;
- int v = value.toInt(&ok, 0);
+ int const v = value.toInt(&ok, 0);
if (ok)
return QVariant(v);
else
return defaultValue;
- break;
}
case QVariant::Double: {
bool ok;
- double v = value.toDouble(&ok);
+ double const v = value.toDouble(&ok);
if (ok)
return QVariant(v);
else
return defaultValue;
- break;
}
case QVariant::Bool: {
if (eVaf::Common::isTrue(value))
@@ -65,33 +62,36 @@ QVariant eVaf::Common::toVariant(QString const & value, QVariant const & default
return QVariant(false);
else {
bool ok;
- uint v = value.toUInt(&ok, 0);
+ uint const v = value.toUInt(&ok, 0);
if (ok)
return QVariant(v);
else
return defaultValue;
}
- break;
}
case QVariant::Char: {
if (value.size() > 0) {
if (value.startsWith("\\0x")) {
bool ok;
- char c = value.mid(1).toUInt(&ok, 16);
+ char const c = static_cast(value.mid(1).toUInt(&ok, 16));
if (ok)
return QVariant(c);
}
else if (value.startsWith("\\0")) {
bool ok;
- char c = value.mid(1).toUInt(&ok, 8);
+ char const c = static_cast(value.mid(1).toUInt(&ok, 8));
if (ok)
return QVariant(c);
}
+ else if (value.startsWith('&')) {
+ QString const c = strFromEscapedCharArray(value.toLatin1());
+ if (c.size() > 0)
+ return QVariant(c.at(0));
+ }
else
return QVariant(value.at(0));
}
return defaultValue;
- break;
}
default:
return QVariant(value);
@@ -115,7 +115,7 @@ QByteArray eVaf::Common::strToEscapedCharArray(QString const & str)
else if (c == '>')
rval.append(">");
else
- rval.append((char const)c.unicode());
+ rval.append(static_cast(c.unicode()));
}
return rval;
@@ -134,7 +134,7 @@ QString eVaf::Common::strFromEscapedCharArray(QByteArray const & str)
ref = "&";
}
else
- rval.append(QChar((ushort)c));
+ rval.append(QChar(static_cast(c)));
}
else {
ref.append(c);
@@ -145,7 +145,7 @@ QString eVaf::Common::strFromEscapedCharArray(QByteArray const & str)
if (ref.startsWith("")) {
// Numeric character reference in the HEX format
bool ok;
- ushort ucode = ref.mid(3, ref.size() - 4).toUInt(&ok, 16);
+ ushort const ucode = static_cast(ref.mid(3, ref.size() - 4).toUInt(&ok, 16));
if (ok)
rval.append(QChar(ucode));
else
@@ -155,7 +155,7 @@ QString eVaf::Common::strFromEscapedCharArray(QByteArray const & str)
else if (ref.startsWith("")) {
// Numeric character reference in the DEC format
bool ok;
- ushort ucode = ref.mid(2, ref.size() - 3).toUInt(&ok, 10);
+ ushort const ucode = static_cast(ref.mid(2, ref.size() - 3).toUInt(&ok, 10));
if (ok)
rval.append(QChar(ucode));
else
@@ -185,7 +185,7 @@ QString eVaf::Common::strFromEscapedCharArray(QByteArray const & str)
QByteArray eVaf::Common::binToEscapedCharArray(QByteArray const & src)
{
QByteArray rval;
- foreach (uchar c, src) {
+ foreach (char const c, src) {
if (c < 32 || c >= 127)
rval.append("" + QByteArray::number(c, 16) + ";");
else if (c == '\"')
@@ -229,7 +229,7 @@ QByteArray eVaf::Common::binFromEscapedCharArray(QByteArray const & str)
if (ref.startsWith("")) {
// Numeric character reference in the HEX format
bool ok;
- uchar ucode = ref.mid(3, ref.size() - 4).toUInt(&ok, 16);
+ char const ucode = static_cast(ref.mid(3, ref.size() - 4).toUInt(&ok, 16));
if (ok)
rval.append(ucode);
else
@@ -239,7 +239,7 @@ QByteArray eVaf::Common::binFromEscapedCharArray(QByteArray const & str)
else if (ref.startsWith("")) {
// Numeric character reference in the DEC format
bool ok;
- uchar ucode = ref.mid(2, ref.size() - 3).toUInt(&ok, 10);
+ char const ucode = static_cast(ref.mid(2, ref.size() - 3).toUInt(&ok, 10));
if (ok)
rval.append(ucode);
else