summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-06-03 10:58:26 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-06-03 10:58:26 +0200
commit643b70006fd5f6762561696421808f20d4e1e86f (patch)
treee770962bd4830b9b41abf5446f5674f67c164048
parent9cf0ac710a6ace0a833fa193c7e18c4a7405bc42 (diff)
Teach loplugin:stringconstant about RTL_CONSTASCII_STRINGPARAM
Change-Id: I8ff0e104aad045f3835dc8facc760a8339b1d088
-rw-r--r--avmedia/source/macavf/player.mm2
-rw-r--r--avmedia/source/macavf/window.mm2
-rw-r--r--compilerplugins/clang/stringconstant.cxx14
-rw-r--r--compilerplugins/clang/typecheck.cxx10
-rw-r--r--compilerplugins/clang/typecheck.hxx2
-rw-r--r--framework/inc/protocols.h20
-rw-r--r--sal/qa/rtl/oustring/rtl_OUString2.cxx53
-rw-r--r--vcl/osx/printaccessoryview.mm72
8 files changed, 86 insertions, 89 deletions
diff --git a/avmedia/source/macavf/player.mm b/avmedia/source/macavf/player.mm
index 4f753c3f0441..e747364d55af 100644
--- a/avmedia/source/macavf/player.mm
+++ b/avmedia/source/macavf/player.mm
@@ -392,7 +392,7 @@ uno::Reference< media::XFrameGrabber > SAL_CALL Player::createFrameGrabber()
sal_Bool SAL_CALL Player::supportsService( const ::rtl::OUString& ServiceName )
throw (uno::RuntimeException)
{
- return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_MACAVF_PLAYER_SERVICENAME ) );
+ return ServiceName == AVMEDIA_MACAVF_PLAYER_SERVICENAME;
}
diff --git a/avmedia/source/macavf/window.mm b/avmedia/source/macavf/window.mm
index 0ddee7fe120d..6bfd6c122466 100644
--- a/avmedia/source/macavf/window.mm
+++ b/avmedia/source/macavf/window.mm
@@ -282,7 +282,7 @@ void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventLis
sal_Bool SAL_CALL Window::supportsService( const ::rtl::OUString& ServiceName )
throw (uno::RuntimeException)
{
- return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( AVMEDIA_MACAVF_WINDOW_SERVICENAME ) );
+ return ServiceName == AVMEDIA_MACAVF_WINDOW_SERVICENAME;
}
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index 456413c6eb99..c68d58f9b6b0 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -821,6 +821,20 @@ bool StringConstant::isStringConstant(
assert(embeddedNuls != nullptr);
assert(terminatingNul != nullptr);
QualType t = expr->getType();
+ // Look inside RTL_CONSTASCII_STRINGPARAM:
+ if (loplugin::TypeCheck(t).Pointer().Const().Char()) {
+ auto e2 = dyn_cast<UnaryOperator>(expr);
+ if (e2 == nullptr || e2->getOpcode() != UO_AddrOf) {
+ return false;
+ }
+ auto e3 = dyn_cast<ArraySubscriptExpr>(
+ e2->getSubExpr()->IgnoreParenImpCasts());
+ if (e3 == nullptr || !isZero(e3->getIdx()->IgnoreParenImpCasts())) {
+ return false;
+ }
+ expr = e3->getBase()->IgnoreParenImpCasts();
+ t = expr->getType();
+ }
if (!(t->isConstantArrayType() && t.isConstQualified()
&& (loplugin::TypeCheck(t->getAsArrayTypeUnsafe()->getElementType())
.Char())))
diff --git a/compilerplugins/clang/typecheck.cxx b/compilerplugins/clang/typecheck.cxx
index e185643ec32e..800a2d295bc7 100644
--- a/compilerplugins/clang/typecheck.cxx
+++ b/compilerplugins/clang/typecheck.cxx
@@ -39,6 +39,16 @@ TypeCheck TypeCheck::LvalueReference() const {
return TypeCheck();
}
+TypeCheck TypeCheck::Pointer() const {
+ if (!type_.isNull()) {
+ auto const t = type_->getAs<clang::PointerType>();
+ if (t != nullptr) {
+ return TypeCheck(t->getPointeeType());
+ }
+ }
+ return TypeCheck();
+}
+
TypeCheck TypeCheck::NotSubstTemplateTypeParmType() const {
return
(!type_.isNull()
diff --git a/compilerplugins/clang/typecheck.hxx b/compilerplugins/clang/typecheck.hxx
index 70e3d8c9c265..c49adccae3c3 100644
--- a/compilerplugins/clang/typecheck.hxx
+++ b/compilerplugins/clang/typecheck.hxx
@@ -31,6 +31,8 @@ public:
TerminalCheck Char() const;
+ TypeCheck Pointer() const;
+
TypeCheck LvalueReference() const;
template<std::size_t N> inline NamespaceCheck Class(char const (& id)[N])
diff --git a/framework/inc/protocols.h b/framework/inc/protocols.h
index fafba56637ce..d729d6f72235 100644
--- a/framework/inc/protocols.h
+++ b/framework/inc/protocols.h
@@ -86,34 +86,34 @@ class ProtocolCheck
switch(eRequired)
{
case E_PRIVATE:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_PRIVATE);
break;
case E_PRIVATE_OBJECT:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_OBJECT));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_PRIVATE_OBJECT);
break;
case E_PRIVATE_STREAM:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_STREAM));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_PRIVATE_STREAM);
break;
case E_PRIVATE_FACTORY:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_PRIVATE_FACTORY));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_PRIVATE_FACTORY);
break;
case E_SLOT:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_SLOT));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_SLOT);
break;
case E_UNO:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_UNO));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_UNO);
break;
case E_MACRO:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_MACRO));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_MACRO);
break;
case E_SERVICE:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_SERVICE));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_SERVICE);
break;
case E_MAILTO:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_MAILTO));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_MAILTO);
break;
case E_NEWS:
- bRet = sURL.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(SPECIALPROTOCOL_NEWS));
+ bRet = sURL.startsWith(SPECIALPROTOCOL_NEWS);
break;
default:
bRet = sal_False;
diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx
index 6c44741a44c2..00a7f6667579 100644
--- a/sal/qa/rtl/oustring/rtl_OUString2.cxx
+++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx
@@ -925,32 +925,16 @@ public:
};
void indexOfAscii::test() {
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), rtl::OUString().indexOf(""));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), rtl::OUString().lastIndexOf(""));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rtl::OUString("foo").indexOf("foo"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rtl::OUString("foo").lastIndexOf("foo"));
CPPUNIT_ASSERT_EQUAL(
- sal_Int32(-1),
- rtl::OUString().indexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
+ sal_Int32(2), rtl::OUString("fofoobar").indexOf("foo"));
CPPUNIT_ASSERT_EQUAL(
- sal_Int32(-1),
- rtl::OUString().lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
+ sal_Int32(3), rtl::OUString("foofoofob").lastIndexOf("foo"));
CPPUNIT_ASSERT_EQUAL(
- sal_Int32(0),
- rtl::OUString("foo").indexOfAsciiL(
- RTL_CONSTASCII_STRINGPARAM("foo")));
- CPPUNIT_ASSERT_EQUAL(
- sal_Int32(0),
- rtl::OUString("foo").lastIndexOfAsciiL(
- RTL_CONSTASCII_STRINGPARAM("foo")));
- CPPUNIT_ASSERT_EQUAL(
- sal_Int32(2),
- rtl::OUString("fofoobar").indexOfAsciiL(
- RTL_CONSTASCII_STRINGPARAM("foo")));
- CPPUNIT_ASSERT_EQUAL(
- sal_Int32(3),
- rtl::OUString("foofoofob").
- lastIndexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
- CPPUNIT_ASSERT_EQUAL(
- sal_Int32(3),
- rtl::OUString("foofoobar").indexOfAsciiL(
- RTL_CONSTASCII_STRINGPARAM("foo"), 1));
+ sal_Int32(3), rtl::OUString("foofoobar").indexOf("foo", 1));
}
class endsWith: public CppUnit::TestFixture {
@@ -963,24 +947,11 @@ public:
};
void endsWith::test() {
- CPPUNIT_ASSERT_EQUAL(
- true,
- rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
- CPPUNIT_ASSERT_EQUAL(
- false,
- rtl::OUString().endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")));
- CPPUNIT_ASSERT_EQUAL(
- true,
- rtl::OUString("bar").endsWithAsciiL(
- RTL_CONSTASCII_STRINGPARAM("bar")));
- CPPUNIT_ASSERT_EQUAL(
- true,
- rtl::OUString("foobar").endsWithAsciiL(
- RTL_CONSTASCII_STRINGPARAM("bar")));
- CPPUNIT_ASSERT_EQUAL(
- false,
- rtl::OUString("FOOBAR").endsWithAsciiL(
- RTL_CONSTASCII_STRINGPARAM("bar")));
+ CPPUNIT_ASSERT_EQUAL(true, rtl::OUString().endsWith(""));
+ CPPUNIT_ASSERT_EQUAL(false, rtl::OUString().endsWith("foo"));
+ CPPUNIT_ASSERT_EQUAL(true, rtl::OUString("bar").endsWith("bar"));
+ CPPUNIT_ASSERT_EQUAL(true, rtl::OUString("foobar").endsWith("bar"));
+ CPPUNIT_ASSERT_EQUAL(false, rtl::OUString("FOOBAR").endsWith("bar"));
}
class isEmpty: public CppUnit::TestFixture {
diff --git a/vcl/osx/printaccessoryview.mm b/vcl/osx/printaccessoryview.mm
index db23d3ca8359..e25bf7a092e7 100644
--- a/vcl/osx/printaccessoryview.mm
+++ b/vcl/osx/printaccessoryview.mm
@@ -259,7 +259,7 @@ public:
if( pVal )
{
// ugly
- if( name_it->second.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PrintContent")) )
+ if( name_it->second == "PrintContent" )
pVal->Value <<= i_bValue ? sal_Int32(2) : sal_Int32(0);
else
pVal->Value <<= i_bValue;
@@ -301,7 +301,7 @@ public:
-1;
std::map< int, rtl::OUString >::const_iterator name_it = maTagToPropertyName.find( nTag );
- if( name_it != maTagToPropertyName.end() && ! name_it->second.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PrintContent")) )
+ if( name_it != maTagToPropertyName.end() && name_it->second != "PrintContent" )
{
vcl::PrinterController * mpController = [mpAccessoryController printerController];
BOOL bEnabled = mpController->isUIOptionEnabled( name_it->second ) ? YES : NO;
@@ -889,7 +889,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
aFieldRect.origin.y = rCurY - aFieldRect.size.height;
[pFieldView setFrame: aFieldRect];
- if( rCtrlType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Range" ) ) )
+ if( rCtrlType == "Range" )
{
// add a stepper control
NSRect aStepFrame = { { aFieldRect.origin.x + aFieldRect.size.width + 5,
@@ -1011,29 +1011,29 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
for( int n = 0; n < aOptProp.getLength(); n++ )
{
const beans::PropertyValue& rEntry( aOptProp[ n ] );
- if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ControlType")) )
+ if( rEntry.Name == "ControlType" )
{
rEntry.Value >>= aCtrlType;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Choices")) )
+ else if( rEntry.Name == "Choices" )
{
rEntry.Value >>= aChoices;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ChoicesDisabled")) )
+ else if( rEntry.Name == "ChoicesDisabled" )
{
rEntry.Value >>= aChoicesDisabled;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Property")) )
+ else if( rEntry.Name == "Property" )
{
PropertyValue aVal;
rEntry.Value >>= aVal;
aPropertyName = aVal.Name;
- if( aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PrintContent")) )
+ if( aPropertyName == "PrintContent" )
aVal.Value >>= aSelectionChecked;
}
}
- if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Radio")) &&
- aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PrintContent")) &&
+ if( aCtrlType == "Radio" &&
+ aPropertyName == "PrintContent" &&
aChoices.getLength() > 2 )
{
bAddSelectionCheckBox = true;
@@ -1062,74 +1062,74 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
for( int n = 0; n < aOptProp.getLength(); n++ )
{
const beans::PropertyValue& rEntry( aOptProp[ n ] );
- if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Text")) )
+ if( rEntry.Name == "Text" )
{
rEntry.Value >>= aText;
aText = filterAccelerator( aText );
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ControlType")) )
+ else if( rEntry.Name == "ControlType" )
{
rEntry.Value >>= aCtrlType;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Choices")) )
+ else if( rEntry.Name == "Choices" )
{
rEntry.Value >>= aChoices;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Property")) )
+ else if( rEntry.Name == "Property" )
{
PropertyValue aVal;
rEntry.Value >>= aVal;
aPropertyName = aVal.Name;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Enabled")) )
+ else if( rEntry.Name == "Enabled" )
{
sal_Bool bValue = true;
rEntry.Value >>= bValue;
bEnabled = bValue;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MinValue")) )
+ else if( rEntry.Name == "MinValue" )
{
rEntry.Value >>= nMinValue;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MaxValue")) )
+ else if( rEntry.Name == "MaxValue" )
{
rEntry.Value >>= nMaxValue;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("AttachToDependency")) )
+ else if( rEntry.Name == "AttachToDependency" )
{
nAttachOffset = 20;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("InternalUIOnly")) )
+ else if( rEntry.Name == "InternalUIOnly" )
{
sal_Bool bValue = false;
rEntry.Value >>= bValue;
bIgnore = bValue;
}
- else if( rEntry.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("GroupingHint")) )
+ else if( rEntry.Name == "GroupingHint" )
{
rEntry.Value >>= aGroupHint;
}
}
- if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Group")) ||
- aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) ||
- aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Radio")) ||
- aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("List")) ||
- aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Edit")) ||
- aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range")) ||
- aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Bool")) )
+ if( aCtrlType == "Group" ||
+ aCtrlType == "Subgroup" ||
+ aCtrlType == "Radio" ||
+ aCtrlType == "List" ||
+ aCtrlType == "Edit" ||
+ aCtrlType == "Range" ||
+ aCtrlType == "Bool" )
{
bool bIgnoreSubgroup = false;
// with `setAccessoryView' method only one accessory view can be set
// so create this single accessory view as tabbed for grouping
- if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Group"))
+ if( aCtrlType == "Group"
|| ! pCurParent
- || ( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) && nCurY < -250 && ! bIgnore )
+ || ( aCtrlType == "Subgroup" && nCurY < -250 && ! bIgnore )
)
{
rtl::OUString aGroupTitle( aText );
- if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) )
+ if( aCtrlType == "Subgroup" )
aGroupTitle = pControllerProperties->getMoreString();
// set size of current parent
@@ -1163,7 +1163,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
}
}
- if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Subgroup")) && pCurParent )
+ if( aCtrlType == "Subgroup" && pCurParent )
{
bIgnoreSubgroup = bIgnore;
if( bIgnore )
@@ -1175,7 +1175,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
{
continue;
}
- else if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Bool")) && pCurParent )
+ else if( aCtrlType == "Bool" && pCurParent )
{
sal_Bool bVal = false;
PropertyValue* pVal = pController->getValue( aPropertyName );
@@ -1185,7 +1185,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
aText, true, aPropertyName, bVal,
aRightColumn, pControllerProperties, pCtrlTarget );
}
- else if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Radio")) && pCurParent )
+ else if( aCtrlType == "Radio" && pCurParent )
{
// get currently selected value
sal_Int32 nSelectVal = 0;
@@ -1198,7 +1198,7 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
aLeftColumn, aRightColumn,
pControllerProperties, pCtrlTarget );
}
- else if( aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("List")) && pCurParent )
+ else if( aCtrlType == "List" && pCurParent )
{
PropertyValue* pVal = pController->getValue( aPropertyName );
sal_Int32 aSelectVal = 0;
@@ -1210,8 +1210,8 @@ static void addEdit( NSView* pCurParent, long& rCurX, long& rCurY, long nAttachO
aLeftColumn, aRightColumn,
pControllerProperties, pCtrlTarget );
}
- else if( (aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Edit"))
- || aCtrlType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Range"))) && pCurParent )
+ else if( (aCtrlType == "Edit"
+ || aCtrlType == "Range") && pCurParent )
{
// current value
PropertyValue* pVal = pController->getValue( aPropertyName );