From 99e691fbe36cdd7922cab8d3a79057dc3f65f278 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Wed, 4 Aug 2021 06:47:14 +1000 Subject: [PATCH 1/2] Avoid the inclusion of header due to Ubuntu Bionic (18.04) which as gcc version less than 8.1 Partially reverts commit fd67ebde2549bf5eb626c8c4ea76536c1f003a56 --- apps/opencs/model/world/refcollection.cpp | 17 +++++------------ apps/opencs/model/world/refcollection.hpp | 2 +- apps/opencs/view/doc/loader.cpp | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index 1f6fc76c4d..f47a79accd 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -1,7 +1,5 @@ #include "refcollection.hpp" -#include - #include #include "ref.hpp" @@ -183,19 +181,14 @@ std::string CSMWorld::RefCollection::getNewId() return "ref#" + std::to_string(mNextId++); } -unsigned int CSMWorld::RefCollection::extractIdNum(std::string_view id) const +unsigned int CSMWorld::RefCollection::extractIdNum (const std::string& id) const { - const auto separator = id.find_last_of('#'); + std::string::size_type separator = id.find_last_of('#'); - if (separator == std::string_view::npos) - throw std::runtime_error("invalid ref ID: " + std::string(id)); + if (separator == std::string::npos) + throw std::runtime_error("invalid ref ID: " + id); - const std::string_view number = id.substr(separator + 1); - unsigned int result; - if (std::from_chars(number.data(), number.data() + number.size(), result).ec != std::errc()) - throw std::runtime_error("invalid ref ID number: " + std::string(number)); - - return result; + return static_cast(std::stoi(id.substr(separator+1))); } int CSMWorld::RefCollection::getIntIndex (unsigned int id) const diff --git a/apps/opencs/model/world/refcollection.hpp b/apps/opencs/model/world/refcollection.hpp index e0e88d721f..1bdfda3925 100644 --- a/apps/opencs/model/world/refcollection.hpp +++ b/apps/opencs/model/world/refcollection.hpp @@ -29,7 +29,7 @@ namespace CSMWorld int mNextId; - unsigned int extractIdNum(std::string_view id) const; + unsigned int extractIdNum(const std::string& id) const; int getIntIndex (unsigned int id) const; diff --git a/apps/opencs/view/doc/loader.cpp b/apps/opencs/view/doc/loader.cpp index 7929b13f6c..2420b87c6c 100644 --- a/apps/opencs/view/doc/loader.cpp +++ b/apps/opencs/view/doc/loader.cpp @@ -17,7 +17,7 @@ void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event) } CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document) -: mDocument (document), mAborted (false), mMessages (nullptr), mRecordsLabel (0), mTotalRecordsLabel (0) +: mDocument (document), mTotalRecordsLabel (0), mRecordsLabel (0), mAborted (false), mMessages (nullptr), mRecords(0) { setWindowTitle (QString::fromUtf8((std::string("Opening ") + document->getSavePath().filename().string()).c_str())); From bf06898a79a5460c571b1d6f5b2b9cb7c7f52052 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Wed, 4 Aug 2021 08:23:22 +1000 Subject: [PATCH 2/2] Retain the use of std::string_view in the function signature. --- apps/opencs/model/world/refcollection.cpp | 6 +++--- apps/opencs/model/world/refcollection.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp index f47a79accd..4782bde6b9 100644 --- a/apps/opencs/model/world/refcollection.cpp +++ b/apps/opencs/model/world/refcollection.cpp @@ -181,14 +181,14 @@ std::string CSMWorld::RefCollection::getNewId() return "ref#" + std::to_string(mNextId++); } -unsigned int CSMWorld::RefCollection::extractIdNum (const std::string& id) const +unsigned int CSMWorld::RefCollection::extractIdNum(std::string_view id) const { std::string::size_type separator = id.find_last_of('#'); if (separator == std::string::npos) - throw std::runtime_error("invalid ref ID: " + id); + throw std::runtime_error("invalid ref ID: " + std::string(id)); - return static_cast(std::stoi(id.substr(separator+1))); + return static_cast(std::stoi(std::string(id.substr(separator+1)))); } int CSMWorld::RefCollection::getIntIndex (unsigned int id) const diff --git a/apps/opencs/model/world/refcollection.hpp b/apps/opencs/model/world/refcollection.hpp index 1bdfda3925..e0e88d721f 100644 --- a/apps/opencs/model/world/refcollection.hpp +++ b/apps/opencs/model/world/refcollection.hpp @@ -29,7 +29,7 @@ namespace CSMWorld int mNextId; - unsigned int extractIdNum(const std::string& id) const; + unsigned int extractIdNum(std::string_view id) const; int getIntIndex (unsigned int id) const;