Skip to content

Commit

Permalink
Deduplicate code and use stdlib in string functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowNinja committed Jan 3, 2015
1 parent d91559b commit 3c3887b
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 212 deletions.
2 changes: 1 addition & 1 deletion src/test.cpp
Expand Up @@ -189,7 +189,7 @@ struct TestUtilities: public TestBase
str_replace(test_str, "there", "world");
UASSERT(test_str == "Hello world");
test_str = "ThisAisAaAtest";
str_replace_char(test_str, 'A', ' ');
str_replace(test_str, 'A', ' ');
UASSERT(test_str == "This is a test");
UASSERT(string_allowed("hello", "abcdefghijklmno") == true);
UASSERT(string_allowed("123", "abcdefghijklmno") == false);
Expand Down
2 changes: 1 addition & 1 deletion src/tile.cpp
Expand Up @@ -1380,7 +1380,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
return false;
}

str_replace_char(part_of_name, '&', '^');
str_replace(part_of_name, '&', '^');
Strfnd sf(part_of_name);
sf.next("{");
std::string imagename_top = sf.next("{");
Expand Down
15 changes: 11 additions & 4 deletions src/util/string.cpp
Expand Up @@ -22,15 +22,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "numeric.h"
#include "log.h"

#include <sstream>
#include <iomanip>
#include <map>

#include "../sha1.h"
#include "../base64.h"
#include "../hex.h"
#include "../porting.h"

#include <algorithm>
#include <sstream>
#include <iomanip>
#include <map>

static bool parseHexColorString(const std::string &value, video::SColor &color);
static bool parseNamedColorString(const std::string &value, video::SColor &color);

Expand Down Expand Up @@ -577,3 +578,9 @@ static bool parseNamedColorString(const std::string &value, video::SColor &color

return true;
}

void str_replace(std::string &str, char from, char to)
{
std::replace(str.begin(), str.end(), from, to);
}

0 comments on commit 3c3887b

Please sign in to comment.