summaryrefslogtreecommitdiff
path: root/l10ntools
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-04-10 15:36:21 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-04-10 20:15:16 +0200
commitb24a4d255d31233c48152e6e1ce992a693cdaeae (patch)
treee0ad8f574d3b1ddcad3d81ec3ac438777ca4846d /l10ntools
parent57f22d9b1a4e1cd161a35c8e4c390661db981d2c (diff)
use more string_view
found by tweaking the loplugin:stringview and making it whitelist getLength Change-Id: Ic15d3703d1fb07658e99e1db1c89e2fa5bc70c19 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132771 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'l10ntools')
-rw-r--r--l10ntools/inc/cfgmerge.hxx2
-rw-r--r--l10ntools/inc/helper.hxx8
-rw-r--r--l10ntools/inc/po.hxx2
-rw-r--r--l10ntools/source/cfgmerge.cxx4
-rw-r--r--l10ntools/source/helper.cxx46
-rw-r--r--l10ntools/source/po.cxx26
6 files changed, 45 insertions, 43 deletions
diff --git a/l10ntools/inc/cfgmerge.hxx b/l10ntools/inc/cfgmerge.hxx
index 8c7e90720081..12e5cace11f2 100644
--- a/l10ntools/inc/cfgmerge.hxx
+++ b/l10ntools/inc/cfgmerge.hxx
@@ -118,7 +118,7 @@ private:
const OString &rIsoLang,
const OString &rResTyp );
- static bool IsTokenClosed(const OString &rToken);
+ static bool IsTokenClosed(std::string_view rToken);
public:
CfgParser();
diff --git a/l10ntools/inc/helper.hxx b/l10ntools/inc/helper.hxx
index fb0db0fc13f7..c1347db04c64 100644
--- a/l10ntools/inc/helper.hxx
+++ b/l10ntools/inc/helper.hxx
@@ -25,15 +25,15 @@ namespace helper {
/// Escape all given character in the text
OString escapeAll(
- const OString& rText, const OString& rUnEscaped, const OString& rEscaped );
+ std::string_view rText, std::string_view rUnEscaped, std::string_view rEscaped );
/// Unescape all given character in the text
OString unEscapeAll(
- const OString& rText, const OString& rEscaped, std::string_view rUnEscaped );
+ std::string_view rText, std::string_view rEscaped, std::string_view rUnEscaped );
/// Convert special characters to XML entity references
-OString QuotHTML( const OString &rString );
+OString QuotHTML( std::string_view rString );
/// Convert XML entity references to single characters
-OString UnQuotHTML( const OString& rString );
+OString UnQuotHTML( std::string_view rString );
/// Check whether text is a valid XML expression
bool isWellFormedXML( std::string_view text );
diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx
index db513cab1f8e..8267525133b7 100644
--- a/l10ntools/inc/po.hxx
+++ b/l10ntools/inc/po.hxx
@@ -47,7 +47,7 @@ public:
PoEntry();
PoEntry( const OString& rSourceFile, std::string_view rResType, std::string_view rGroupId,
- std::string_view rLocalId, const OString& rHelpText, const OString& rText,
+ std::string_view rLocalId, std::string_view rHelpText, const OString& rText,
const TYPE eType );
~PoEntry();
diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx
index 69fbd3777f85..aa0126b22822 100644
--- a/l10ntools/source/cfgmerge.cxx
+++ b/l10ntools/source/cfgmerge.cxx
@@ -134,9 +134,9 @@ CfgParser::~CfgParser()
{
}
-bool CfgParser::IsTokenClosed(const OString &rToken)
+bool CfgParser::IsTokenClosed(std::string_view rToken)
{
- return rToken[rToken.getLength() - 2] == '/';
+ return rToken[rToken.size() - 2] == '/';
}
void CfgParser::AddText(
diff --git a/l10ntools/source/helper.cxx b/l10ntools/source/helper.cxx
index b8df012dc149..4726234b19dd 100644
--- a/l10ntools/source/helper.cxx
+++ b/l10ntools/source/helper.cxx
@@ -12,6 +12,7 @@
#include <libxml/parser.h>
#include <o3tl/safeint.hxx>
+#include <o3tl/string_view.hxx>
#include <rtl/strbuf.hxx>
#include <helper.hxx>
@@ -19,16 +20,16 @@
namespace helper {
OString escapeAll(
- const OString& rText, const OString& rUnEscaped, const OString& rEscaped )
+ std::string_view rText, std::string_view rUnEscaped, std::string_view rEscaped )
{
- assert( rEscaped.getLength() == 2*rUnEscaped.getLength() );
+ assert( rEscaped.size() == 2*rUnEscaped.size() );
OStringBuffer sReturn;
- for ( sal_Int32 nIndex = 0; nIndex < rText.getLength(); ++nIndex )
+ for ( size_t nIndex = 0; nIndex < rText.size(); ++nIndex )
{
- sal_Int32 nUnEscapedOne = rUnEscaped.indexOf(rText[nIndex]);
- if( nUnEscapedOne != -1 )
+ size_t nUnEscapedOne = rUnEscaped.find(rText[nIndex]);
+ if( nUnEscapedOne != std::string_view::npos )
{
- sReturn.append(rEscaped.subView(nUnEscapedOne*2,2));
+ sReturn.append(rEscaped.substr(nUnEscapedOne*2,2));
}
else
sReturn.append(rText[nIndex]);
@@ -38,17 +39,17 @@ OString escapeAll(
OString unEscapeAll(
- const OString& rText, const OString& rEscaped, std::string_view rUnEscaped)
+ std::string_view rText, std::string_view rEscaped, std::string_view rUnEscaped)
{
- assert( o3tl::make_unsigned(rEscaped.getLength()) == 2*rUnEscaped.length() );
+ assert( rEscaped.size() == 2*rUnEscaped.length() );
OStringBuffer sReturn;
- const sal_Int32 nLength = rText.getLength();
- for ( sal_Int32 nIndex = 0; nIndex < nLength; ++nIndex )
+ const size_t nLength = rText.size();
+ for ( size_t nIndex = 0; nIndex < nLength; ++nIndex )
{
if( rText[nIndex] == '\\' && nIndex+1 < nLength )
{
- sal_Int32 nEscapedOne = rEscaped.indexOf(rText.subView(nIndex,2));
- if( nEscapedOne != -1 )
+ size_t nEscapedOne = rEscaped.find(rText.substr(nIndex,2));
+ if( nEscapedOne != std::string_view::npos )
{
sReturn.append(rUnEscaped[nEscapedOne/2]);
++nIndex;
@@ -65,10 +66,10 @@ OString unEscapeAll(
}
-OString QuotHTML(const OString &rString)
+OString QuotHTML(std::string_view rString)
{
OStringBuffer sReturn;
- for (sal_Int32 i = 0; i < rString.getLength(); ++i)
+ for (size_t i = 0; i < rString.size(); ++i)
{
switch (rString[i])
{
@@ -85,7 +86,7 @@ OString QuotHTML(const OString &rString)
sReturn.append("&apos;");
break;
case '&':
- if (rString.match("&amp;", i))
+ if (o3tl::starts_with(rString.substr(i), "&amp;"))
sReturn.append('&');
else
sReturn.append("&amp;");
@@ -98,23 +99,24 @@ OString QuotHTML(const OString &rString)
return sReturn.makeStringAndClear();
}
-OString UnQuotHTML( const OString& rString )
+OString UnQuotHTML( std::string_view rString )
{
OStringBuffer sReturn;
- for (sal_Int32 i = 0; i != rString.getLength();) {
- if (rString.match("&amp;", i)) {
+ for (size_t i = 0; i != rString.size();) {
+ auto tmp = rString.substr(i);
+ if (o3tl::starts_with(tmp, "&amp;")) {
sReturn.append('&');
i += RTL_CONSTASCII_LENGTH("&amp;");
- } else if (rString.match("&lt;", i)) {
+ } else if (o3tl::starts_with(tmp, "&lt;")) {
sReturn.append('<');
i += RTL_CONSTASCII_LENGTH("&lt;");
- } else if (rString.match("&gt;", i)) {
+ } else if (o3tl::starts_with(tmp, "&gt;")) {
sReturn.append('>');
i += RTL_CONSTASCII_LENGTH("&gt;");
- } else if (rString.match("&quot;", i)) {
+ } else if (o3tl::starts_with(tmp, "&quot;")) {
sReturn.append('"');
i += RTL_CONSTASCII_LENGTH("&quot;");
- } else if (rString.match("&apos;", i)) {
+ } else if (o3tl::starts_with(tmp, "&apos;")) {
sReturn.append('\'');
i += RTL_CONSTASCII_LENGTH("&apos;");
} else {
diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx
index a29fb4fe98dd..2bf522d4b05e 100644
--- a/l10ntools/source/po.cxx
+++ b/l10ntools/source/po.cxx
@@ -80,9 +80,9 @@ public:
namespace
{
// Convert a normal string to msg/po output string
- OString lcl_GenMsgString(const OString& rString)
+ OString lcl_GenMsgString(std::string_view rString)
{
- if ( rString.isEmpty() )
+ if ( rString.empty() )
return "\"\"";
OString sResult =
@@ -107,11 +107,11 @@ namespace
}
// Convert msg string to normal form
- OString lcl_GenNormString(const OString& rString)
+ OString lcl_GenNormString(std::string_view rString)
{
return
helper::unEscapeAll(
- rString.copy(1,rString.getLength()-2),
+ rString.substr(1,rString.size()-2),
"\\n""\\t""\\r""\\\\""\\\"",
"\n""\t""\r""\\""\"");
}
@@ -150,7 +150,7 @@ void GenPoEntry::writeToFile(std::ofstream& rOFStream) const
<< std::endl;
if ( !m_sMsgStrPlural.empty() )
for(auto & line : m_sMsgStrPlural)
- rOFStream << line.copy(0,10) << lcl_GenMsgString(line.copy(10)) << std::endl;
+ rOFStream << line.copy(0,10) << lcl_GenMsgString(line.subView(10)) << std::endl;
else
rOFStream << "msgstr "
<< lcl_GenMsgString(m_sMsgStr) << std::endl;
@@ -192,29 +192,29 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream)
}
else if (sLine.startsWith("msgctxt "))
{
- m_sMsgCtxt = lcl_GenNormString(sLine.copy(8));
+ m_sMsgCtxt = lcl_GenNormString(sLine.subView(8));
pLastMsg = &m_sMsgCtxt;
}
else if (sLine.startsWith("msgid "))
{
- m_sMsgId = lcl_GenNormString(sLine.copy(6));
+ m_sMsgId = lcl_GenNormString(sLine.subView(6));
pLastMsg = &m_sMsgId;
}
else if (sLine.startsWith("msgid_plural "))
{
- m_sMsgIdPlural = lcl_GenNormString(sLine.copy(13));
+ m_sMsgIdPlural = lcl_GenNormString(sLine.subView(13));
pLastMsg = &m_sMsgIdPlural;
}
else if (sLine.startsWith("msgstr "))
{
- m_sMsgStr = lcl_GenNormString(sLine.copy(7));
+ m_sMsgStr = lcl_GenNormString(sLine.subView(7));
pLastMsg = &m_sMsgStr;
}
else if (sLine.startsWith("msgstr["))
{
// assume there are no more than 10 plural forms...
// and that plural strings are never split to multi-line in po
- m_sMsgStrPlural.push_back(sLine.subView(0,10) + lcl_GenNormString(sLine.copy(10)));
+ m_sMsgStrPlural.push_back(sLine.subView(0,10) + lcl_GenNormString(sLine.subView(10)));
}
else if (sLine.startsWith("\"") && pLastMsg)
{
@@ -241,7 +241,7 @@ PoEntry::PoEntry()
PoEntry::PoEntry(
const OString& rSourceFile, std::string_view rResType, std::string_view rGroupId,
- std::string_view rLocalId, const OString& rHelpText,
+ std::string_view rLocalId, std::string_view rHelpText,
const OString& rText, const TYPE eType )
: m_bIsInitialized( false )
{
@@ -253,7 +253,7 @@ PoEntry::PoEntry(
throw NOGROUPID;
else if ( rText.isEmpty() )
throw NOSTRING;
- else if ( rHelpText.getLength() == 5 )
+ else if ( rHelpText.size() == 5 )
throw WRONGHELPTEXT;
m_pGenPo.reset( new GenPoEntry() );
@@ -277,7 +277,7 @@ PoEntry::PoEntry(
m_pGenPo->setMsgCtxt(sMsgCtxt);
m_pGenPo->setMsgId(rText);
m_pGenPo->setExtractCom(OStringConcatenation(
- ( !rHelpText.isEmpty() ? rHelpText + "\n" : OString()) +
+ ( !rHelpText.empty() ? OString::Concat(rHelpText) + "\n" : OString()) +
genKeyId( m_pGenPo->getReference().front() + rGroupId + rLocalId + rResType + rText ) ));
m_bIsInitialized = true;
}