Fix loplugin:stringliteralvar
...detection of OUString( const sal_Unicode * value, sal_Int32 length ) ctor. (On platforms where sal_Int32 is a typedef for int, an argument that already is of type int will not be wrapped in an ImplicitCastExpr to the sal_Int32 typedef.) Change-Id: Ifc5456a62d42c1acad76ea949549dc24bd67201a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110654 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
parent
4b92707c19
commit
4cae353cae
@ -74,7 +74,8 @@ public:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
switch (expr->getConstructor()->getNumParams())
|
||||
auto const ctor = expr->getConstructor();
|
||||
switch (ctor->getNumParams())
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
@ -126,7 +127,9 @@ public:
|
||||
.Namespace("libreoffice_internal")
|
||||
.Namespace("rtl")
|
||||
.GlobalNamespace())
|
||||
|| (loplugin::TypeCheck(e2->getType()).Typedef("sal_Int32").GlobalNamespace()
|
||||
|| (loplugin::TypeCheck(ctor->getParamDecl(1)->getType())
|
||||
.Typedef("sal_Int32")
|
||||
.GlobalNamespace()
|
||||
&& e2->isIntegerConstantExpr(compiler.getASTContext()))))
|
||||
{
|
||||
return true;
|
||||
|
@ -87,4 +87,12 @@ void f9()
|
||||
f(OUString(literal, SAL_N_ELEMENTS(literal)));
|
||||
}
|
||||
|
||||
void f10()
|
||||
{
|
||||
// expected-error@+1 {{change type of variable 'literal' from constant character array ('const sal_Unicode [3]') to OUStringLiteral [loplugin:stringliteralvar]}}
|
||||
static sal_Unicode const literal[] = { 'f', 'o', 'o' };
|
||||
// expected-note@+1 {{first passed into a 'rtl::OUString' constructor here [loplugin:stringliteralvar]}}
|
||||
f(OUString(literal, 3));
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
|
@ -57,8 +57,8 @@ namespace {
|
||||
OUString lclGetShapeId( sal_Int32 nShapeId )
|
||||
{
|
||||
// identifier consists of a literal NUL character, a lowercase 's', and the id
|
||||
sal_Unicode const aStr[2] = { '\0', 's' };
|
||||
return OUString( aStr, 2 ) + OUString::number( nShapeId );
|
||||
static constexpr OUStringLiteral aStr = u"\0s";
|
||||
return aStr + OUString::number( nShapeId );
|
||||
}
|
||||
|
||||
/** Returns the numeric VML shape identifier from its textual representation. */
|
||||
|
@ -81,45 +81,41 @@ void createMessage(
|
||||
void test::oustringbuffer::Utf32::appendUtf32() {
|
||||
int const str1Len = 3;
|
||||
sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
|
||||
int const str2Len = 4;
|
||||
sal_Unicode const str2[str2Len] = { 'a', 'b', 'c', 'd' };
|
||||
int const str3Len = 6;
|
||||
sal_Unicode const str3[str3Len] = { 'a', 'b', 'c', 'd', 0xD800, 0xDC00 };
|
||||
static constexpr OUStringLiteral str2 = u"abcd";
|
||||
static constexpr OUStringLiteral str3 = u"abcd\U00010000";
|
||||
OStringBuffer message;
|
||||
OUStringBuffer buf1(std::u16string_view(str1, str1Len));
|
||||
buf1.appendUtf32('d');
|
||||
OUString res1(buf1.makeStringAndClear());
|
||||
createMessage(message, res1, OUString(str2, str2Len));
|
||||
createMessage(message, res1, str2);
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
message.getStr(), OUString(str2, str2Len), res1);
|
||||
OUStringBuffer buf2(std::u16string_view(str2, str2Len));
|
||||
message.getStr(), OUString(str2), res1);
|
||||
OUStringBuffer buf2(str2);
|
||||
buf2.appendUtf32(0x10000);
|
||||
OUString res2(buf2.makeStringAndClear());
|
||||
createMessage(message, res2, OUString(str3, str3Len));
|
||||
createMessage(message, res2, str3);
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
message.getStr(), OUString(str3, str3Len), res2);
|
||||
message.getStr(), OUString(str3), res2);
|
||||
}
|
||||
|
||||
void test::oustringbuffer::Utf32::insertUtf32() {
|
||||
int const str1Len = 3;
|
||||
sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
|
||||
int const str2Len = 4;
|
||||
sal_Unicode const str2[str2Len] = { 'a', 'b', 'd', 'c' };
|
||||
int const str3Len = 6;
|
||||
sal_Unicode const str3[str3Len] = { 'a', 'b', 0xDBFF, 0xDFFF, 'd', 'c' };
|
||||
static constexpr OUStringLiteral str2 = u"abdc";
|
||||
static constexpr OUStringLiteral str3 = u"ab\U0010FFFFdc";
|
||||
OStringBuffer message;
|
||||
OUStringBuffer buf1(std::u16string_view(str1, str1Len));
|
||||
buf1.insertUtf32(2, 'd');
|
||||
OUString res1(buf1.makeStringAndClear());
|
||||
createMessage(message, res1, OUString(str2, str2Len));
|
||||
createMessage(message, res1, str2);
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
message.getStr(), OUString(str2, str2Len), res1);
|
||||
OUStringBuffer buf2(std::u16string_view(str2, str2Len));
|
||||
message.getStr(), OUString(str2), res1);
|
||||
OUStringBuffer buf2(str2);
|
||||
buf2.insertUtf32(2, 0x10FFFF);
|
||||
OUString res2(buf2.makeStringAndClear());
|
||||
createMessage(message, res2, OUString(str3, str3Len));
|
||||
createMessage(message, res2, str3);
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
message.getStr(), OUString(str3, str3Len), res2);
|
||||
message.getStr(), OUString(str3), res2);
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@ -876,8 +876,8 @@ namespace sw::mark {
|
||||
return vListEntries[nCurrentIdx];
|
||||
}
|
||||
|
||||
static const sal_Unicode vEnSpaces[ODF_FORMFIELD_DEFAULT_LENGTH] = {8194, 8194, 8194, 8194, 8194};
|
||||
return OUString(vEnSpaces, ODF_FORMFIELD_DEFAULT_LENGTH);
|
||||
static constexpr OUStringLiteral vEnSpaces = u"\u2002\u2002\u2002\u2002\u2002";
|
||||
return vEnSpaces;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -690,12 +690,12 @@ FIELD_INSERT:
|
||||
if(pCursorPos)
|
||||
{
|
||||
// Insert five En Space into the text field so the field has extent
|
||||
static const sal_Unicode vEnSpaces[ODF_FORMFIELD_DEFAULT_LENGTH] = {8194, 8194, 8194, 8194, 8194};
|
||||
bool bSuccess = rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, OUString(vEnSpaces, ODF_FORMFIELD_DEFAULT_LENGTH));
|
||||
static constexpr OUStringLiteral vEnSpaces = u"\u2002\u2002\u2002\u2002\u2002";
|
||||
bool bSuccess = rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, vEnSpaces);
|
||||
if(bSuccess)
|
||||
{
|
||||
IDocumentMarkAccess* pMarksAccess = rSh.GetDoc()->getIDocumentMarkAccess();
|
||||
SwPaM aFieldPam(pCursorPos->GetPoint()->nNode, pCursorPos->GetPoint()->nContent.GetIndex() - ODF_FORMFIELD_DEFAULT_LENGTH,
|
||||
SwPaM aFieldPam(pCursorPos->GetPoint()->nNode, pCursorPos->GetPoint()->nContent.GetIndex() - vEnSpaces.getLength(),
|
||||
pCursorPos->GetPoint()->nNode, pCursorPos->GetPoint()->nContent.GetIndex());
|
||||
pMarksAccess->makeFieldBookmark(aFieldPam, OUString(), ODF_FORMTEXT,
|
||||
aFieldPam.Start());
|
||||
|
Loading…
x
Reference in New Issue
Block a user