use more string_view in unotools

Change-Id: Iaf91f9c63a0a666250e92a5ba7bebdb06dffb258
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140233
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2022-09-20 11:37:12 +02:00
parent 321a1b5034
commit 5edefc801f
4 changed files with 25 additions and 22 deletions

View file

@ -840,7 +840,7 @@ css::uno::Reference< css::uno::XInterface > FilterCache::impl_openConfig(EConfig
return *pConfig;
}
css::uno::Any FilterCache::impl_getDirectCFGValue(const OUString& sDirectKey)
css::uno::Any FilterCache::impl_getDirectCFGValue(std::u16string_view sDirectKey)
{
OUString sRoot;
OUString sKey ;

View file

@ -664,7 +664,7 @@ class FilterCache : public cppu::BaseMutex
Can be empty if an internal error occurred or if the requested
key does not exists!
*/
css::uno::Any impl_getDirectCFGValue(const OUString& sDirectKey);
css::uno::Any impl_getDirectCFGValue(std::u16string_view sDirectKey);
/** @short load the underlying configuration into this cache.

View file

@ -51,7 +51,7 @@ namespace utl
<FALSE/>, if the path was a one-level path or an invalid path
*/
UNOTOOLS_DLLPUBLIC bool splitLastFromConfigurationPath(OUString const& _sInPath,
UNOTOOLS_DLLPUBLIC bool splitLastFromConfigurationPath(std::u16string_view _sInPath,
OUString& _rsOutPath,
OUString& _rsLocalName);

View file

@ -72,72 +72,75 @@ void lcl_resolveCharEntities(OUString & aLocalString)
aLocalString = aResult.makeStringAndClear();
}
bool splitLastFromConfigurationPath(OUString const& _sInPath,
bool splitLastFromConfigurationPath(std::u16string_view _sInPath,
OUString& _rsOutPath,
OUString& _rsLocalName)
{
sal_Int32 nStart,nEnd;
size_t nStart,nEnd;
sal_Int32 nPos = _sInPath.getLength()-1;
size_t nPos = _sInPath.size()-1;
// strip trailing slash
if (nPos > 0 && _sInPath[ nPos ] == '/')
if (nPos != std::u16string_view::npos && _sInPath[ nPos ] == '/')
{
OSL_FAIL("Invalid config path: trailing '/' is not allowed");
--nPos;
}
// check for predicate ['xxx'] or ["yyy"]
if (nPos > 0 && _sInPath[ nPos ] == ']')
if (nPos != std::u16string_view::npos && _sInPath[ nPos ] == ']')
{
sal_Unicode chQuote = _sInPath[--nPos];
if (chQuote == '\'' || chQuote == '\"')
{
nEnd = nPos;
nPos = _sInPath.lastIndexOf(chQuote,nEnd);
nPos = _sInPath.find(chQuote,nEnd);
nStart = nPos + 1;
--nPos; // nPos = rInPath.lastIndexOf('[',nPos);
}
else // allow [xxx]
{
nEnd = nPos + 1;
nPos = _sInPath.lastIndexOf('[',nEnd);
nPos = _sInPath.rfind('[',nEnd);
nStart = nPos + 1;
}
OSL_ENSURE(nPos >= 0 && _sInPath[nPos] == '[', "Invalid config path: unmatched quotes or brackets");
if (nPos >= 0 && _sInPath[nPos] == '[')
OSL_ENSURE(nPos != std::u16string_view::npos && _sInPath[nPos] == '[', "Invalid config path: unmatched quotes or brackets");
if (nPos != std::u16string_view::npos && _sInPath[nPos] == '[')
{
nPos = _sInPath.lastIndexOf('/',nPos);
nPos = _sInPath.rfind('/',nPos);
}
else // defined behavior for invalid paths
{
nStart = 0;
nEnd = _sInPath.getLength();
nPos = -1;
nEnd = _sInPath.size();
nPos = std::u16string_view::npos;
}
}
else
{
nEnd = nPos+1;
nPos = _sInPath.lastIndexOf('/',nEnd);
nPos = _sInPath.rfind('/',nEnd);
nStart = nPos + 1;
}
OSL_ASSERT( -1 <= nPos &&
OSL_ASSERT( nPos != std::u16string_view::npos &&
nPos < nStart &&
nStart < nEnd &&
nEnd <= _sInPath.getLength() );
nEnd <= _sInPath.size() );
OSL_ASSERT(nPos == -1 || _sInPath[nPos] == '/');
OSL_ASSERT(nPos == std::u16string_view::npos || _sInPath[nPos] == '/');
OSL_ENSURE(nPos != 0 , "Invalid config child path: immediate child of root");
_rsLocalName = _sInPath.copy(nStart, nEnd-nStart);
_rsOutPath = (nPos > 0) ? _sInPath.copy(0,nPos) : OUString();
_rsLocalName = _sInPath.substr(nStart, nEnd-nStart);
if (nPos > 0 && nPos != std::u16string_view::npos)
_rsOutPath = _sInPath.substr(0,nPos);
else
_rsOutPath.clear();
lcl_resolveCharEntities(_rsLocalName);
return nPos >= 0;
return nPos != std::u16string_view::npos;
}
OUString extractFirstFromConfigurationPath(OUString const& _sInPath, OUString* _sOutPath)