Skip to content

Commit eedb106

Browse files
committed
fix: fix whitespace handling
1 parent fca3f58 commit eedb106

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/sentence-splitter.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ export function split(text, options = {}) {
9090
// reset stat
9191
startPoint = currentIndex;
9292
isSplitPoint = false;
93-
}
94-
// Sentence<WhiteSpace>Sentence
95-
if (whiteSpaceCharacters.indexOf(char) !== -1) {
96-
results.push(createNode(Syntax.WhiteSpace, currentIndex, currentIndex + 1));
97-
startPoint++;
98-
currentIndex++;
93+
// Sentence<WhiteSpace>Sentence
94+
if (whiteSpaceCharacters.indexOf(char) !== -1) {
95+
results.push(createNode(Syntax.WhiteSpace, currentIndex, currentIndex + 1));
96+
startPoint++;
97+
currentIndex++;
98+
}
9999
}
100100
}
101101
}

test/sentence-utils-test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,20 @@ describe("sentence-utils", function() {
9393
assert.deepEqual(sentence2.loc.end, { line: 2, column: 4 });
9494
});
9595
it("should return sentences split by . and whitespace", function() {
96-
let sentences = splitSentences("1txt. 2txt");
96+
let sentences = splitSentences("1st text. 2nd text");
9797
assert.equal(sentences.length, 3);
9898
var sentence0 = sentences[0];
99-
assert.strictEqual(sentence0.raw, "1txt.");
99+
assert.strictEqual(sentence0.raw, "1st text.");
100100
assert.deepEqual(sentence0.loc.start, { line: 1, column: 0 });
101-
assert.deepEqual(sentence0.loc.end, { line: 1, column: 5 });
101+
assert.deepEqual(sentence0.loc.end, { line: 1, column: 9 });
102102
var whiteSpace1 = sentences[1];
103103
assert.strictEqual(whiteSpace1.raw, " ");
104-
assert.deepEqual(whiteSpace1.loc.start, { line: 1, column: 5 });
105-
assert.deepEqual(whiteSpace1.loc.end, { line: 1, column: 6 });
104+
assert.deepEqual(whiteSpace1.loc.start, { line: 1, column: 9 });
105+
assert.deepEqual(whiteSpace1.loc.end, { line: 1, column: 10 });
106106
var sentence2 = sentences[2];
107-
assert.strictEqual(sentence2.raw, "2txt");
108-
assert.deepEqual(sentence2.loc.start, { line: 1, column: 6 });
109-
assert.deepEqual(sentence2.loc.end, { line: 1, column: 10 });
107+
assert.strictEqual(sentence2.raw, "2nd text");
108+
assert.deepEqual(sentence2.loc.start, { line: 1, column: 10 });
109+
assert.deepEqual(sentence2.loc.end, { line: 1, column: 18 });
110110
});
111111
it("should return sentences split by !?", function() {
112112
let sentences = splitSentences("text!?text");

0 commit comments

Comments
 (0)