summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/FurnaceRecipe.cpp13
-rw-r--r--src/FurnaceRecipe.h4
2 files changed, 9 insertions, 8 deletions
diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp
index 8040552cc..d53854950 100644
--- a/src/FurnaceRecipe.cpp
+++ b/src/FurnaceRecipe.cpp
@@ -57,7 +57,6 @@ void cFurnaceRecipe::ReloadRecipes(void)
std::ifstream f(FURNACE_RECIPE_FILE, std::ios::in);
if (!f.good())
{
- f.close();
LOG("Could not open the furnace recipes file \"%s\"", FURNACE_RECIPE_FILE);
return;
}
@@ -126,7 +125,6 @@ void cFurnaceRecipe::ReloadRecipes(void)
m_pState->Recipes.push_back(R);
}
}
- f.close();
LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
}
@@ -146,6 +144,7 @@ void cFurnaceRecipe::PrintParseError(unsigned int a_Line, size_t a_Position, con
bool cFurnaceRecipe::ReadMandatoryNumber(AString::size_type & a_Begin, const AString & a_Delimiter, const AString & a_Text, unsigned int a_Line, int & a_Value, bool a_IsLastValue)
{
+ // TODO: replace atoi with std::stoi
AString::size_type End;
if (a_IsLastValue)
{
@@ -167,7 +166,7 @@ bool cFurnaceRecipe::ReadMandatoryNumber(AString::size_type & a_Begin, const ASt
PrintParseError(a_Line, a_Begin, "number");
return false;
}
- a_Value = std::stoi(a_Text.substr(a_Begin, End - a_Begin));
+ a_Value = atoi(a_Text.substr(a_Begin, End - a_Begin).c_str());
a_Begin = End + 1; // Jump over delimiter
return true;
@@ -179,6 +178,7 @@ bool cFurnaceRecipe::ReadMandatoryNumber(AString::size_type & a_Begin, const ASt
bool cFurnaceRecipe::ReadOptionalNumbers(AString::size_type & a_Begin, const AString & a_DelimiterOne, const AString & a_DelimiterTwo, const AString & a_Text, unsigned int a_Line, int & a_ValueOne, int & a_ValueTwo, bool a_IsLastValue)
{
+ // TODO: replace atoi with std::stoi
AString::size_type End, Begin = a_Begin;
End = a_Text.find_first_of(a_DelimiterOne, Begin);
@@ -186,7 +186,7 @@ bool cFurnaceRecipe::ReadOptionalNumbers(AString::size_type & a_Begin, const ASt
{
if (DoesStringContainOnlyNumbers(a_Text.substr(Begin, End - Begin)))
{
- a_ValueOne = std::stoi(a_Text.substr(Begin, End - Begin));
+ a_ValueOne = std::atoi(a_Text.substr(Begin, End - Begin).c_str());
Begin = End + 1;
if (a_IsLastValue)
@@ -209,7 +209,7 @@ bool cFurnaceRecipe::ReadOptionalNumbers(AString::size_type & a_Begin, const ASt
PrintParseError(a_Line, Begin, "number");
return false;
}
- a_ValueTwo = std::stoi(a_Text.substr(Begin, End - Begin));
+ a_ValueTwo = atoi(a_Text.substr(Begin, End - Begin).c_str());
a_Begin = End + 1; // Jump over delimiter
return true;
@@ -229,7 +229,8 @@ bool cFurnaceRecipe::ReadOptionalNumbers(AString::size_type & a_Begin, const ASt
bool cFurnaceRecipe::DoesStringContainOnlyNumbers(const AString & a_String)
{
- return std::all_of(a_String.begin(), a_String.end(), isdigit);
+ // TODO: replace this with std::all_of(a_String.begin(), a_String.end(), isdigit)
+ return a_String.find_first_not_of("0123456789") == AString::npos;
}
diff --git a/src/FurnaceRecipe.h b/src/FurnaceRecipe.h
index cddcc215f..ab78b6051 100644
--- a/src/FurnaceRecipe.h
+++ b/src/FurnaceRecipe.h
@@ -42,7 +42,7 @@ private:
void ClearRecipes(void);
/** Calls LOGWARN with the line, position, and error */
- inline static void PrintParseError(unsigned int a_Line, size_t a_Position, const AString & a_CharactersMissing);
+ static void PrintParseError(unsigned int a_Line, size_t a_Position, const AString & a_CharactersMissing);
/** Reads a number from a string given, starting at a given position and ending at a delimiter given
Updates beginning position to the delimiter found + 1, and updates the value to the one read
@@ -60,7 +60,7 @@ private:
static bool ReadOptionalNumbers(AString::size_type & a_Begin, const AString & a_DelimiterOne, const AString & a_DelimiterTwo, const AString & a_Text, unsigned int a_Line, int & a_ValueOne, int & a_ValueTwo, bool a_IsLastValue = false);
/** Uses std::all_of to determine if a string contains only digits */
- inline static bool DoesStringContainOnlyNumbers(const AString & a_String);
+ static bool DoesStringContainOnlyNumbers(const AString & a_String);
struct sFurnaceRecipeState;