Skip to content

Commit 82e7533

Browse files
committed
---
yaml --- r: 54631 b: refs/heads/snap-stage3 c: 4ad76e6 h: refs/heads/master i: 54629: 219edf2 54627: 994458b 54623: be269b2 v: v3
1 parent 86ee9b9 commit 82e7533

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
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: 9a16179fd3ec18e8f3bc4ca68054981f6628fdcd
4+
refs/heads/snap-stage3: 4ad76e66aad1813bc927ae1b5cf8205c8c5a8944
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,18 @@ pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
20562056

20572057
/**
20582058
* Returns the byte offset of an inner slice relative to an enclosing outer slice
2059+
*
2060+
* # Example
2061+
*
2062+
* ~~~
2063+
* let string = "a\nb\nc";
2064+
* let mut lines = ~[];
2065+
* for each_line(string) |line| { lines.push(line) }
2066+
*
2067+
* assert!(subslice_offset(string, lines[0]) == 0); // &"a"
2068+
* assert!(subslice_offset(string, lines[1]) == 2); // &"b"
2069+
* assert!(subslice_offset(string, lines[2]) == 4); // &"c"
2070+
* ~~~
20592071
*/
20602072
#[inline(always)]
20612073
pub fn subslice_offset(outer: &str, inner: &str) -> uint {
@@ -3461,6 +3473,13 @@ mod tests {
34613473
let c = slice(a, 0, len(a) - 6);
34623474
assert!(subslice_offset(a, b) == 7);
34633475
assert!(subslice_offset(a, c) == 0);
3476+
3477+
let string = "a\nb\nc";
3478+
let mut lines = ~[];
3479+
for each_line(string) |line| { lines.push(line) }
3480+
assert!(subslice_offset(string, lines[0]) == 0);
3481+
assert!(subslice_offset(string, lines[1]) == 2);
3482+
assert!(subslice_offset(string, lines[2]) == 4);
34643483
}
34653484
34663485
#[test]

0 commit comments

Comments
 (0)