A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: footnote link text (#1666)

## Summary

Previouls where ALL whitespace (and square brackes) removed from the
footnote link text, however some link texts are multiworded, like "`turn
to 252`" which were truncated into "`turnto252`", (an example from the
first book "Flight from the Dark" of the Lone Wolf book series by Joe
Dever, see [link](https://www.projectaon.org/en/Main/FlightFromTheDark))

* This change will only remove whitespaces from the beginning and end of
the string
so "` [ 12 ] `" will become "`12`" just like before, and "` turn to 252
`" will become "`turn to 252`".

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_

authored by

Stefan Blixten Karlsson and committed by
GitHub
80772ff6 57fc6555

+22 -7
+22 -7
lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
··· 697 697 // Collect footnote link display text (for the number label) 698 698 // Skip whitespace and brackets to normalize noterefs like "[1]" → "1" 699 699 if (self->insideFootnoteLink) { 700 - for (int i = 0; i < len; i++) { 701 - unsigned char c = static_cast<unsigned char>(s[i]); 702 - if (isWhitespace(c) || c == '[' || c == ']') continue; 703 - if (self->currentFootnoteLinkTextLen < static_cast<int>(sizeof(self->currentFootnoteLinkText)) - 1) { 704 - self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen++] = c; 705 - self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen] = '\0'; 706 - } 700 + int start = 0; 701 + int end = len - 1; 702 + 703 + // Example input and output texts: 704 + // " [ 12 ] " => "12" 705 + // " turn to 256 " => "turn to 256" 706 + 707 + // Ignore leading whitespaces and left square brackets 708 + while (start < len && (isWhitespace(s[start]) || (s[start] == '['))) { 709 + ++start; 710 + } 711 + 712 + // Ignore trailing whitespaces and right square brackets 713 + while (end >= start && (isWhitespace(s[end]) || (s[end] == ']'))) { 714 + --end; 707 715 } 716 + 717 + // Extract footnote link text 718 + for (int i = start; (self->currentFootnoteLinkTextLen < sizeof(self->currentFootnoteLinkText) - 1) && (i <= end); 719 + ++i) { 720 + self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen++] = s[i]; 721 + } 722 + self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen] = '\0'; 708 723 } 709 724 710 725 for (int i = 0; i < len; i++) {