Skip to content

Commit c8fdc3b

Browse files
committed
---
yaml --- r: 7326 b: refs/heads/master c: 1223bbc h: refs/heads/master v: v3
1 parent 9afd12f commit c8fdc3b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: b3927d605255c806ddf4654fae1bf72d5c0ca55a
2+
refs/heads/master: 1223bbc4de2165097f6b044d7477940ad2499c0f

trunk/src/libcore/str.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,13 @@ fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str {
962962
} else if starts_with(s, from) {
963963
ret to + replace(slice(s, byte_len(from), byte_len(s)), from, to);
964964
} else {
965-
ret unsafe_from_byte(s[0]) +
966-
replace(slice(s, 1u, byte_len(s)), from, to);
965+
let idx = find(s, from);
966+
if idx == -1 {
967+
ret s;
968+
}
969+
ret char_slice(s, 0u, idx as uint) + to +
970+
replace(char_slice(s, idx as uint + char_len(from), char_len(s)),
971+
from, to);
967972
}
968973
}
969974

0 commit comments

Comments
 (0)