Skip to content

Commit

Permalink
Handle carriage returns and spaces when looking for blank lines betwe…
Browse files Browse the repository at this point in the history
…en PO entries
  • Loading branch information
Blake-Madden committed Jun 9, 2024
1 parent 6977776 commit f354d24
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
27 changes: 23 additions & 4 deletions src/po_file_review.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
12 changes: 10 additions & 2 deletions tests/potests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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"
Expand Down

0 comments on commit f354d24

Please sign in to comment.