From 9abd74d7931b0df6f977c43729b8e224a9956ead Mon Sep 17 00:00:00 2001 From: Blake-Madden <66873089+Blake-Madden@users.noreply.github.com> Date: Wed, 15 May 2024 11:18:17 -0400 Subject: [PATCH] Fix boundary issues --- src/i18n_review.h | 6 +++++- tests/cpptests.cpp | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/i18n_review.h b/src/i18n_review.h index 8934fb9..c1853d1 100644 --- a/src/i18n_review.h +++ b/src/i18n_review.h @@ -705,7 +705,11 @@ namespace i18n_check { return std::wstring_view{}; } - for (int64_t i = str.length() - 2; i >= 0; --i) + if (str.length() == 1) + { + return is_valid_name_char(str[0]) ? str : std::wstring_view{}; + } + for (int64_t i = str.length() - 1; i >= 0; --i) { if (!is_valid_name_char(str[static_cast(i)])) { diff --git a/tests/cpptests.cpp b/tests/cpptests.cpp index ca87fe3..a81603a 100644 --- a/tests/cpptests.cpp +++ b/tests/cpptests.cpp @@ -395,7 +395,10 @@ MyWindow::MyWindow() { QLabel *senderLabel = new QLabel(tr("Name:")); QLabel *recipientLabel = new QLabel(tr("Name:", "recipient")); -})"; +} +QLabel *label = new QLabel( + s("Password:"), logwid); +)"; cpp(code, L""); cpp.review_strings(); REQUIRE(cpp.get_localizable_strings().size() == 4); @@ -404,10 +407,11 @@ MyWindow::MyWindow() CHECK(cpp.get_localizable_strings()[2].m_string == L"Name:"); CHECK(cpp.get_localizable_strings()[3].m_string == L"Name:"); CHECK(cpp.get_not_available_for_localization_strings().size() == 0); - REQUIRE(cpp.get_internal_strings().size() == 2); + REQUIRE(cpp.get_internal_strings().size() == 3); // context portion of translate() and tr() CHECK(cpp.get_internal_strings()[0].m_string == L"LoginWidget"); CHECK(cpp.get_internal_strings()[1].m_string == L"recipient"); + CHECK(cpp.get_internal_strings()[2].m_string == L"Password:"); CHECK(cpp.get_unsafe_localizable_strings().size() == 0); }