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:
2
filter/source/config/cache/filtercache.cxx
vendored
2
filter/source/config/cache/filtercache.cxx
vendored
@@ -840,7 +840,7 @@ css::uno::Reference< css::uno::XInterface > FilterCache::impl_openConfig(EConfig
|
|||||||
return *pConfig;
|
return *pConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
css::uno::Any FilterCache::impl_getDirectCFGValue(const OUString& sDirectKey)
|
css::uno::Any FilterCache::impl_getDirectCFGValue(std::u16string_view sDirectKey)
|
||||||
{
|
{
|
||||||
OUString sRoot;
|
OUString sRoot;
|
||||||
OUString sKey ;
|
OUString sKey ;
|
||||||
|
2
filter/source/config/cache/filtercache.hxx
vendored
2
filter/source/config/cache/filtercache.hxx
vendored
@@ -664,7 +664,7 @@ class FilterCache : public cppu::BaseMutex
|
|||||||
Can be empty if an internal error occurred or if the requested
|
Can be empty if an internal error occurred or if the requested
|
||||||
key does not exists!
|
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.
|
/** @short load the underlying configuration into this cache.
|
||||||
|
@@ -51,7 +51,7 @@ namespace utl
|
|||||||
<FALSE/>, if the path was a one-level path or an invalid path
|
<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& _rsOutPath,
|
||||||
OUString& _rsLocalName);
|
OUString& _rsLocalName);
|
||||||
|
|
||||||
|
@@ -72,72 +72,75 @@ void lcl_resolveCharEntities(OUString & aLocalString)
|
|||||||
aLocalString = aResult.makeStringAndClear();
|
aLocalString = aResult.makeStringAndClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool splitLastFromConfigurationPath(OUString const& _sInPath,
|
bool splitLastFromConfigurationPath(std::u16string_view _sInPath,
|
||||||
OUString& _rsOutPath,
|
OUString& _rsOutPath,
|
||||||
OUString& _rsLocalName)
|
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
|
// 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");
|
OSL_FAIL("Invalid config path: trailing '/' is not allowed");
|
||||||
--nPos;
|
--nPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for predicate ['xxx'] or ["yyy"]
|
// check for predicate ['xxx'] or ["yyy"]
|
||||||
if (nPos > 0 && _sInPath[ nPos ] == ']')
|
if (nPos != std::u16string_view::npos && _sInPath[ nPos ] == ']')
|
||||||
{
|
{
|
||||||
sal_Unicode chQuote = _sInPath[--nPos];
|
sal_Unicode chQuote = _sInPath[--nPos];
|
||||||
|
|
||||||
if (chQuote == '\'' || chQuote == '\"')
|
if (chQuote == '\'' || chQuote == '\"')
|
||||||
{
|
{
|
||||||
nEnd = nPos;
|
nEnd = nPos;
|
||||||
nPos = _sInPath.lastIndexOf(chQuote,nEnd);
|
nPos = _sInPath.find(chQuote,nEnd);
|
||||||
nStart = nPos + 1;
|
nStart = nPos + 1;
|
||||||
--nPos; // nPos = rInPath.lastIndexOf('[',nPos);
|
--nPos; // nPos = rInPath.lastIndexOf('[',nPos);
|
||||||
}
|
}
|
||||||
else // allow [xxx]
|
else // allow [xxx]
|
||||||
{
|
{
|
||||||
nEnd = nPos + 1;
|
nEnd = nPos + 1;
|
||||||
nPos = _sInPath.lastIndexOf('[',nEnd);
|
nPos = _sInPath.rfind('[',nEnd);
|
||||||
nStart = nPos + 1;
|
nStart = nPos + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSL_ENSURE(nPos >= 0 && _sInPath[nPos] == '[', "Invalid config path: unmatched quotes or brackets");
|
OSL_ENSURE(nPos != std::u16string_view::npos && _sInPath[nPos] == '[', "Invalid config path: unmatched quotes or brackets");
|
||||||
if (nPos >= 0 && _sInPath[nPos] == '[')
|
if (nPos != std::u16string_view::npos && _sInPath[nPos] == '[')
|
||||||
{
|
{
|
||||||
nPos = _sInPath.lastIndexOf('/',nPos);
|
nPos = _sInPath.rfind('/',nPos);
|
||||||
}
|
}
|
||||||
else // defined behavior for invalid paths
|
else // defined behavior for invalid paths
|
||||||
{
|
{
|
||||||
nStart = 0;
|
nStart = 0;
|
||||||
nEnd = _sInPath.getLength();
|
nEnd = _sInPath.size();
|
||||||
nPos = -1;
|
nPos = std::u16string_view::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nEnd = nPos+1;
|
nEnd = nPos+1;
|
||||||
nPos = _sInPath.lastIndexOf('/',nEnd);
|
nPos = _sInPath.rfind('/',nEnd);
|
||||||
nStart = nPos + 1;
|
nStart = nPos + 1;
|
||||||
}
|
}
|
||||||
OSL_ASSERT( -1 <= nPos &&
|
OSL_ASSERT( nPos != std::u16string_view::npos &&
|
||||||
nPos < nStart &&
|
nPos < nStart &&
|
||||||
nStart < nEnd &&
|
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");
|
OSL_ENSURE(nPos != 0 , "Invalid config child path: immediate child of root");
|
||||||
|
|
||||||
_rsLocalName = _sInPath.copy(nStart, nEnd-nStart);
|
_rsLocalName = _sInPath.substr(nStart, nEnd-nStart);
|
||||||
_rsOutPath = (nPos > 0) ? _sInPath.copy(0,nPos) : OUString();
|
if (nPos > 0 && nPos != std::u16string_view::npos)
|
||||||
|
_rsOutPath = _sInPath.substr(0,nPos);
|
||||||
|
else
|
||||||
|
_rsOutPath.clear();
|
||||||
lcl_resolveCharEntities(_rsLocalName);
|
lcl_resolveCharEntities(_rsLocalName);
|
||||||
|
|
||||||
return nPos >= 0;
|
return nPos != std::u16string_view::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
OUString extractFirstFromConfigurationPath(OUString const& _sInPath, OUString* _sOutPath)
|
OUString extractFirstFromConfigurationPath(OUString const& _sInPath, OUString* _sOutPath)
|
||||||
|
Reference in New Issue
Block a user