aboutsummaryrefslogtreecommitdiff
path: root/src/common/IPLocation
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-05-13 15:46:27 +0200
committerShauren <shauren.trinity@gmail.com>2023-05-13 15:46:27 +0200
commit3260b94dd627b7b0c7114f94bb97d108b005af3e (patch)
tree980d58d6db4a3d20785f8bca881d36f79d0f5755 /src/common/IPLocation
parentc4d40085964109893c76d301b6f7d99f03838fa0 (diff)
Core/Misc: Replace string to int conversion functions from Common.h with c++17 std::from_chars based ones Trinity::StringTo
Diffstat (limited to 'src/common/IPLocation')
-rw-r--r--src/common/IPLocation/IPLocation.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/common/IPLocation/IPLocation.cpp b/src/common/IPLocation/IPLocation.cpp
index 060972fa5b4..d707d366928 100644
--- a/src/common/IPLocation/IPLocation.cpp
+++ b/src/common/IPLocation/IPLocation.cpp
@@ -16,11 +16,12 @@
*/
#include "IPLocation.h"
-#include "Common.h"
#include "Config.h"
#include "Errors.h"
#include "IpAddress.h"
#include "Log.h"
+#include "StringConvert.h"
+#include "Util.h"
#include <fstream>
IpLocationStore::IpLocationStore()
@@ -82,9 +83,17 @@ void IpLocationStore::Load()
countryName.erase(std::remove(countryName.begin(), countryName.end(), '"'), countryName.end());
// Convert country code to lowercase
- std::transform(countryCode.begin(), countryCode.end(), countryCode.begin(), ::tolower);
+ strToLower(countryCode);
- _ipLocationStore.emplace_back(uint32(atoul(ipFrom.c_str())), uint32(atoul(ipTo.c_str())), std::move(countryCode), std::move(countryName));
+ Optional<uint32> from = Trinity::StringTo<uint32>(ipFrom);
+ if (!from)
+ continue;
+
+ Optional<uint32> to = Trinity::StringTo<uint32>(ipTo);
+ if (!to)
+ continue;
+
+ _ipLocationStore.emplace_back(*from, *to, std::move(countryCode), std::move(countryName));
}
std::sort(_ipLocationStore.begin(), _ipLocationStore.end(), [](IpLocationRecord const& a, IpLocationRecord const& b) { return a.IpFrom < b.IpFrom; });