Skip to content

Commit

Permalink
Ignore whitespace only lines in brewing and furnace recipes (cuberite…
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbell10 authored Jun 11, 2019
1 parent 52e6543 commit 9dc1343
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/BrewingRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ void cBrewingRecipes::ReloadRecipes(void)
ParsingLine.erase(FirstCommentSymbol);
}

if (ParsingLine.empty())
if (IsOnlyWhitespace(ParsingLine))
{
// Ignore empty and whitespace only lines
continue;
}
AddRecipeFromLine(ParsingLine, LineNum);
Expand Down
14 changes: 6 additions & 8 deletions src/FurnaceRecipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ void cFurnaceRecipe::ReloadRecipes(void)
while (std::getline(f, ParsingLine))
{
LineNum++;
if (ParsingLine.empty())
{
// There is a problem here on Android. Text files transferred from another OS may have a newline representation Android's implementation of getline doesn't expect
// Thus, part of a newline may be left in ParsingLine. ::empty() thus thinks the string isn't empty, and the below code outputs interesting errors since it was passed a nearly empty string
// Ref: https://stackoverflow.com/questions/6089231/getting-std-ifstream-to-handle-lf-cr-and-crlf
// TODO: There is a solution in the above reference, but it isn't very pretty. Fix it somehow.
continue;
}

// Remove comments from the line:
size_t FirstCommentSymbol = ParsingLine.find('#');
Expand All @@ -84,6 +76,12 @@ void cFurnaceRecipe::ReloadRecipes(void)
ParsingLine.erase(ParsingLine.begin() + static_cast<const long>(FirstCommentSymbol), ParsingLine.end());
}

if (IsOnlyWhitespace(ParsingLine))
{
// Ignore empty and whitespace only lines
continue;
}

switch (ParsingLine[0])
{
case '#':
Expand Down
8 changes: 8 additions & 0 deletions src/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,3 +1071,11 @@ bool StringToFloat(const AString & a_String, float & a_Num)
return true;
}





bool IsOnlyWhitespace(const AString & a_String)
{
return std::all_of(a_String.cbegin(), a_String.cend(), isspace);
}
3 changes: 3 additions & 0 deletions src/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ extern AString StringsConcat(const AStringVector & a_Strings, char a_Separator);
/** Converts a string into a float. Returns false if the conversion fails. */
extern bool StringToFloat(const AString & a_String, float & a_Num);

/** Returns true if only whitespace characters are present in the string */
bool IsOnlyWhitespace(const AString & a_String);




Expand Down

0 comments on commit 9dc1343

Please sign in to comment.