Skip to content

Commit e684294

Browse files
committed
---
yaml --- r: 56799 b: refs/heads/try c: 4ad76e6 h: refs/heads/master i: 56797: a76217c 56795: 87c649f 56791: 6326ff4 56783: 1554c31 56767: 245e3d3 v: v3
1 parent 4e11296 commit e684294

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
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: 9a16179fd3ec18e8f3bc4ca68054981f6628fdcd
5+
refs/heads/try: 4ad76e66aad1813bc927ae1b5cf8205c8c5a8944
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/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)