Skip to content

Commit

Permalink
remove exceptions from remaining int conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Jan 26, 2024
1 parent f140cb2 commit fceb9b9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
21 changes: 6 additions & 15 deletions src/managers/BetterInfoStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,8 @@ time_t BetterInfoStats::getCompletion(GJGameLevel* level, bool practice) {

auto ret = dict->valueForKey(keyForLevel(level));
if(std::string_view(ret->getCString()).empty()) return 0;
try {
return std::strtol(ret->getCString(), nullptr, 10);
} catch(...) {
return 0;
}

return BetterInfo::strtol(ret->getCString());
}

void BetterInfoStats::logPlay(GJGameLevel* level) {
Expand All @@ -161,11 +158,8 @@ time_t BetterInfoStats::getPlay(GJGameLevel* level, bool last) {

auto ret = dict->valueForKey(keyForLevel(level));
if(std::string_view(ret->getCString()).empty()) return 0;
try {
return std::strtol(ret->getCString(), nullptr, 10);
} catch(...) {
return 0;
}

return BetterInfo::strtol(ret->getCString());
}

std::string BetterInfoStats::keyForLevel(GJGameLevel* level) {
Expand All @@ -185,9 +179,6 @@ int BetterInfoStats::getAttempts(GJGameLevel* level, bool practice) {

auto ret = dict->valueForKey(keyForLevel(level));
if(std::string_view(ret->getCString()).empty()) return 0;
try {
return std::strtol(ret->getCString(), nullptr, 10);
} catch(...) {
return 0;
}

return BetterInfo::stoi(ret->getCString());
}
6 changes: 6 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,4 +709,10 @@ int BetterInfo::stoi(std::string_view str) {
int result = 0;
std::from_chars(str.data(), str.data() + str.size(), result);
return result;
}

long long BetterInfo::strtol(std::string_view str) {
long long result = 0;
std::from_chars(str.data(), str.data() + str.size(), result);
return result;
}
1 change: 1 addition & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ namespace BetterInfo {
AxisLayoutOptions* copyLayoutOptions(AxisLayoutOptions* a);

int stoi(std::string_view str);
long long strtol(std::string_view str);
}
6 changes: 2 additions & 4 deletions src/utils/LevelProgressDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

#include "../managers/BetterInfoStats.h"
#include "../layers/PaginatedFLAlert.h"
#include "../utils.hpp"

std::string LevelProgressDialog::printableProgress(std::string personalBests, int percentage){

std::stringstream bestsStream(personalBests);
std::string currentBest;
std::deque<int> progresses;
while(getline(bestsStream, currentBest, ',')){
try {
progresses.push_front(std::stoi(currentBest));
//contentStream << percentage << "% ";
}catch(...){}
progresses.push_front(BetterInfo::stoi(currentBest));
}
std::string printable;
//std::reverse(std::begin(progresses), std::end(progresses));
Expand Down

0 comments on commit fceb9b9

Please sign in to comment.