Skip to content

Commit da6f0e8

Browse files
committed
---
yaml --- r: 54431 b: refs/heads/snap-stage3 c: df66e8d h: refs/heads/master i: 54429: 1a3e3c4 54427: 495ac69 54423: 3b83e1d 54415: 37f267a 54399: 4447124 v: v3
1 parent 8a557fd commit da6f0e8

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 75d615d6f6d8fd8e931689106dfa22e4a6e662a2
4+
refs/heads/snap-stage3: df66e8d4a197443c214e918a858208ecc38e9f1c
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/str.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,8 +1865,10 @@ pub struct CharRange {
18651865
* Given a byte position and a str, return the previous char and its position
18661866
*
18671867
* This function can be used to iterate over a unicode string in reverse.
1868+
*
1869+
* returns 0 for next index if called on start index 0
18681870
*/
1869-
fn char_range_at_reverse(ss: &str, start: uint) -> CharRange {
1871+
pub fn char_range_at_reverse(ss: &str, start: uint) -> CharRange {
18701872
let mut prev = start;
18711873

18721874
// while there is a previous byte == 10......
@@ -1875,7 +1877,12 @@ fn char_range_at_reverse(ss: &str, start: uint) -> CharRange {
18751877
}
18761878

18771879
// now refer to the initial byte of previous char
1878-
prev -= 1u;
1880+
if prev > 0u {
1881+
prev -= 1u;
1882+
} else {
1883+
prev = 0u;
1884+
}
1885+
18791886

18801887
let ch = char_at(ss, prev);
18811888
return CharRange {ch:ch, next:prev};
@@ -3761,4 +3768,10 @@ mod tests {
37613768
"12345555".cmp(& &"123456") == Less;
37623769
"22".cmp(& &"1234") == Greater;
37633770
}
3771+
3772+
#[test]
3773+
fn test_char_range_at_reverse_underflow() {
3774+
assert!(char_range_at_reverse("abc", 0).next == 0);
3775+
}
3776+
37643777
}

0 commit comments

Comments
 (0)