From f354d24c63fb6483df92e7486c34f3ea7cef4298 Mon Sep 17 00:00:00 2001 From: Blake-Madden <66873089+Blake-Madden@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:15:03 -0400 Subject: [PATCH] Handle carriage returns and spaces when looking for blank lines between PO entries --- src/po_file_review.cpp | 27 +++++++++++++++++++++++---- tests/potests.cpp | 12 ++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/po_file_review.cpp b/src/po_file_review.cpp index bab8588..82e1373 100644 --- a/src/po_file_review.cpp +++ b/src/po_file_review.cpp @@ -72,11 +72,30 @@ namespace i18n_check } poFileText.remove_prefix(entryPos); - /// @todo handle \r - size_t endOfEntryPos = poFileText.find(L"\n\n"); - if (endOfEntryPos == std::wstring_view::npos) + // find the next blank line, which is the separator between catalog entries + size_t endOfEntryPos{ 0 }; + while (endOfEntryPos != std::wstring_view::npos) { - return std::make_pair(true, poFileText); + endOfEntryPos = poFileText.find(L'\n', endOfEntryPos); + // we must be at the last entry + if (endOfEntryPos == std::wstring_view::npos || + endOfEntryPos == poFileText.length() - 1) + { + return std::make_pair(true, poFileText); + } + ++endOfEntryPos; + // eat up whitespace on line + while (endOfEntryPos < poFileText.length() - 1 && + string_util::is_either(poFileText[endOfEntryPos], L'\t', L' ')) + { + ++endOfEntryPos; + } + // stop if we encountered a blank line (with or without empty whitespace in it) + if (endOfEntryPos == poFileText.length() - 1 || + string_util::is_either(poFileText[endOfEntryPos], L'\r', L'\n')) + { + break; + } } return std::make_pair(true, poFileText.substr(0, endOfEntryPos)); } diff --git a/tests/potests.cpp b/tests/potests.cpp index 9772e4f..9a12395 100644 --- a/tests/potests.cpp +++ b/tests/potests.cpp @@ -20,7 +20,15 @@ msgstr "Сервер не поддерживает команду PORT." #: ../src/common/file.cpp:612 # fuzzy, c-format msgid "The server doesn't support %s mode." -msgstr "Сервер не поддерживает пассивный %d.")"; +msgstr "Сервер не поддерживает пассивный %d. + +#: ../src/common/file.cpp:604 +msgid "The server doesn't support the PORT command %s." +msgstr "Сервер не поддерживает команду PORT." + +#: ../src/common/file.cpp:604 +msgid "The server doesn't support the PORT command %s." +msgstr "Сервер не поддерживает команду PORT."")"; po(code, L""); po.review_strings(); @@ -38,7 +46,7 @@ msgstr "Сервер не поддерживает пассивный %d.")"; #, c-format msgid "Incorrect frame size (%u, %s) for the frame #%u" msgstr "Неправильный размер кадра (%u, %d) для frame #%u" - + #: ../src/common/decod.cpp:826 #, c-format msgid "Incorrect frame size (%.5f, %s) for the frame #%u"