in packages/selector/src/text/match-text-position.ts [57:79]
export function textPositionSelectorMatcher(
selector: TextPositionSelector,
): <TChunk extends Chunk<any>>(
scope: Chunker<TChunk>,
) => AsyncGenerator<ChunkRange<TChunk>, void, void> {
const { start, end } = selector;
return async function* matchAll<TChunk extends Chunk<string>>(
textChunks: Chunker<TChunk>,
) {
const codeUnitSeeker = new TextSeeker(textChunks);
const codePointSeeker = new CodePointSeeker(codeUnitSeeker);
codePointSeeker.seekTo(start);
const startChunk = codeUnitSeeker.currentChunk;
const startIndex = codeUnitSeeker.offsetInChunk;
codePointSeeker.seekTo(end);
const endChunk = codeUnitSeeker.currentChunk;
const endIndex = codeUnitSeeker.offsetInChunk;
yield { startChunk, startIndex, endChunk, endIndex };
};
}