Skip to content

Commit d9ef75c

Browse files
committed
---
yaml --- r: 11940 b: refs/heads/master c: ddbd02a h: refs/heads/master v: v3
1 parent 255b973 commit d9ef75c

File tree

2 files changed

+63
-6
lines changed

2 files changed

+63
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e399ddbf179bec4798433b1d839065a7188c0f51
2+
refs/heads/master: ddbd02aaf2804b39762bdbe5e4c6b73b84f139bb
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustdoc/desc_to_brief_pass.rs

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,42 @@ fn parse_desc(desc: str) -> option<str> {
123123
fn first_sentence(s: str) -> option<str> {
124124
let paras = paragraphs(s);
125125
if vec::is_not_empty(paras) {
126-
let first = vec::head(sentences(vec::head(paras)));
127-
some(str::replace(first, "\n", " "))
126+
let first_para = vec::head(paras);
127+
some(str::replace(first_sentence_(first_para), "\n", " "))
128128
} else {
129129
none
130130
}
131131
}
132132

133-
fn sentences(s: str) -> [str] {
134-
str::split_char(s, '.')
133+
fn first_sentence_(s: str) -> str {
134+
let dotcount = 0;
135+
// The index of the character following a single dot. This allows
136+
// Things like [0..1) to appear in the brief description
137+
let idx = str::find(s) {|ch|
138+
if ch == '.' {
139+
dotcount += 1;
140+
false
141+
} else {
142+
if dotcount == 1 {
143+
true
144+
} else {
145+
dotcount = 0;
146+
false
147+
}
148+
}
149+
};
150+
alt idx {
151+
some(idx) if idx > 2u {
152+
str::slice(s, 0u, idx - 1u)
153+
}
154+
_ {
155+
if str::ends_with(s, ".") {
156+
str::slice(s, 0u, str::len(s))
157+
} else {
158+
s
159+
}
160+
}
161+
}
135162
}
136163

137164
fn paragraphs(s: str) -> [str] {
@@ -216,4 +243,34 @@ counties.");
216243
let brief = extract(desc);
217244
assert brief == some(
218245
"Warkworth Castle is a ruined medieval building in the town");
219-
}
246+
}
247+
248+
#[test]
249+
fn should_not_consider_double_period_to_end_sentence() {
250+
let desc = some("Warkworth..Castle is a ruined medieval building
251+
in the town. of the same name in the English county of Northumberland,
252+
and the town and castle occupy a loop of the River Coquet, less than a mile
253+
from England's north-east coast. When the castle was founded is uncertain,
254+
but traditionally its construction has been ascribed to Prince Henry of
255+
Scotland in the mid 12th century, although it may have been built by
256+
King Henry II of England when he took control of England'snorthern
257+
counties.");
258+
let brief = extract(desc);
259+
assert brief == some(
260+
"Warkworth..Castle is a ruined medieval building in the town");
261+
}
262+
263+
#[test]
264+
fn should_not_consider_triple_period_to_end_sentence() {
265+
let desc = some("Warkworth... Castle is a ruined medieval building
266+
in the town. of the same name in the English county of Northumberland,
267+
and the town and castle occupy a loop of the River Coquet, less than a mile
268+
from England's north-east coast. When the castle was founded is uncertain,
269+
but traditionally its construction has been ascribed to Prince Henry of
270+
Scotland in the mid 12th century, although it may have been built by
271+
King Henry II of England when he took control of England'snorthern
272+
counties.");
273+
let brief = extract(desc);
274+
assert brief == some(
275+
"Warkworth... Castle is a ruined medieval building in the town");
276+
}

0 commit comments

Comments
 (0)