logic: Trim lines and remove empty ones when checking license key

This commit is contained in:
Eberhard Graether
2016-01-19 11:48:41 +01:00
parent cc2b74ccca
commit 46d9825454
6 changed files with 37 additions and 2 deletions
+7
View File
@@ -168,4 +168,11 @@ namespace utility
return str;
}
std::string trim(const std::string &str)
{
auto wsfront = std::find_if_not(str.begin(), str.end(), [](int c){ return std::isspace(c); });
auto wsback = std::find_if_not(str.rbegin(), str.rend(), [](int c){ return std::isspace(c); }).base();
return (wsback <= wsfront ? std::string() : std::string(wsfront, wsback));
}
}
+1
View File
@@ -39,6 +39,7 @@ namespace utility
std::string replace(std::string str, const std::string& from, const std::string& to);
std::string trim(const std::string &str);
template <typename ContainerType>
ContainerType split(const std::string& str, const std::string& delimiter)
+10 -1
View File
@@ -38,6 +38,16 @@ void QtLicense::clear()
}
}
void QtLicense::load()
{
clear();
if (m_licenseText)
{
m_licenseText->setText(ApplicationSettings::getInstance()->getLicenseString().c_str());
}
}
void QtLicense::setup()
{
setStyleSheet((
@@ -67,7 +77,6 @@ void QtLicense::setup()
m_licenseText = new QTextEdit(this);
m_licenseText->setObjectName("licenseField");
m_licenseText->setText(ApplicationSettings::getInstance()->getLicenseString().c_str());
m_licenseText->setPlaceholderText(
"-----BEGIN LICENSE-----\n"
"Jane Doe\n"
+1
View File
@@ -17,6 +17,7 @@ public:
QSize sizeHint() const Q_DECL_OVERRIDE;
void clear();
void load();
virtual void setup() override;
+1
View File
@@ -365,6 +365,7 @@ void QtMainWindow::enterLicense()
connect(m_enterLicenseWindow.get(), SIGNAL(canceled()), this, SLOT(popWindow()));
}
m_enterLicenseWindow->load();
pushWindow(m_enterLicenseWindow.get());
}
+17 -1
View File
@@ -1,5 +1,6 @@
#include "License.h"
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
@@ -15,6 +16,16 @@
// #include "botan/rsa.h"
// #endif
namespace
{
std::string trim(const std::string &str)
{
auto wsfront = std::find_if_not(str.begin(), str.end(), [](int c){ return std::isspace(c); });
auto wsback = std::find_if_not(str.rbegin(), str.rend(), [](int c){ return std::isspace(c); }).base();
return (wsback <= wsfront ? std::string() : std::string(wsfront, wsback));
}
}
License::License()
{
}
@@ -119,9 +130,14 @@ bool License::load(std::istream& stream)
{
lines.clear();
std::string line;
while (getline(stream, line, '\n'))
{
lines.push_back(line);
std::string l = trim(line);
if (l.size())
{
lines.push_back(l);
}
}
if (lines.front() != BEGIN_LICENSE)