From 3814f10b1b5cd98d2aff944d369803db53f116b6 Mon Sep 17 00:00:00 2001 From: Joel Goguen Date: Sun, 26 Apr 2026 18:58:00 -0400 Subject: [PATCH] refactor: Clean up cppcheck finding causing tests to fail --- src/activities/reader/XtcReaderActivity.cpp | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/activities/reader/XtcReaderActivity.cpp b/src/activities/reader/XtcReaderActivity.cpp index d65bab38..b918c711 100644 --- a/src/activities/reader/XtcReaderActivity.cpp +++ b/src/activities/reader/XtcReaderActivity.cpp @@ -12,13 +12,14 @@ #include #include +#include + #include "CrossPointSettings.h" #include "CrossPointState.h" #include "MappedInputManager.h" #include "ReaderUtils.h" #include "RecentBooksStore.h" #include "XtcReaderChapterSelectionActivity.h" -#include "components/UITheme.h" #include "fontIds.h" namespace { @@ -462,24 +463,24 @@ void XtcReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION a case BA::BTN_NEXT_SECTION: if (xtc->hasChapters()) { const auto& chapters = xtc->getChapters(); - for (const auto& ch : chapters) { - if (ch.startPage > currentPage) { - currentPage = ch.startPage; - requestUpdate(); - break; - } + const auto nextChapter = std::find_if(chapters.begin(), chapters.end(), + [this](const auto& ch) { return ch.startPage > currentPage; }); + + if (nextChapter != chapters.end()) { + currentPage = nextChapter->startPage; + requestUpdate(); } } break; case BA::BTN_PREV_SECTION: if (xtc->hasChapters()) { const auto& chapters = xtc->getChapters(); - for (int i = static_cast(chapters.size()) - 1; i >= 0; i--) { - if (chapters[i].startPage < currentPage) { - currentPage = chapters[i].startPage; - requestUpdate(); - break; - } + const auto prevChapter = std::find_if(chapters.rbegin(), chapters.rend(), + [this](const auto& ch) { return ch.startPage < currentPage; }); + + if (prevChapter != chapters.rend()) { + currentPage = prevChapter->startPage; + requestUpdate(); } } break;