@@ -19,7 +19,7 @@ use fold::Fold;
1919use fold;
2020use pass:: Pass ;
2121
22- use core:: str ;
22+ use core:: iterator :: IteratorUtil ;
2323
2424pub fn mk_pass ( ) -> Pass {
2525 Pass {
@@ -104,39 +104,37 @@ fn sectionalize(desc: Option<~str>) -> (Option<~str>, ~[doc::Section]) {
104104 if desc. is_none ( ) {
105105 return ( None , ~[ ] ) ;
106106 }
107- let mut lines = ~[ ] ;
108- for str:: each_line_any( * desc. get_ref ( ) ) |line| { lines. push ( line. to_owned ( ) ) ; }
109107
110108 let mut new_desc = None :: < ~str > ;
111109 let mut current_section = None ;
112110 let mut sections = ~[ ] ;
113111
114- for lines . each |line| {
115- match parse_header ( copy * line) {
112+ for desc . get_ref ( ) . any_line_iter ( ) . advance |line| {
113+ match parse_header( line) {
116114 Some ( header) => {
117115 if current_section. is_some( ) {
118- sections += [ copy * current_section. get_ref ( ) ] ;
116+ sections. push ( copy * current_section. get_ref( ) ) ;
119117 }
120118 current_section = Some ( doc:: Section {
121- header : header,
119+ header : header. to_owned ( ) ,
122120 body: ~""
123121 } ) ;
124122 }
125123 None => {
126124 match copy current_section {
127125 Some ( section) => {
128126 current_section = Some ( doc:: Section {
129- body : section . body + " \n " + * line,
127+ body : fmt ! ( "%s \n %s" , section . body , line) ,
130128 .. section
131129 } ) ;
132130 }
133131 None => {
134132 new_desc = match copy new_desc {
135133 Some ( desc) => {
136- Some ( desc + " \n " + * line)
134+ Some ( fmt ! ( "%s \n %s" , desc , line) )
137135 }
138136 None => {
139- Some ( copy * line)
137+ Some ( line. to_owned ( ) )
140138 }
141139 } ;
142140 }
@@ -146,15 +144,15 @@ fn sectionalize(desc: Option<~str>) -> (Option<~str>, ~[doc::Section]) {
146144 }
147145
148146 if current_section. is_some( ) {
149- sections += [ current_section. get ( ) ] ;
147+ sections. push ( current_section. unwrap ( ) ) ;
150148 }
151149
152150 ( new_desc, sections)
153151}
154152
155- fn parse_header( line: ~ str ) -> Option <~ str> {
153+ fn parse_header < ' a > ( line: & ' a str) -> Option <& ' a str > {
156154 if line. starts_with ( "# " ) {
157- Some ( line. slice ( 2 u , line . len ( ) ) . to_owned ( ) )
155+ Some ( line. slice_from ( 2 ) )
158156 } else {
159157 None
160158 }
0 commit comments