Skip to content

Commit cf58d50

Browse files
committed
---
yaml --- r: 14332 b: refs/heads/try c: 042a522 h: refs/heads/master v: v3
1 parent a22f373 commit cf58d50

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: d1c9b160adf5f13bca690e114f254b5353fe798d
5+
refs/heads/try: 042a5222d1f324a60b61bbc58f3938770d3e0cd0
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/comp/syntax/codemap.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
157157

158158
fn get_line(fm: filemap, line: int) -> str unsafe {
159159
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
160-
let end = alt str::byte_index(*fm.src, '\n' as u8, begin) {
160+
let end = alt str::byte_index_from(*fm.src, '\n' as u8, begin,
161+
str::len(*fm.src)) {
161162
some(e) { e }
162163
none { str::len(*fm.src) }
163164
};

branches/try/src/libcore/str.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export
7171
// Searching
7272
index,
7373
byte_index,
74+
byte_index_from,
7475
rindex,
7576
find,
7677
find_bytes,
@@ -859,13 +860,19 @@ fn index(ss: str, cc: char) -> option<uint> {
859860
//
860861
// Returns the index of the first matching byte
861862
// (as option some/none)
862-
fn byte_index(s: str, b: u8, start: uint) -> option<uint> {
863-
let i = start, l = len_bytes(s);
864-
while i < l {
865-
if s[i] == b { ret some(i); }
866-
i += 1u;
867-
}
868-
ret none;
863+
fn byte_index(s: str, b: u8) -> option<uint> {
864+
byte_index_from(s, b, 0u, len_bytes(s))
865+
}
866+
867+
// Function: byte_index_from
868+
//
869+
// Returns the index of the first matching byte within the range [`start`,
870+
// `end`).
871+
// (as option some/none)
872+
fn byte_index_from(s: str, b: u8, start: uint, end: uint) -> option<uint> {
873+
assert end <= len_bytes(s);
874+
875+
str::as_bytes(s) { |v| vec::position_from(v, start, end) { |x| x == b } }
869876
}
870877

871878
// Function: rindex

0 commit comments

Comments
 (0)