Skip to content

Commit 40fab58

Browse files
committed
🚑 lastSentenceEnd: prefer breaking on space if no sentence end
and take largest string if none of the above
1 parent 48f3f9d commit 40fab58

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

‎lib/app.js

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/app.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,22 @@ var assert = function(condition, message) {
668668
let APYMAXBYTES = 4096; // TODO: APY endpoint to return select.PIPE_BUF ?
669669

670670
var lastSentenceEnd = function(str) {
671-
let sep = /[.:!]\s/g;
671+
let sep = /[.:!?]\s/g;
672672
let found = 0;
673673
for(let res = sep.exec(str);
674674
res !== null;
675675
res = sep.exec(str)) {
676676
found = res.index + res.length;
677677
}
678+
if (found === 0) {
679+
let lastSpace = str.lastIndexOf(" ");
680+
if(lastSpace !== -1) {
681+
return lastSpace;
682+
}
683+
else {
684+
return str.length - 1;
685+
}
686+
}
678687
return found;
679688
};
680689

0 commit comments

Comments
 (0)