aboutsummaryrefslogtreecommitdiff
path: root/src/common/IPLocation/IPLocation.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-05-13 15:46:27 +0200
committerShauren <shauren.trinity@gmail.com>2023-08-15 21:59:52 +0200
commita4299c2a4b88d1cbdcea1301a190da6081abf876 (patch)
tree85b194c12b0413b8da3ad554633ddeb0fec98185 /src/common/IPLocation/IPLocation.cpp
parentb9201d3c07ecbd690117d248bec238e3657b57b9 (diff)
Core/Misc: Replace string to int conversion functions from Common.h with c++17 std::from_chars based ones Trinity::StringTo
(cherry picked from commit 3260b94dd627b7b0c7114f94bb97d108b005af3e)
Diffstat (limited to 'src/common/IPLocation/IPLocation.cpp')
-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 a1717420eb4..2dfd025fc7e 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>
#include <iostream>
@@ -83,9 +84,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; });