address potential find/rfind failures

in the conversion in
    commit 74957c7d2f
    Author: Noel Grandin <noel.grandin@collabora.co.uk>
    Date:   Wed Apr 13 13:54:22 2022 +0200
    use more string_view in l10ntools

where the prior code might have been relying on the -1 returned by
indexOf and lastIndexOd

Change-Id: Ief5dedccbaf4e14e5f59aa3c2f7481ff0bb7e2e8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133027
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Noel Grandin
2022-04-14 18:52:19 +02:00
committed by Stephan Bergmann
parent 6fd447aaf2
commit b9c806b9e3
2 changed files with 13 additions and 5 deletions

View File

@@ -34,10 +34,15 @@ namespace
{
OString lcl_NormalizeFilename(std::string_view rFilename)
{
return OString(rFilename.substr(
std::max(
rFilename.rfind( '\\' ),
rFilename.rfind( '/' ))+1));
size_t idx1 = rFilename.rfind( '\\' );
size_t idx2 = rFilename.rfind( '/' );
if (idx1 == std::string_view::npos && idx2 == std::string_view::npos)
return OString(rFilename);
if (idx1 == std::string_view::npos)
idx1 = 0;
if (idx2 == std::string_view::npos)
idx2 = 0;
return OString(rFilename.substr(std::max(idx1, idx2)+1));
};
bool lcl_ReadPoChecked(

View File

@@ -257,7 +257,10 @@ PoEntry::PoEntry(
throw WRONGHELPTEXT;
m_pGenPo.reset( new GenPoEntry() );
OString sReference(rSourceFile.substr(rSourceFile.rfind('/')+1));
size_t idx = rSourceFile.rfind('/');
if (idx == std::string_view::npos)
idx = 0;
OString sReference(rSourceFile.substr(idx+1));
m_pGenPo->setReference(sReference);
OString sMsgCtxt =