Skip to content

Commit 6acc41f

Browse files
committed
Simplify content capturing
1 parent bfe1f72 commit 6acc41f

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

src/participant/streamParsing.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,10 @@ class FragmentMatcher {
114114
// We haven't matched the start identifier yet, so try and do that
115115
const startIndex = this._startMatcher.match(fragment);
116116
if (startIndex !== -1) {
117-
let endIndex = this._endMatcher.match(fragment.slice(startIndex));
118-
if (endIndex !== -1) {
119-
// This is the case where both the start and the end identifiers are contained in the same fragment.
120-
// In this case, we emit the content between the two identifiers and continue processing the rest of the fragment.
121-
122-
// endIndex is relative to the slice, so we need to add startIndex to it.
123-
endIndex = startIndex + endIndex;
124-
125-
this._matchedContent = fragment.slice(startIndex, endIndex);
126-
this._contentMatched();
127-
this.process(fragment.slice(endIndex));
128-
} else {
129-
// If we only matched the start, we add the partial fragment to the matched content and
130-
// wait for another fragment to complete the match.
131-
this._matchedContent = fragment.slice(startIndex);
132-
}
117+
// We found a match for the start identifier - update `_matchedContent` to an empty string
118+
// and recursively call `process` with the remainder of the fragment.
119+
this._matchedContent = '';
120+
this.process(fragment.slice(startIndex));
133121
}
134122
} else {
135123
const endIndex = this._endMatcher.match(fragment);
@@ -139,6 +127,8 @@ class FragmentMatcher {
139127
this._contentMatched();
140128
this.process(fragment.slice(endIndex));
141129
} else {
130+
// We haven't matched the end yet - append the fragment to the matched content and wait
131+
// for a future fragment to contain the end identifier.
142132
this._matchedContent += fragment;
143133
}
144134
}

0 commit comments

Comments
 (0)