summaryrefslogtreecommitdiff
path: root/l10ntools
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-04-14 18:52:19 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-04-15 14:06:06 +0200
commitb9c806b9e3631d76b8ceaa6208497aba60c75f83 (patch)
tree3b9180a34ba78c7e000c85a2c0742cd6a0ec6723 /l10ntools
parent6fd447aaf2f21a4708ca4e4268e209f4499cbeee (diff)
address potential find/rfind failures
in the conversion in commit 74957c7d2f3697fbf2b6f4d6a31c61d5d7df039b 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>
Diffstat (limited to 'l10ntools')
-rw-r--r--l10ntools/source/merge.cxx13
-rw-r--r--l10ntools/source/po.cxx5
2 files changed, 13 insertions, 5 deletions
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index 8a6964c61fa4..588cb73d8614 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -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(
diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx
index b93126838c99..62d09e1e7407 100644
--- a/l10ntools/source/po.cxx
+++ b/l10ntools/source/po.cxx
@@ -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 =