Kaydet (Commit) 218be53f authored tarafından Michael Stahl's avatar Michael Stahl

tools: replace boost::ptr_vector with std::unordered_map

Change-Id: I530c5f95dda9aa80654e3a2a20a2e236221e7305
üst 5c832532
...@@ -971,9 +971,8 @@ Reference<deployment::XPackage> PackageManagerImpl::getDeployedPackage_( ...@@ -971,9 +971,8 @@ Reference<deployment::XPackage> PackageManagerImpl::getDeployedPackage_(
INetContentTypeParameterList params; INetContentTypeParameterList params;
if (INetContentTypes::parse( data.mediaType, type, subType, &params )) if (INetContentTypes::parse( data.mediaType, type, subType, &params ))
{ {
INetContentTypeParameter const * param = params.find( auto const iter = params.find(OString("platform"));
OString("platform") ); if (iter != params.end() && !platform_fits(iter->second.m_sValue))
if (param != 0 && !platform_fits( param->m_sValue ))
throw lang::IllegalArgumentException( throw lang::IllegalArgumentException(
getResourceString(RID_STR_NO_SUCH_PACKAGE) + id, getResourceString(RID_STR_NO_SUCH_PACKAGE) + id,
static_cast<OWeakObject *>(this), static_cast<OWeakObject *>(this),
......
...@@ -670,21 +670,21 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( ...@@ -670,21 +670,21 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_(
{ {
// xxx todo: probe and evaluate component xml description // xxx todo: probe and evaluate component xml description
INetContentTypeParameter const * param = params.find(OString("platform")); auto const iter = params.find(OString("platform"));
bool bPlatformFits(param == 0); bool bPlatformFits(iter == params.end());
OUString aPlatform; OUString aPlatform;
if (!bPlatformFits) // platform is specified, we have to check if (!bPlatformFits) // platform is specified, we have to check
{ {
aPlatform = param->m_sValue; aPlatform = iter->second.m_sValue;
bPlatformFits = platform_fits(aPlatform); bPlatformFits = platform_fits(aPlatform);
} }
// If the package is being removed, do not care whether // If the package is being removed, do not care whether
// platform fits. We won't be using it anyway. // platform fits. We won't be using it anyway.
if (bPlatformFits || bRemoved) { if (bPlatformFits || bRemoved) {
param = params.find(OString("type")); auto const iterType = params.find(OString("type"));
if (param != 0) if (iterType != params.end())
{ {
OUString const & value = param->m_sValue; OUString const & value = iterType->second.m_sValue;
if (value.equalsIgnoreAsciiCase("native")) { if (value.equalsIgnoreAsciiCase("native")) {
if (bPlatformFits) if (bPlatformFits)
return new BackendImpl::ComponentPackageImpl( return new BackendImpl::ComponentPackageImpl(
...@@ -713,8 +713,8 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( ...@@ -713,8 +713,8 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_(
} }
else if (subType.equalsIgnoreAsciiCase("vnd.sun.star.uno-components")) else if (subType.equalsIgnoreAsciiCase("vnd.sun.star.uno-components"))
{ {
INetContentTypeParameter const * param = params.find(OString("platform")); auto const iter = params.find(OString("platform"));
if (param == 0 || platform_fits( param->m_sValue )) { if (iter == params.end() || platform_fits(iter->second.m_sValue)) {
return new BackendImpl::ComponentsPackageImpl( return new BackendImpl::ComponentsPackageImpl(
this, url, name, m_xComponentsTypeInfo, bRemoved, this, url, name, m_xComponentsTypeInfo, bRemoved,
identifier); identifier);
...@@ -722,9 +722,9 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_( ...@@ -722,9 +722,9 @@ Reference<deployment::XPackage> BackendImpl::bindPackage_(
} }
else if (subType.equalsIgnoreAsciiCase( "vnd.sun.star.uno-typelibrary")) else if (subType.equalsIgnoreAsciiCase( "vnd.sun.star.uno-typelibrary"))
{ {
INetContentTypeParameter const * param = params.find(OString("type")); auto const iter = params.find(OString("type"));
if (param != 0) { if (iter != params.end()) {
OUString const & value = param->m_sValue; OUString const & value = iter->second.m_sValue;
if (value.equalsIgnoreAsciiCase("RDB")) if (value.equalsIgnoreAsciiCase("RDB"))
{ {
return new BackendImpl::TypelibraryPackageImpl( return new BackendImpl::TypelibraryPackageImpl(
......
...@@ -1473,8 +1473,8 @@ void BackendImpl::PackageImpl::scanBundle( ...@@ -1473,8 +1473,8 @@ void BackendImpl::PackageImpl::scanBundle(
if (! INetContentTypes::parse( mediaType, type, subType, &params )) if (! INetContentTypes::parse( mediaType, type, subType, &params ))
continue; continue;
INetContentTypeParameter const * param = params.find("platform"); auto const iter = params.find("platform");
if (param != 0 && !platform_fits( param->m_sValue )) if (iter != params.end() && !platform_fits(iter->second.m_sValue))
continue; continue;
const OUString url( makeURL( packageRootURL, fullPath ) ); const OUString url( makeURL( packageRootURL, fullPath ) );
...@@ -1483,14 +1483,15 @@ void BackendImpl::PackageImpl::scanBundle( ...@@ -1483,14 +1483,15 @@ void BackendImpl::PackageImpl::scanBundle(
subType.equalsIgnoreAsciiCase( "vnd.sun.star.package-bundle-description")) subType.equalsIgnoreAsciiCase( "vnd.sun.star.package-bundle-description"))
{ {
// check locale: // check locale:
param = params.find("locale"); auto const iterLocale = params.find("locale");
if (param == 0) { if (iterLocale == params.end())
{
if (descrFile.isEmpty()) if (descrFile.isEmpty())
descrFile = url; descrFile = url;
} }
else { else {
// match best locale: // match best locale:
LanguageTag descrTag( param->m_sValue); LanguageTag descrTag(iter->second.m_sValue);
if (officeLocale.getLanguage() == descrTag.getLanguage()) if (officeLocale.getLanguage() == descrTag.getLanguage())
{ {
size_t nPenalty = nPenaltyMax; size_t nPenalty = nPenaltyMax;
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
#ifndef INCLUDED_TOOLS_INETMIME_HXX #ifndef INCLUDED_TOOLS_INETMIME_HXX
#define INCLUDED_TOOLS_INETMIME_HXX #define INCLUDED_TOOLS_INETMIME_HXX
#include <boost/ptr_container/ptr_vector.hpp>
#include <tools/toolsdllapi.h> #include <tools/toolsdllapi.h>
#include <rtl/alloc.h> #include <rtl/alloc.h>
#include <rtl/character.hxx> #include <rtl/character.hxx>
...@@ -31,11 +29,81 @@ ...@@ -31,11 +29,81 @@
#include <tools/debug.hxx> #include <tools/debug.hxx>
#include <tools/errcode.hxx> #include <tools/errcode.hxx>
#include <unordered_map>
class DateTime; class DateTime;
class INetContentTypeParameterList;
class INetMIMECharsetList_Impl; class INetMIMECharsetList_Impl;
class INetMIMEOutputSink; class INetMIMEOutputSink;
struct INetContentTypeParameter
{
/** The name of the attribute, in US-ASCII encoding and converted to lower
case. If a parameter value is split as described in RFC 2231, there
will only be one item for the complete parameter, with the attribute
name lacking any section suffix.
*/
const OString m_sAttribute;
/** The optional character set specification (see RFC 2231), in US-ASCII
encoding and converted to lower case.
*/
const OString m_sCharset;
/** The optional language specification (see RFC 2231), in US-ASCII
encoding and converted to lower case.
*/
const OString m_sLanguage;
/** The attribute value. If the value is a quoted-string, it is
'unpacked.' If a character set is specified, and the value can be
converted to Unicode, this is done. Also, if no character set is
specified, it is first tried to convert the value from UTF-8 encoding
to Unicode, and if that doesn't work (because the value is not in
UTF-8 encoding), it is converted from ISO-8859-1 encoding to Unicode
(which will always work). But if a character set is specified and the
value cannot be converted from that character set to Unicode, special
action is taken to produce a value that can possibly be transformed
back into its original form: Any 8-bit character from a non-encoded
part of the original value is directly converted to Unicode
(effectively handling it as if it was ISO-8859-1 encoded), and any
8-bit character from an encoded part of the original value is mapped
to the range U+F800..U+F8FF at the top of the Corporate Use Subarea
within Unicode's Private Use Area (effectively adding 0xF800 to the
character's numeric value).
*/
const OUString m_sValue;
/** This is true if the value is successfully converted to Unicode, and
false if the value is a special mixture of ISO-LATIN-1 characters and
characters from Unicode's Private Use Area.
*/
const bool m_bConverted;
INetContentTypeParameter(const OString& rTheAttribute,
const OString& rTheCharset, const OString& rTheLanguage,
const OUString& rTheValue, bool bTheConverted)
: m_sAttribute(rTheAttribute)
, m_sCharset(rTheCharset)
, m_sLanguage(rTheLanguage)
, m_sValue(rTheValue)
, m_bConverted(bTheConverted)
{
}
};
struct OString_equalsIgnoreAsciiCase
{
bool operator()(const OString& r1, const OString& r2) const
{
return r1.equalsIgnoreAsciiCase(r2);
}
};
// the key is the m_sAttribute again
typedef std::unordered_map<OString, INetContentTypeParameter, OStringHash,
OString_equalsIgnoreAsciiCase> INetContentTypeParameterList;
class TOOLS_DLLPUBLIC INetMIME class TOOLS_DLLPUBLIC INetMIME
{ {
public: public:
...@@ -935,80 +1003,6 @@ inline bool INetMIMEEncodedWordOutputSink::flush() ...@@ -935,80 +1003,6 @@ inline bool INetMIMEEncodedWordOutputSink::flush()
return m_ePrevCoding != CODING_NONE; return m_ePrevCoding != CODING_NONE;
} }
struct INetContentTypeParameter
{
/** The name of the attribute, in US-ASCII encoding and converted to lower
case. If a parameter value is split as described in RFC 2231, there
will only be one item for the complete parameter, with the attribute
name lacking any section suffix.
*/
const OString m_sAttribute;
/** The optional character set specification (see RFC 2231), in US-ASCII
encoding and converted to lower case.
*/
const OString m_sCharset;
/** The optional language specification (see RFC 2231), in US-ASCII
encoding and converted to lower case.
*/
const OString m_sLanguage;
/** The attribute value. If the value is a quoted-string, it is
'unpacked.' If a character set is specified, and the value can be
converted to Unicode, this is done. Also, if no character set is
specified, it is first tried to convert the value from UTF-8 encoding
to Unicode, and if that doesn't work (because the value is not in
UTF-8 encoding), it is converted from ISO-8859-1 encoding to Unicode
(which will always work). But if a character set is specified and the
value cannot be converted from that character set to Unicode, special
action is taken to produce a value that can possibly be transformed
back into its original form: Any 8-bit character from a non-encoded
part of the original value is directly converted to Unicode
(effectively handling it as if it was ISO-8859-1 encoded), and any
8-bit character from an encoded part of the original value is mapped
to the range U+F800..U+F8FF at the top of the Corporate Use Subarea
within Unicode's Private Use Area (effectively adding 0xF800 to the
character's numeric value).
*/
const OUString m_sValue;
/** This is true if the value is successfully converted to Unicode, and
false if the value is a special mixture of ISO-LATIN-1 characters and
characters from Unicode's Private Use Area.
*/
const bool m_bConverted;
INetContentTypeParameter(const OString& rTheAttribute,
const OString& rTheCharset, const OString& rTheLanguage,
const OUString& rTheValue, bool bTheConverted)
: m_sAttribute(rTheAttribute)
, m_sCharset(rTheCharset)
, m_sLanguage(rTheLanguage)
, m_sValue(rTheValue)
, m_bConverted(bTheConverted)
{
}
};
class TOOLS_DLLPUBLIC INetContentTypeParameterList
{
public:
void Clear();
void Append(INetContentTypeParameter *pParameter)
{
maEntries.push_back(pParameter);
}
const INetContentTypeParameter * find(const OString& rAttribute) const;
private:
boost::ptr_vector<INetContentTypeParameter> maEntries;
};
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -48,8 +48,7 @@ void Test::testBad() { ...@@ -48,8 +48,7 @@ void Test::testBad() {
CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s, &ps)); CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s, &ps));
CPPUNIT_ASSERT(t.isEmpty()); CPPUNIT_ASSERT(t.isEmpty());
CPPUNIT_ASSERT(s.isEmpty()); CPPUNIT_ASSERT(s.isEmpty());
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT(ps.end() == ps.find("foo"));
static_cast<INetContentTypeParameter const *>(0), ps.find("foo"));
} }
void Test::testFull() { void Test::testFull() {
...@@ -63,9 +62,9 @@ void Test::testFull() { ...@@ -63,9 +62,9 @@ void Test::testFull() {
CPPUNIT_ASSERT(INetContentTypes::parse(in, t, s, &ps)); CPPUNIT_ASSERT(INetContentTypes::parse(in, t, s, &ps));
CPPUNIT_ASSERT_EQUAL(OUString("foo"), t); CPPUNIT_ASSERT_EQUAL(OUString("foo"), t);
CPPUNIT_ASSERT_EQUAL(OUString("bar"), s); CPPUNIT_ASSERT_EQUAL(OUString("bar"), s);
INetContentTypeParameter const * p = ps.find("baz"); auto iter = ps.find("baz");
CPPUNIT_ASSERT(p != 0); CPPUNIT_ASSERT(iter != ps.end());
CPPUNIT_ASSERT_EQUAL(OUString("boz"), p->m_sValue); CPPUNIT_ASSERT_EQUAL(OUString("boz"), iter->second.m_sValue);
} }
void Test::testFollow() { void Test::testFollow() {
...@@ -79,8 +78,7 @@ void Test::testFollow() { ...@@ -79,8 +78,7 @@ void Test::testFollow() {
CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s)); CPPUNIT_ASSERT(!INetContentTypes::parse(in, t, s));
CPPUNIT_ASSERT(t.isEmpty()); CPPUNIT_ASSERT(t.isEmpty());
CPPUNIT_ASSERT(s.isEmpty()); CPPUNIT_ASSERT(s.isEmpty());
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT(ps.end() == ps.find("baz"));
static_cast<INetContentTypeParameter const *>(0), ps.find("baz"));
} }
CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_TEST_SUITE_REGISTRATION(Test);
......
...@@ -2092,9 +2092,10 @@ rtl_TextEncoding HTMLParser::GetEncodingByMIME( const OUString& rMime ) ...@@ -2092,9 +2092,10 @@ rtl_TextEncoding HTMLParser::GetEncodingByMIME( const OUString& rMime )
INetContentTypeParameterList aParameters; INetContentTypeParameterList aParameters;
if (INetContentTypes::parse(rMime, sType, sSubType, &aParameters)) if (INetContentTypes::parse(rMime, sType, sSubType, &aParameters))
{ {
const INetContentTypeParameter * pCharset = aParameters.find("charset"); auto const iter = aParameters.find("charset");
if (pCharset != 0) if (iter != aParameters.end())
{ {
const INetContentTypeParameter * pCharset = &iter->second;
OString sValue(OUStringToOString(pCharset->m_sValue, RTL_TEXTENCODING_ASCII_US)); OString sValue(OUStringToOString(pCharset->m_sValue, RTL_TEXTENCODING_ASCII_US));
return GetExtendedCompatibilityTextEncoding( rtl_getTextEncodingFromMimeCharset( sValue.getStr() ) ); return GetExtendedCompatibilityTextEncoding( rtl_getTextEncodingFromMimeCharset( sValue.getStr() ) );
} }
......
...@@ -257,7 +257,7 @@ bool parseParameters(ParameterList const & rInput, ...@@ -257,7 +257,7 @@ bool parseParameters(ParameterList const & rInput,
INetContentTypeParameterList * pOutput) INetContentTypeParameterList * pOutput)
{ {
if (pOutput) if (pOutput)
pOutput->Clear(); pOutput->clear();
Parameter * pPrev = 0; Parameter * pPrev = 0;
for (Parameter * p = rInput.m_pList; p; p = p->m_pNext) for (Parameter * p = rInput.m_pList; p; p = p->m_pNext)
...@@ -335,11 +335,14 @@ bool parseParameters(ParameterList const & rInput, ...@@ -335,11 +335,14 @@ bool parseParameters(ParameterList const & rInput,
break; break;
}; };
} }
pOutput->Append(new INetContentTypeParameter(p->m_aAttribute, auto const ret = pOutput->insert(std::make_pair(p->m_aAttribute,
INetContentTypeParameter(p->m_aAttribute,
p->m_aCharset, p->m_aCharset,
p->m_aLanguage, p->m_aLanguage,
aValue, aValue,
!bBadEncoding)); !bBadEncoding)));
SAL_INFO_IF(!ret.second, "tools",
"INetMIME: dropping duplicate parameter: " << p->m_aAttribute);
p = pNext; p = pNext;
} }
return true; return true;
...@@ -3738,24 +3741,4 @@ INetMIMEEncodedWordOutputSink::WriteUInt32(sal_uInt32 nChar) ...@@ -3738,24 +3741,4 @@ INetMIMEEncodedWordOutputSink::WriteUInt32(sal_uInt32 nChar)
return *this; return *this;
} }
// INetContentTypeParameterList
void INetContentTypeParameterList::Clear()
{
maEntries.clear();
}
const INetContentTypeParameter *
INetContentTypeParameterList::find(const OString& rAttribute) const
{
boost::ptr_vector<INetContentTypeParameter>::const_iterator iter;
for (iter = maEntries.begin(); iter != maEntries.end(); ++iter)
{
if (iter->m_sAttribute.equalsIgnoreAsciiCase(rAttribute))
return &(*iter);
}
return NULL;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment