From c525565e849d1c06b30eba85f446c480a8a4c9e1 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 28 Nov 2023 14:57:01 +0100 Subject: [PATCH] Utilize new functions for converting strings to upper/lower case (#2956) * Utilize new functions for converting strings to upper/lower case * Adapt to updated file name * Use new function signature * Update ghoul --- ext/ghoul | 2 +- .../dashboard/dashboarditeminputstate.cpp | 2 +- .../renderablefieldlinessequence.cpp | 15 +++--------- .../globebrowsing/globebrowsingmodule_lua.inl | 4 ++-- modules/globebrowsing/src/gdalwrapper.cpp | 8 ++----- modules/imgui/src/guipropertycomponent.cpp | 2 +- modules/imgui/src/guiscenecomponent.cpp | 2 +- modules/imgui/src/renderproperties.cpp | 2 +- modules/kameleon/src/kameleonwrapper.cpp | 23 ++++--------------- modules/skybrowser/src/wwtdatahandler.cpp | 2 +- modules/space/horizonsfile.cpp | 2 +- modules/space/kepler.cpp | 2 +- .../renderableconstellationlines.cpp | 2 +- .../renderableconstellationsbase.cpp | 2 +- .../util/hongkangparser.cpp | 8 ++----- .../util/instrumentdecoder.cpp | 8 ++----- modules/statemachine/statemachinemodule.cpp | 2 +- src/documentation/verifier.cpp | 2 +- src/engine/openspaceengine.cpp | 12 ++++------ src/properties/list/doublelistproperty.cpp | 2 +- src/properties/list/intlistproperty.cpp | 2 +- src/properties/list/stringlistproperty.cpp | 2 +- src/properties/selectionproperty.cpp | 2 +- src/rendering/luaconsole.cpp | 17 ++++---------- src/scene/profile.cpp | 2 +- src/scene/scene.cpp | 2 +- src/scripting/systemcapabilitiesbinding.cpp | 2 +- src/util/json_helper.cpp | 18 ++++----------- src/util/keys.cpp | 9 ++------ src/util/openspacemodule.cpp | 17 +++----------- src/util/time.cpp | 2 +- src/util/versionchecker.cpp | 2 +- 32 files changed, 54 insertions(+), 127 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index a5f9918f57..b9c9a031f8 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit a5f9918f5757eefd7c10b338797de6cf21ec8f9a +Subproject commit b9c9a031f8169f13349c458815ecf34e9f6990d6 diff --git a/modules/base/dashboard/dashboarditeminputstate.cpp b/modules/base/dashboard/dashboarditeminputstate.cpp index ea0758154e..eecc6e0da4 100644 --- a/modules/base/dashboard/dashboarditeminputstate.cpp +++ b/modules/base/dashboard/dashboarditeminputstate.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include namespace { constexpr openspace::properties::Property::PropertyInfo ShowWhenEnabledInfo = { diff --git a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp index 92b10d7c1c..a660a15456 100644 --- a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp +++ b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -411,12 +412,7 @@ RenderableFieldlinesSequence::RenderableFieldlinesSequence( [&fileTypeString](const std::string& str) { const size_t extLength = fileTypeString.length(); std::string sub = str.substr(str.length() - extLength, extLength); - std::transform( - sub.begin(), - sub.end(), - sub.begin(), - [](char c) { return static_cast(::tolower(c)); } - ); + sub = ghoul::toLowerCase(sub); return sub != fileTypeString; } ), @@ -570,12 +566,7 @@ void RenderableFieldlinesSequence::initializeGL() { // Returns fls::Model::Invalid if it fails to extract mandatory information fls::Model stringToModel(std::string str) { - std::transform( - str.begin(), - str.end(), - str.begin(), - [](char c) { return static_cast(::tolower(c)); } - ); + str = ghoul::toLowerCase(str); return fls::stringToModel(str); } diff --git a/modules/globebrowsing/globebrowsingmodule_lua.inl b/modules/globebrowsing/globebrowsingmodule_lua.inl index ab315063bc..3d51d058cd 100644 --- a/modules/globebrowsing/globebrowsingmodule_lua.inl +++ b/modules/globebrowsing/globebrowsingmodule_lua.inl @@ -23,6 +23,7 @@ ****************************************************************************************/ #include +#include namespace { @@ -673,8 +674,7 @@ geoPositionForCameraDeprecated(bool useEyePosition = false) } std::string extension = path.extension().string(); - std::transform(extension.begin(), extension.end(), extension.begin(), - [](unsigned char c) { return std::tolower(c); }); + extension = ghoul::toLowerCase(extension); if (extension != ".geojson" && extension != ".json") { throw ghoul::lua::LuaError(fmt::format( diff --git a/modules/globebrowsing/src/gdalwrapper.cpp b/modules/globebrowsing/src/gdalwrapper.cpp index 980bddbcb3..fe2787fd48 100644 --- a/modules/globebrowsing/src/gdalwrapper.cpp +++ b/modules/globebrowsing/src/gdalwrapper.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -135,12 +136,7 @@ void GdalWrapper::setGdalProxyConfiguration() { const std::string user = global::configuration->httpProxy.user; const std::string password = global::configuration->httpProxy.password; std::string auth = global::configuration->httpProxy.authentication; - std::transform( - auth.begin(), - auth.end(), - auth.begin(), - [](char c) { return static_cast(::toupper(c)); } - ); + auth = ghoul::toUpperCase(auth); const std::string proxy = address + ":" + std::to_string(port); CPLSetConfigOption("GDAL_HTTP_PROXY", proxy.c_str()); diff --git a/modules/imgui/src/guipropertycomponent.cpp b/modules/imgui/src/guipropertycomponent.cpp index 8f38f0dda8..834e58aedc 100644 --- a/modules/imgui/src/guipropertycomponent.cpp +++ b/modules/imgui/src/guipropertycomponent.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include //#define Debugging_ImGui_TreeNode_Indices diff --git a/modules/imgui/src/guiscenecomponent.cpp b/modules/imgui/src/guiscenecomponent.cpp index 992b0bbe91..7cd8ac9dbc 100644 --- a/modules/imgui/src/guiscenecomponent.cpp +++ b/modules/imgui/src/guiscenecomponent.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include namespace { diff --git a/modules/imgui/src/renderproperties.cpp b/modules/imgui/src/renderproperties.cpp index 6e49500b36..81b8aa6e8a 100644 --- a/modules/imgui/src/renderproperties.cpp +++ b/modules/imgui/src/renderproperties.cpp @@ -50,7 +50,7 @@ #include #include #include -#include +#include namespace openspace { diff --git a/modules/kameleon/src/kameleonwrapper.cpp b/modules/kameleon/src/kameleonwrapper.cpp index d1515b89af..555cc17a98 100644 --- a/modules/kameleon/src/kameleonwrapper.cpp +++ b/modules/kameleon/src/kameleonwrapper.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #ifdef WIN32 @@ -83,24 +83,9 @@ std::array gridVariables(ccmc::Model* model) { std::string y = std::move(tokens.at(1)); std::string z = std::move(tokens.at(2)); - std::transform( - x.cbegin(), - x.cend(), - x.begin(), - [](char c) { return static_cast(tolower(c)); } - ); - std::transform( - y.cbegin(), - y.cend(), - y.begin(), - [](char c) { return static_cast(tolower(c)); } - ); - std::transform( - z.cbegin(), - z.cend(), - z.begin(), - [](char c) { return static_cast(tolower(c)); } - ); + x = ghoul::toLowerCase(x); + y = ghoul::toLowerCase(y); + z = ghoul::toLowerCase(z); return { x, y, z }; } diff --git a/modules/skybrowser/src/wwtdatahandler.cpp b/modules/skybrowser/src/wwtdatahandler.cpp index b661fc6887..a000d3e17c 100644 --- a/modules/skybrowser/src/wwtdatahandler.cpp +++ b/modules/skybrowser/src/wwtdatahandler.cpp @@ -204,7 +204,7 @@ namespace { // Collect name, image url and credits std::string name = attribute(node, Name); if (std::islower(name[0])) { - // convert string to upper case + // convert first character in string to upper case name[0] = static_cast(std::toupper(name[0])); } diff --git a/modules/space/horizonsfile.cpp b/modules/space/horizonsfile.cpp index 08442195ee..f2635c70a8 100644 --- a/modules/space/horizonsfile.cpp +++ b/modules/space/horizonsfile.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/modules/space/kepler.cpp b/modules/space/kepler.cpp index ef5e40e508..45d5ba5b1f 100644 --- a/modules/space/kepler.cpp +++ b/modules/space/kepler.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index 01529fad9d..de1cc76e19 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/modules/space/rendering/renderableconstellationsbase.cpp b/modules/space/rendering/renderableconstellationsbase.cpp index fd77b5bc64..fb75c8fb5a 100644 --- a/modules/space/rendering/renderableconstellationsbase.cpp +++ b/modules/space/rendering/renderableconstellationsbase.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/modules/spacecraftinstruments/util/hongkangparser.cpp b/modules/spacecraftinstruments/util/hongkangparser.cpp index f895523c67..a96f4ac582 100644 --- a/modules/spacecraftinstruments/util/hongkangparser.cpp +++ b/modules/spacecraftinstruments/util/hongkangparser.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -109,12 +110,7 @@ HongKangParser::HongKangParser(std::string name, std::string fileName, std::string HongKangParser::findPlaybookSpecifiedTarget(std::string line) { //remembto add this lua later... - std::transform( - line.begin(), - line.end(), - line.begin(), - [](char v) { return static_cast(toupper(v)); } - ); + line = ghoul::toUpperCase(line); const std::vector& ptarg = _potentialTargets; std::string target; for (const std::string& p : ptarg) { diff --git a/modules/spacecraftinstruments/util/instrumentdecoder.cpp b/modules/spacecraftinstruments/util/instrumentdecoder.cpp index 5fa03edf2a..30ab3af502 100644 --- a/modules/spacecraftinstruments/util/instrumentdecoder.cpp +++ b/modules/spacecraftinstruments/util/instrumentdecoder.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -46,12 +47,7 @@ namespace openspace { InstrumentDecoder::InstrumentDecoder(const ghoul::Dictionary& dictionary) { const Parameters p = codegen::bake(dictionary); - _type = p.detectorType; - std::for_each( - _type.begin(), - _type.end(), - [](char& in) { in = static_cast(toupper(in)); } - ); + _type = ghoul::toUpperCase(p.detectorType); if (p.stopCommand.has_value() && _type == "SCANNER") { _stopCommand = *p.stopCommand; diff --git a/modules/statemachine/statemachinemodule.cpp b/modules/statemachine/statemachinemodule.cpp index 3a4a15b807..69aa15f995 100644 --- a/modules/statemachine/statemachinemodule.cpp +++ b/modules/statemachine/statemachinemodule.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/documentation/verifier.cpp b/src/documentation/verifier.cpp index ebbfec3dff..1bb3580355 100644 --- a/src/documentation/verifier.cpp +++ b/src/documentation/verifier.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 84cf70c4d3..aff5c8289b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -77,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -816,7 +817,7 @@ void OpenSpaceEngine::loadAssets() { it = allSyncs.erase(it); } } - + if (_shouldAbortLoading) { global::windowDelegate->terminate(); break; @@ -830,7 +831,7 @@ void OpenSpaceEngine::loadAssets() { if (finishedLoading) { break; - } + } } // while(true) if (_shouldAbortLoading) { @@ -1533,11 +1534,8 @@ void OpenSpaceEngine::handleDragDrop(std::filesystem::path file) { lua_setglobal(s, "basename"); std::string extension = file.extension().string(); - std::transform( - extension.begin(), extension.end(), - extension.begin(), - [](char c) { return static_cast(::tolower(c)); } - ); + extension = ghoul::toLowerCase(extension); + ghoul::lua::push(s, extension); lua_setglobal(s, "extension"); diff --git a/src/properties/list/doublelistproperty.cpp b/src/properties/list/doublelistproperty.cpp index 0baf967fd2..f0e74faca6 100644 --- a/src/properties/list/doublelistproperty.cpp +++ b/src/properties/list/doublelistproperty.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace openspace::properties { diff --git a/src/properties/list/intlistproperty.cpp b/src/properties/list/intlistproperty.cpp index dffad58a5b..57a85ab51b 100644 --- a/src/properties/list/intlistproperty.cpp +++ b/src/properties/list/intlistproperty.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace openspace::properties { diff --git a/src/properties/list/stringlistproperty.cpp b/src/properties/list/stringlistproperty.cpp index 7e3bd7caf5..99192273a4 100644 --- a/src/properties/list/stringlistproperty.cpp +++ b/src/properties/list/stringlistproperty.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace openspace::properties { diff --git a/src/properties/selectionproperty.cpp b/src/properties/selectionproperty.cpp index d86e0e04b6..be82af68b5 100644 --- a/src/properties/selectionproperty.cpp +++ b/src/properties/selectionproperty.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include namespace { diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index 19ff81c7c9..9d98a997d3 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -507,20 +508,10 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio const size_t fullLength = _autoCompleteInfo.initialValue.length(); const bool correctLength = command.length() >= fullLength; - std::string commandLowerCase; - std::transform( - command.begin(), command.end(), - std::back_inserter(commandLowerCase), - [](char v) { return static_cast(tolower(v)); } - ); + std::string commandLowerCase = ghoul::toLowerCase(command); - std::string initialValueLowerCase; - std::transform( - _autoCompleteInfo.initialValue.begin(), - _autoCompleteInfo.initialValue.end(), - std::back_inserter(initialValueLowerCase), - [](char v) { return static_cast(tolower(v)); } - ); + std::string initialValueLowerCase = + ghoul::toLowerCase(_autoCompleteInfo.initialValue); const bool correctCommand = commandLowerCase.substr(0, fullLength) == initialValueLowerCase; diff --git a/src/scene/profile.cpp b/src/scene/profile.cpp index e2d72bfd9d..647c8de15e 100644 --- a/src/scene/profile.cpp +++ b/src/scene/profile.cpp @@ -38,8 +38,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 1fd7efcdc6..5b020fb8df 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -49,8 +49,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/src/scripting/systemcapabilitiesbinding.cpp b/src/scripting/systemcapabilitiesbinding.cpp index e8f32cc3f0..86e3424bff 100644 --- a/src/scripting/systemcapabilitiesbinding.cpp +++ b/src/scripting/systemcapabilitiesbinding.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/util/json_helper.cpp b/src/util/json_helper.cpp index 6ec2a6b81b..8f4e6475fd 100644 --- a/src/util/json_helper.cpp +++ b/src/util/json_helper.cpp @@ -24,6 +24,8 @@ #include +#include + namespace openspace { std::string escapedJson(const std::string& text) { @@ -89,20 +91,8 @@ void sortJson(nlohmann::json& json, const std::string& key) { json.begin(), json.end(), [&key](const nlohmann::json& lhs, const nlohmann::json& rhs) { - std::string lhsString = lhs[key]; - std::string rhsString = rhs[key]; - std::transform( - lhsString.begin(), - lhsString.end(), - lhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); - std::transform( - rhsString.begin(), - rhsString.end(), - rhsString.begin(), - [](unsigned char c) { return std::tolower(c); } - ); + std::string lhsString = ghoul::toLowerCase(lhs[key]); + std::string rhsString = ghoul::toLowerCase(rhs[key]); return rhsString > lhsString; } diff --git a/src/util/keys.cpp b/src/util/keys.cpp index 6533d59360..b6e647d2ad 100644 --- a/src/util/keys.cpp +++ b/src/util/keys.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -43,12 +43,7 @@ KeyWithModifier stringToKey(std::string str) { std::vector originalTokens = tokens; for (std::string& t : tokens) { - std::transform( - t.begin(), t.end(), - t.begin(), - [](char v) { return static_cast(toupper(v)); } - ); - + t = ghoul::toUpperCase(t); } // default is unknown diff --git a/src/util/openspacemodule.cpp b/src/util/openspacemodule.cpp index 2072f9c26b..3189634580 100644 --- a/src/util/openspacemodule.cpp +++ b/src/util/openspacemodule.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -49,13 +50,7 @@ void OpenSpaceModule::initialize(const ghoul::Dictionary& configuration) { ZoneScoped; ZoneName(identifier().c_str(), identifier().size()); - std::string upperIdentifier = identifier(); - std::transform( - upperIdentifier.begin(), - upperIdentifier.end(), - upperIdentifier.begin(), - [](char v) { return static_cast(toupper(v)); } - ); + std::string upperIdentifier = ghoul::toUpperCase(identifier()); std::string moduleToken = "${" + std::string(ModuleBaseToken) + upperIdentifier + "}"; @@ -110,13 +105,7 @@ std::vector OpenSpaceModule::requiredOpenGLExtensions() const { } std::filesystem::path OpenSpaceModule::modulePath() const { - std::string moduleIdentifier = identifier(); - std::transform( - moduleIdentifier.begin(), - moduleIdentifier.end(), - moduleIdentifier.begin(), - [](char v) { return static_cast(tolower(v)); } - ); + std::string moduleIdentifier = ghoul::toLowerCase(identifier()); // First try the internal module directory std::filesystem::path path = absPath("${MODULES}/" + moduleIdentifier); diff --git a/src/util/time.cpp b/src/util/time.cpp index d83b6378da..87810e03ba 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -40,8 +40,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/src/util/versionchecker.cpp b/src/util/versionchecker.cpp index de72a3af4f..70ad442d80 100644 --- a/src/util/versionchecker.cpp +++ b/src/util/versionchecker.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include