Skip to content

Commit

Permalink
Clean up Strfnd
Browse files Browse the repository at this point in the history
Changes:
  * Fix indentation.
  * Pass strings by const reference.
  * Merge Strfnd and WStrfnd into one class instead of copying them.
  * Remove trailing spaces.
  * Fix variable names.
  * Move to util.
  * Other miscellaneous style fixes.
  • Loading branch information
ShadowNinja committed Mar 20, 2016
1 parent eb7db21 commit 9388704
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 198 deletions.
2 changes: 1 addition & 1 deletion src/ban.cpp
Expand Up @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "threading/mutex_auto_lock.h" #include "threading/mutex_auto_lock.h"
#include <sstream> #include <sstream>
#include <set> #include <set>
#include "strfnd.h" #include "util/strfnd.h"
#include "util/string.h" #include "util/string.h"
#include "log.h" #include "log.h"
#include "filesys.h" #include "filesys.h"
Expand Down
4 changes: 2 additions & 2 deletions src/chat.cpp
Expand Up @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,


#include "chat.h" #include "chat.h"
#include "debug.h" #include "debug.h"
#include "strfnd.h" #include "util/strfnd.h"
#include <cctype> #include <cctype>
#include <sstream> #include <sstream>
#include "util/string.h" #include "util/string.h"
Expand Down Expand Up @@ -684,7 +684,7 @@ void ChatBackend::addMessage(std::wstring name, std::wstring text)


// Note: A message may consist of multiple lines, for example the MOTD. // Note: A message may consist of multiple lines, for example the MOTD.
WStrfnd fnd(text); WStrfnd fnd(text);
while (!fnd.atend()) while (!fnd.at_end())
{ {
std::wstring line = fnd.next(L"\n"); std::wstring line = fnd.next(L"\n");
m_console_buffer.addLine(name, line); m_console_buffer.addLine(name, line);
Expand Down
4 changes: 2 additions & 2 deletions src/client/tile.cpp
Expand Up @@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mesh.h" #include "mesh.h"
#include "log.h" #include "log.h"
#include "gamedef.h" #include "gamedef.h"
#include "strfnd.h" #include "util/strfnd.h"
#include "util/string.h" // for parseColorString() #include "util/string.h" // for parseColorString()
#include "imagefilters.h" #include "imagefilters.h"
#include "guiscalingfilter.h" #include "guiscalingfilter.h"
Expand Down Expand Up @@ -1242,7 +1242,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
baseimg->fill(video::SColor(0,0,0,0)); baseimg->fill(video::SColor(0,0,0,0));
} }
while (sf.atend() == false) { while (sf.at_end() == false) {
u32 x = stoi(sf.next(",")); u32 x = stoi(sf.next(","));
u32 y = stoi(sf.next("=")); u32 y = stoi(sf.next("="));
std::string filename = sf.next(":"); std::string filename = sf.next(":");
Expand Down
4 changes: 2 additions & 2 deletions src/craftdef.cpp
Expand Up @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/serialize.h" #include "util/serialize.h"
#include "util/string.h" #include "util/string.h"
#include "util/numeric.h" #include "util/numeric.h"
#include "strfnd.h" #include "util/strfnd.h"
#include "exceptions.h" #include "exceptions.h"


inline bool isGroupRecipeStr(const std::string &rec_name) inline bool isGroupRecipeStr(const std::string &rec_name)
Expand Down Expand Up @@ -90,7 +90,7 @@ static bool inputItemMatchesRecipe(const std::string &inp_name,
all_groups_match = false; all_groups_match = false;
break; break;
} }
} while (!f.atend()); } while (!f.at_end());
if (all_groups_match) if (all_groups_match)
return true; return true;
} }
Expand Down
2 changes: 1 addition & 1 deletion src/guiFormSpecMenu.cpp
Expand Up @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "constants.h" #include "constants.h"
#include "gamedef.h" #include "gamedef.h"
#include "keycode.h" #include "keycode.h"
#include "strfnd.h" #include "util/strfnd.h"
#include <IGUICheckBox.h> #include <IGUICheckBox.h>
#include <IGUIEditBox.h> #include <IGUIEditBox.h>
#include <IGUIButton.h> #include <IGUIButton.h>
Expand Down
6 changes: 3 additions & 3 deletions src/inventory.cpp
Expand Up @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sstream> #include <sstream>
#include "log.h" #include "log.h"
#include "itemdef.h" #include "itemdef.h"
#include "strfnd.h" #include "util/strfnd.h"
#include "content_mapnode.h" // For loading legacy MaterialItems #include "content_mapnode.h" // For loading legacy MaterialItems
#include "nameidmapping.h" // For loading legacy MaterialItems #include "nameidmapping.h" // For loading legacy MaterialItems
#include "util/serialize.h" #include "util/serialize.h"
Expand Down Expand Up @@ -218,7 +218,7 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
Strfnd fnd(all); Strfnd fnd(all);
fnd.next("\""); fnd.next("\"");
// If didn't skip to end, we have ""s // If didn't skip to end, we have ""s
if(!fnd.atend()){ if(!fnd.at_end()){
name = fnd.next("\""); name = fnd.next("\"");
} else { // No luck, just read a word then } else { // No luck, just read a word then
fnd.start(all); fnd.start(all);
Expand Down Expand Up @@ -246,7 +246,7 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
Strfnd fnd(all); Strfnd fnd(all);
fnd.next("\""); fnd.next("\"");
// If didn't skip to end, we have ""s // If didn't skip to end, we have ""s
if(!fnd.atend()){ if(!fnd.at_end()){
name = fnd.next("\""); name = fnd.next("\"");
} else { // No luck, just read a word then } else { // No luck, just read a word then
fnd.start(all); fnd.start(all);
Expand Down
2 changes: 1 addition & 1 deletion src/inventorymanager.cpp
Expand Up @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h" #include "settings.h"
#include "craftdef.h" #include "craftdef.h"
#include "rollback_interface.h" #include "rollback_interface.h"
#include "strfnd.h" #include "util/strfnd.h"


#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"


Expand Down
4 changes: 2 additions & 2 deletions src/mods.cpp
Expand Up @@ -21,11 +21,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <fstream> #include <fstream>
#include "mods.h" #include "mods.h"
#include "filesys.h" #include "filesys.h"
#include "strfnd.h" #include "util/strfnd.h"
#include "log.h" #include "log.h"
#include "subgame.h" #include "subgame.h"
#include "settings.h" #include "settings.h"
#include "strfnd.h" #include "util/strfnd.h"
#include "convert_json.h" #include "convert_json.h"
#include "exceptions.h" #include "exceptions.h"


Expand Down
4 changes: 2 additions & 2 deletions src/network/clientpackethandler.cpp
Expand Up @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodedef.h" #include "nodedef.h"
#include "serialization.h" #include "serialization.h"
#include "server.h" #include "server.h"
#include "strfnd.h" #include "util/strfnd.h"
#include "network/clientopcodes.h" #include "network/clientopcodes.h"
#include "util/serialize.h" #include "util/serialize.h"
#include "util/srp.h" #include "util/srp.h"
Expand Down Expand Up @@ -641,7 +641,7 @@ void Client::handleCommand_AnnounceMedia(NetworkPacket* pkt)
*pkt >> str; *pkt >> str;


Strfnd sf(str); Strfnd sf(str);
while(!sf.atend()) { while(!sf.at_end()) {
std::string baseurl = trim(sf.next(",")); std::string baseurl = trim(sf.next(","));
if (baseurl != "") if (baseurl != "")
m_media_downloader->addRemoteServer(baseurl); m_media_downloader->addRemoteServer(baseurl);
Expand Down
2 changes: 1 addition & 1 deletion src/settings.cpp
Expand Up @@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_bloated.h" #include "irrlichttypes_bloated.h"
#include "exceptions.h" #include "exceptions.h"
#include "threading/mutex_auto_lock.h" #include "threading/mutex_auto_lock.h"
#include "strfnd.h" #include "util/strfnd.h"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
Expand Down
1 change: 0 additions & 1 deletion src/shader.cpp
Expand Up @@ -35,7 +35,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "EShaderTypes.h" #include "EShaderTypes.h"
#include "log.h" #include "log.h"
#include "gamedef.h" #include "gamedef.h"
#include "strfnd.h" // trim()
#include "client/tile.h" #include "client/tile.h"


/* /*
Expand Down
176 changes: 0 additions & 176 deletions src/strfnd.h

This file was deleted.

8 changes: 4 additions & 4 deletions src/subgame.cpp
Expand Up @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "filesys.h" #include "filesys.h"
#include "settings.h" #include "settings.h"
#include "log.h" #include "log.h"
#include "strfnd.h" #include "util/strfnd.h"
#include "defaultsettings.h" // for override_default_settings #include "defaultsettings.h" // for override_default_settings
#include "mapgen.h" // for MapgenParams #include "mapgen.h" // for MapgenParams
#include "util/string.h" #include "util/string.h"
Expand Down Expand Up @@ -79,7 +79,7 @@ SubgameSpec findSubgame(const std::string &id)


Strfnd search_paths(getSubgamePathEnv()); Strfnd search_paths(getSubgamePathEnv());


while (!search_paths.atend()) { while (!search_paths.at_end()) {
std::string path = search_paths.next(PATH_DELIM); std::string path = search_paths.next(PATH_DELIM);
find_paths.push_back(GameFindPath( find_paths.push_back(GameFindPath(
path + DIR_DELIM + id, false)); path + DIR_DELIM + id, false));
Expand Down Expand Up @@ -153,7 +153,7 @@ std::set<std::string> getAvailableGameIds()


Strfnd search_paths(getSubgamePathEnv()); Strfnd search_paths(getSubgamePathEnv());


while (!search_paths.atend()) while (!search_paths.at_end())
gamespaths.insert(search_paths.next(PATH_DELIM)); gamespaths.insert(search_paths.next(PATH_DELIM));


for (std::set<std::string>::const_iterator i = gamespaths.begin(); for (std::set<std::string>::const_iterator i = gamespaths.begin();
Expand Down Expand Up @@ -230,7 +230,7 @@ std::vector<WorldSpec> getAvailableWorlds()


Strfnd search_paths(getWorldPathEnv()); Strfnd search_paths(getWorldPathEnv());


while (!search_paths.atend()) while (!search_paths.at_end())
worldspaths.insert(search_paths.next(PATH_DELIM)); worldspaths.insert(search_paths.next(PATH_DELIM));


worldspaths.insert(porting::path_user + DIR_DELIM + "worlds"); worldspaths.insert(porting::path_user + DIR_DELIM + "worlds");
Expand Down

0 comments on commit 9388704

Please sign in to comment.