Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/shared/src/threadSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ it("matches both Greek sigma forms without changing source offsets", () => {
expect(findThreadSearchOccurrences("ΟΣ ος οσ", "ς")).toEqual([1, 4, 7]);
expect(findThreadSearchOccurrences("İ ΟΣ", "Σ")).toEqual([3]);
});

it("matches straight and curly apostrophes without changing source offsets", () => {
expect(findThreadSearchOccurrences("don't don’t", "don’t")).toEqual([0, 6]);
expect(findThreadSearchOccurrences("İ don‘t", "don't")).toEqual([2]);
});
7 changes: 5 additions & 2 deletions packages/shared/src/threadSearch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// A typed straight apostrophe finds a curly one: iOS keyboards type "’".
const foldCharacters = (text: string) => text.replace(/ς/g, "σ").replace(/[‘’]/g, "'");

function foldThreadSearchCase(text: string): string {
const lowered = text.toLowerCase().replace(/ς/g, "σ");
const lowered = foldCharacters(text.toLowerCase());
if (lowered.length === text.length) return lowered;

let folded = "";
for (const character of text) {
const loweredCharacter = character.toLowerCase().replace(/ς/g, "σ");
const loweredCharacter = foldCharacters(character.toLowerCase());
folded += loweredCharacter.length === character.length ? loweredCharacter : character;
}
return folded;
Expand Down
Loading