use more string_view in svl

Change-Id: I9b6a074eb6342808d02a69f3ed1fa713e81d2608
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132958
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2022-04-13 14:05:07 +02:00
parent a5343a89f8
commit dae0083c69
4 changed files with 27 additions and 20 deletions

View File

@@ -252,7 +252,7 @@ public:
static INetContentType GetContentTypeFromURL(OUString const& rURL);
static bool GetExtensionFromURL(OUString const& rURL, OUString& rExtension);
static bool GetExtensionFromURL(std::u16string_view rURL, OUString& rExtension);
static bool parse(OUString const& rMediaType, OUString& rType, OUString& rSubType,
INetContentTypeParameterList* pParameters = nullptr);

View File

@@ -392,26 +392,26 @@ INetContentType INetContentTypes::GetContentTypeFromURL(OUString const & rURL)
}
//static
bool INetContentTypes::GetExtensionFromURL(OUString const & rURL,
bool INetContentTypes::GetExtensionFromURL(std::u16string_view rURL,
OUString & rExtension)
{
sal_Int32 nSlashPos = 0;
sal_Int32 i = 0;
while (i >= 0)
size_t nSlashPos = 0;
size_t i = 0;
while (i != std::u16string_view::npos)
{
nSlashPos = i;
i = rURL.indexOf('/', i + 1);
i = rURL.find('/', i + 1);
}
if (nSlashPos != 0)
{
sal_Int32 nLastDotPos = i = rURL.indexOf('.', nSlashPos);
while (i >= 0)
size_t nLastDotPos = i = rURL.find('.', nSlashPos);
while (i != std::u16string_view::npos)
{
nLastDotPos = i;
i = rURL.indexOf('.', i + 1);
i = rURL.find('.', i + 1);
}
if (nLastDotPos >- 0)
rExtension = rURL.copy(nLastDotPos + 1);
rExtension = rURL.substr(nLastDotPos + 1);
return true;
}
return false;

View File

@@ -412,7 +412,7 @@ void SAL_CALL PasswordContainer::disposing( const EventObject& )
}
}
std::vector< OUString > PasswordContainer::DecodePasswords( std::u16string_view aLine, const OUString& aIV, const OUString& aMasterPasswd, css::task::PasswordRequestMode mode )
std::vector< OUString > PasswordContainer::DecodePasswords( std::u16string_view aLine, std::u16string_view aIV, const OUString& aMasterPasswd, css::task::PasswordRequestMode mode )
{
if( !aMasterPasswd.isEmpty() )
{
@@ -428,10 +428,13 @@ std::vector< OUString > PasswordContainer::DecodePasswords( std::u16string_view
code[ ind ] = static_cast<char>(aMasterPasswd.copy( ind*2, 2 ).toUInt32(16));
unsigned char iv[RTL_DIGEST_LENGTH_MD5] = {0};
if (!aIV.isEmpty())
if (!aIV.empty())
{
for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
iv[ ind ] = static_cast<char>(aIV.copy( ind*2, 2 ).toUInt32(16));
{
auto tmp = aIV.substr( ind*2, 2 );
iv[ ind ] = static_cast<char>(rtl_ustr_toInt64_WithLength(tmp.data(), 16, tmp.size()));
}
}
rtlCipherError result = rtl_cipher_init (
@@ -469,7 +472,7 @@ std::vector< OUString > PasswordContainer::DecodePasswords( std::u16string_view
"Can't decode!", css::uno::Reference<css::uno::XInterface>(), mode);
}
OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines, const OUString& aIV, const OUString& aMasterPasswd)
OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines, std::u16string_view aIV, const OUString& aMasterPasswd)
{
if( !aMasterPasswd.isEmpty() )
{
@@ -487,10 +490,13 @@ OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines
code[ ind ] = static_cast<char>(aMasterPasswd.copy( ind*2, 2 ).toUInt32(16));
unsigned char iv[RTL_DIGEST_LENGTH_MD5] = {0};
if (!aIV.isEmpty())
if (!aIV.empty())
{
for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
iv[ ind ] = static_cast<char>(aIV.copy( ind*2, 2 ).toUInt32(16));
{
auto tmp = aIV.substr( ind*2, 2 );
iv[ ind ] = static_cast<char>(rtl_ustr_toInt64_WithLength(tmp.data(), 16, tmp.size()));
}
}
rtlCipherError result = rtl_cipher_init (
@@ -837,12 +843,13 @@ OUString PasswordContainer::RequestPasswordFromUser( PasswordRequestMode aRMode,
}
// Mangle the key to match an old bug
static OUString ReencodeAsOldHash(const OUString& rPass)
static OUString ReencodeAsOldHash(std::u16string_view rPass)
{
OUStringBuffer aBuffer;
for (int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ++ind)
{
unsigned char i = static_cast<char>(rPass.copy(ind * 2, 2).toUInt32(16));
auto tmp = rPass.substr(ind * 2, 2);
unsigned char i = static_cast<char>(rtl_ustr_toInt64_WithLength(tmp.data(), 16, tmp.size()));
aBuffer.append(static_cast< sal_Unicode >('a' + (i >> 4)));
aBuffer.append(static_cast< sal_Unicode >('a' + (i & 15)));
}

View File

@@ -316,10 +316,10 @@ private:
const css::uno::Reference< css::task::XInteractionHandler >& Handler );
/// @throws css::uno::RuntimeException
static ::std::vector< OUString > DecodePasswords( std::u16string_view aLine, const OUString& aIV, const OUString& aMasterPassword, css::task::PasswordRequestMode mode );
static ::std::vector< OUString > DecodePasswords( std::u16string_view aLine, std::u16string_view aIV, const OUString& aMasterPassword, css::task::PasswordRequestMode mode );
/// @throws css::uno::RuntimeException
static OUString EncodePasswords(const std::vector< OUString >& lines, const OUString& aIV, const OUString& aMasterPassword );
static OUString EncodePasswords(const std::vector< OUString >& lines, std::u16string_view aIV, const OUString& aMasterPassword );
public:
PasswordContainer( const css::uno::Reference< css::uno::XComponentContext >& );