LaurentGomila/SFML — pull request #355 by abodelot (2013-02-16 21:48:03+00:00)
Title: substr and replace methods for sf::String

This patch is a fix for issue #21 and provides *substr* and *replace* (2) methods for sf::String.

The *substr* and the first *replace* methods are pretty much equivalent to their std::string counterparts.

```c++
// Generate a substring
String substr(std::size_t pos = 0, std::size_t len = InvalidPos) const;
// Replace a portion of the string
void replace(std::size_t pos, std::size_t len, const String& str);
```

The second *replace* method allows user to replace a substring by a replacement value.

```c++
// Replace all occurrences of a substring with a replacement string
String replace(const String& search, const String& replacement) const;
```
Please find bellow a test case for these new methods:

```c++
#include
#include

int main()
{
// Test sf::String::substr
sf::String string("Hello, World!");
assert(string.substr() == string);
assert(string.substr(0) == string);
assert(string.substr(0, 5) == "Hello");
assert(string.substr(7, 5) == "World");
assert(string.substr(7) == "World!");
assert(string.substr(7, 9000) == "World!");

// Test sf::String::replace (1)
string.replace(0, 5, "Hi");
assert(string == "Hi, World!");
string.replace(4, sf::String::InvalidPos, "SFML!");
assert(string == "Hi, SFML!");

// Test sf::String::replace (2)
string = "foobar foobaz barbaz";
assert(string.replace("foo", "bar") == "barbar barbaz barbaz");
assert(string.replace("baz", "bar") == "foobar foobar barbar");

return 0;
}
```

Regards,

-- Alexandre