File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5
- refs/heads/try: d1c9b160adf5f13bca690e114f254b5353fe798d
5
+ refs/heads/try: 042a5222d1f324a60b61bbc58f3938770d3e0cd0
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Original file line number Diff line number Diff line change @@ -157,7 +157,8 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
157
157
158
158
fn get_line ( fm : filemap , line : int ) -> str unsafe {
159
159
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 ) ) {
161
162
some ( e) { e }
162
163
none { str : : len ( * fm. src ) }
163
164
} ;
Original file line number Diff line number Diff line change 71
71
// Searching
72
72
index,
73
73
byte_index,
74
+ byte_index_from,
74
75
rindex,
75
76
find,
76
77
find_bytes,
@@ -859,13 +860,19 @@ fn index(ss: str, cc: char) -> option<uint> {
859
860
//
860
861
// Returns the index of the first matching byte
861
862
// (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 += 1 u;
867
- }
868
- ret none;
863
+ fn byte_index ( s : str , b : u8 ) -> option < uint > {
864
+ byte_index_from ( s, b, 0 u, 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 } }
869
876
}
870
877
871
878
// Function: rindex
You can’t perform that action at this time.
0 commit comments