From f05914150540fb44b6f580b5b02d0d528b432b68 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Fri, 27 Sep 2024 22:46:50 +0100 Subject: [PATCH] [*] AuCmdLine::GetValue(...) (both variants) refactored to use views to help with future stability issues around AuStrings (and their allocator?) --- Include/Aurora/CmdLine/CmdLine.hpp | 4 ++-- Source/CmdLine/AuCmdLine.cpp | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Include/Aurora/CmdLine/CmdLine.hpp b/Include/Aurora/CmdLine/CmdLine.hpp index 7d0ea867..371204a4 100644 --- a/Include/Aurora/CmdLine/CmdLine.hpp +++ b/Include/Aurora/CmdLine/CmdLine.hpp @@ -36,14 +36,14 @@ namespace Aurora::CmdLine * @param defaultValue * @return */ - AUKN_SYM const AuString &GetValue(const AuROString &key, const AuString &defaultValue); + AUKN_SYM AuROString GetValue(const AuROString &key, const AuROString &defaultValue); /** * @brief Returns part after key= * @param key * @return */ - AUKN_SYM AuOptional GetValue(const AuROString &key); + AUKN_SYM AuOptional GetValue(const AuROString &key); /** * @brief Returns a constant array of values; key=values and /key values diff --git a/Source/CmdLine/AuCmdLine.cpp b/Source/CmdLine/AuCmdLine.cpp index e5e8dfa9..97dd9845 100644 --- a/Source/CmdLine/AuCmdLine.cpp +++ b/Source/CmdLine/AuCmdLine.cpp @@ -35,27 +35,32 @@ namespace Aurora::CmdLine AuExists(gCmdValueMap, key); } - AUKN_SYM const AuString &GetValue(const AuROString &key, const AuString &defaultValue) + AUKN_SYM AuROString GetValue(const AuROString &key, const AuROString &defaultValue) { - auto itr = gCmdValueMap.find(key); - if (itr == gCmdValueMap.end()) + AuString *pValue {}; + + if (AuTryFind(gCmdValueMap, key, pValue)) { - return defaultValue; + return *pValue; } else { - return itr->second; + return defaultValue; } } - AUKN_SYM AuOptional GetValue(const AuROString &key) + AUKN_SYM AuOptional GetValue(const AuROString &key) { - auto itr = gCmdValueMap.find(key); - if (itr == gCmdValueMap.end()) + AuString *pValue {}; + + if (AuTryFind(gCmdValueMap, key, pValue)) { - return AuOptional {}; + return *pValue; + } + else + { + return AuOptional {}; } - return itr->second; } AUKN_SYM const AuList &GetValues(const AuROString &key)