@@ -108,20 +108,32 @@ fn parse_desc(desc: str) -> option<str> {
108108
109109 const max_brief_len: uint = 120 u;
110110
111- let paras = paragraphs ( desc) ;
112-
113- if check vec:: is_not_empty ( paras) {
114- let maybe_brief = vec:: head ( paras) ;
115- if str:: len ( maybe_brief) <= max_brief_len {
116- some ( maybe_brief)
111+ alt first_sentence ( desc) {
112+ some ( first_sentence) {
113+ if str:: len ( first_sentence) <= max_brief_len {
114+ some ( first_sentence)
117115 } else {
118116 none
119117 }
118+ }
119+ none { none }
120+ }
121+ }
122+
123+ fn first_sentence ( s : str ) -> option < str > {
124+ let paras = paragraphs ( s) ;
125+ if vec:: is_not_empty ( paras) {
126+ let first = vec:: head ( sentences ( vec:: head ( paras) ) ) ;
127+ some ( str:: replace ( first, "\n " , " " ) )
120128 } else {
121129 none
122130 }
123131}
124132
133+ fn sentences ( s : str ) -> [ str ] {
134+ str:: split_char ( s, '.' )
135+ }
136+
125137fn paragraphs ( s : str ) -> [ str ] {
126138 let lines = str:: lines_any ( s) ;
127139 let whitespace_lines = 0 ;
@@ -180,8 +192,8 @@ fn should_promote_short_descs() {
180192#[ test]
181193fn should_not_promote_long_descs ( ) {
182194 let desc = some ( "Warkworth Castle is a ruined medieval building
183- in the town of the same name in the English county of Northumberland.
184- The town and castle occupy a loop of the River Coquet, less than a mile
195+ in the town of the same name in the English county of Northumberland,
196+ and the town and castle occupy a loop of the River Coquet, less than a mile
185197from England's north-east coast. When the castle was founded is uncertain,
186198but traditionally its construction has been ascribed to Prince Henry of
187199Scotland in the mid 12th century, although it may have been built by
@@ -190,3 +202,18 @@ counties.");
190202 let brief = extract ( desc) ;
191203 assert brief == none;
192204}
205+
206+ #[ test]
207+ fn should_promote_first_sentence ( ) {
208+ let desc = some ( "Warkworth Castle is a ruined medieval building
209+ in the town. of the same name in the English county of Northumberland,
210+ and the town and castle occupy a loop of the River Coquet, less than a mile
211+ from England's north-east coast. When the castle was founded is uncertain,
212+ but traditionally its construction has been ascribed to Prince Henry of
213+ Scotland in the mid 12th century, although it may have been built by
214+ King Henry II of England when he took control of England'snorthern
215+ counties." ) ;
216+ let brief = extract ( desc) ;
217+ assert brief == some (
218+ "Warkworth Castle is a ruined medieval building in the town" ) ;
219+ }
0 commit comments