From 31c9f9fecc89aee742500629457838971495978b Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Mon, 12 Mar 2018 00:39:36 +0100 Subject: [PATCH] license: Removed license generator dependency to lib_utitlity to avoid linking with Qt --- CMakeLists.txt | 5 ++--- src/lib_license/License.cpp | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c69083a4..041dbe55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -252,7 +252,6 @@ create_source_groups(${LIB_LICENSE_FILES}) target_include_directories( ${LIB_LICENSE_PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/src/lib_license" "${CMAKE_BINARY_DIR}/src/lib_license" - "${CMAKE_SOURCE_DIR}/src/lib_utility" ) target_include_directories(${LIB_LICENSE_PROJECT_NAME} SYSTEM @@ -261,8 +260,6 @@ target_include_directories(${LIB_LICENSE_PROJECT_NAME} SYSTEM ${BOTAN_INCLUDE_DIR} ) -target_link_libraries(${LIB_LICENSE_PROJECT_NAME} ${LIB_UTILITY_PROJECT_NAME}) - if(UNIX) target_link_libraries(${LIB_LICENSE_PROJECT_NAME} ${BOTAN}) else() @@ -578,6 +575,7 @@ set_property( PROPERTY INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/src/app" "${CMAKE_SOURCE_DIR}/src/lib" + "${CMAKE_SOURCE_DIR}/src/lib_utility" "${CMAKE_SOURCE_DIR}/src/lib_gui" "${CMAKE_SOURCE_DIR}/src/lib_license" "${CMAKE_SOURCE_DIR}/src/lib_cxx" @@ -723,6 +721,7 @@ if (CXXTEST_FOUND) PROPERTY INCLUDE_DIRECTORIES "${CXXTEST_INCLUDE_DIR}" "${CMAKE_SOURCE_DIR}/src/lib" + "${CMAKE_SOURCE_DIR}/src/lib_utility" "${CMAKE_SOURCE_DIR}/src/lib_gui" "${CMAKE_SOURCE_DIR}/src/lib_cxx" "${CMAKE_SOURCE_DIR}/src/lib_java" diff --git a/src/lib_license/License.cpp b/src/lib_license/License.cpp index e977eec1..e39e3528 100644 --- a/src/lib_license/License.cpp +++ b/src/lib_license/License.cpp @@ -21,10 +21,28 @@ #include "botan/auto_rng.h" #include "botan/pbkdf.h" -#include "utility/utilityString.h" #include "utility/Version.h" #include "PublicKey.h" +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)); +} + +std::string toLowerCase(const std::string& in) +{ + std::string out; + std::transform(in.begin(), in.end(), std::back_inserter(out), tolower); + return out; +} + +} + License::License() : m_rng(std::make_shared()) , m_user("") @@ -95,7 +113,7 @@ std::string License::getLine(std::istream& stream) std::string line; if(getline(stream, line, '\n')) { - return utility::trim(line); + return trim(line); } return ""; } @@ -274,7 +292,7 @@ bool License::load(std::istream& stream) // separator line getline(stream, line, '\n'); - if (utility::trim(line) != LicenseConstants::SEPARATOR_STRING) + if (trim(line) != LicenseConstants::SEPARATOR_STRING) { return false; } @@ -286,7 +304,7 @@ bool License::load(std::istream& stream) m_signature = ""; while (getline(stream, line, '\n')) { - std::string l = utility::trim(line); + std::string l = trim(line); if (l == LicenseConstants::END_LICENSE_STRING) { break; @@ -320,7 +338,7 @@ void License::setTypeAndNumberOfUsers(const std::string& line) m_numberOfUsers = 0; } - if (utility::toLowerCase(line).find("seat") != line.npos) + if (toLowerCase(line).find("seat") != line.npos) { m_createdWithSeats = true; }