Skip to content

Commit 3c3887b

Browse files
committedJan 3, 2015
Deduplicate code and use stdlib in string functions
1 parent d91559b commit 3c3887b

File tree

4 files changed

+162
-212
lines changed

4 files changed

+162
-212
lines changed
 

‎src/test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct TestUtilities: public TestBase
189189
str_replace(test_str, "there", "world");
190190
UASSERT(test_str == "Hello world");
191191
test_str = "ThisAisAaAtest";
192-
str_replace_char(test_str, 'A', ' ');
192+
str_replace(test_str, 'A', ' ');
193193
UASSERT(test_str == "This is a test");
194194
UASSERT(string_allowed("hello", "abcdefghijklmno") == true);
195195
UASSERT(string_allowed("123", "abcdefghijklmno") == false);

‎src/tile.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
13801380
return false;
13811381
}
13821382

1383-
str_replace_char(part_of_name, '&', '^');
1383+
str_replace(part_of_name, '&', '^');
13841384
Strfnd sf(part_of_name);
13851385
sf.next("{");
13861386
std::string imagename_top = sf.next("{");

‎src/util/string.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222
#include "numeric.h"
2323
#include "log.h"
2424

25-
#include <sstream>
26-
#include <iomanip>
27-
#include <map>
28-
2925
#include "../sha1.h"
3026
#include "../base64.h"
3127
#include "../hex.h"
3228
#include "../porting.h"
3329

30+
#include <algorithm>
31+
#include <sstream>
32+
#include <iomanip>
33+
#include <map>
34+
3435
static bool parseHexColorString(const std::string &value, video::SColor &color);
3536
static bool parseNamedColorString(const std::string &value, video::SColor &color);
3637

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

578579
return true;
579580
}
581+
582+
void str_replace(std::string &str, char from, char to)
583+
{
584+
std::replace(str.begin(), str.end(), from, to);
585+
}
586+

0 commit comments

Comments
 (0)
Please sign in to comment.