diff options
| author | Shauren <shauren.trinity@gmail.com> | 2023-05-13 15:46:27 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2023-05-13 15:46:27 +0200 |
| commit | 3260b94dd627b7b0c7114f94bb97d108b005af3e (patch) | |
| tree | 980d58d6db4a3d20785f8bca881d36f79d0f5755 /src/common/IPLocation | |
| parent | c4d40085964109893c76d301b6f7d99f03838fa0 (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.cpp | 15 |
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; }); |
