Kaydet (Commit) d5415561 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:stringloop in various

Change-Id: Ia400e67108e622ae63a8d59667eae96c858f22dc
Reviewed-on: https://gerrit.libreoffice.org/58463
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst d3e7bbec
......@@ -39,6 +39,8 @@ private:
void StringLoop::run()
{
// Various places are not worth changing, the code becomes too awkward
// Just exclude stuff as I go
StringRef fn(handler.getMainFileName());
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/bridges/"))
return;
......@@ -60,6 +62,120 @@ void StringLoop::run()
return;
if (loplugin::isSamePathname(fn, SRCDIR "/vcl/source/control/combobox.cxx"))
return;
if (loplugin::isSamePathname(fn, SRCDIR "/vcl/source/gdi/pdfwriter_impl.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/svtools/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/idl/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/framework/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/basic/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sfx2/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/avmedia/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/connectivity/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/editeng/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/svx/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/basctl/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/filter/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/chart2/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/cui/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/dbaccess/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/oox/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/writerfilter/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/desktop/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/extensions/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/dtrans/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/i18npool/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/embeddedobj/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sd/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/xmloff/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/xmlhelp/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/forms/"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/core/tool/address.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/core/tool/compiler.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/ui/docshell/impex.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/ui/miscdlgs/acredlin.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/ui/pagedlg/areasdlg.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/ui/view/gridwin2.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sc/source/filter/html/htmlpars.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/doc/doctxm.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/edit/edattr.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/layout/dbg_lay.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/ascii/ascatr.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/html/htmlforw.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/unocore/unosect.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/unocore/unochart.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/core/unocore/unoobj.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/html/parcss1.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/html/svxcss1.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/html/swhtml.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/uibase/utlui/gloslst.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/uibase/utlui/content.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/uibase/docvw/edtwin.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/ww8/ww8atr.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/ww8/ww8scan.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/filter/ww8/ww8par5.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/fldui/fldfunc.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/misc/bookmark.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/dbui/mmlayoutpage.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/dbui/dbinsdlg.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/dbui/mmresultdialogs.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sw/source/ui/index/cnttab.cxx"))
return;
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/ucb/source/ucp/file/bc.cxx"))
return;
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
......@@ -132,11 +248,16 @@ bool StringLoop::VisitCallExpr(CallExpr const* callExpr)
if (!tc.Class("OUString").Namespace("rtl").GlobalNamespace()
&& !tc.Class("OString").Namespace("rtl").GlobalNamespace())
return true;
auto fieldDecl = dyn_cast<FieldDecl>(memberExpr->getMemberDecl());
if (isInUnoIncludeFile(
compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocation())))
return true;
if (ignoreLocation(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocation())))
return true;
report(DiagnosticsEngine::Warning,
"appending to OUString in loop, rather use OUStringBuffer",
operatorCallExpr->getLocStart())
<< operatorCallExpr->getSourceRange();
auto fieldDecl = dyn_cast<FieldDecl>(memberExpr->getMemberDecl());
report(DiagnosticsEngine::Note, "field here", fieldDecl->getLocStart())
<< fieldDecl->getSourceRange();
}
......
......@@ -743,7 +743,7 @@ static OUString lcl_serializeForDisplay( const Reference< XAttr >& _rxAttrNode )
static OUString lcl_serializeForDisplay( const Reference<XNodeList>& xNodes )
{
OUString sResult;
OUStringBuffer sResult;
// create document fragment
Reference<XDocument> xDocument( getDocumentBuilder()->newDocument() );
......@@ -770,7 +770,7 @@ static OUString lcl_serializeForDisplay( const Reference<XNodeList>& xNodes )
Reference< XAttr > xAttr( xCurrent, UNO_QUERY );
if ( xAttr.is() )
{
sResult += lcl_serializeForDisplay( xAttr );
sResult.append(lcl_serializeForDisplay( xAttr ));
++nAttributeNodes;
}
}
......@@ -787,7 +787,7 @@ static OUString lcl_serializeForDisplay( const Reference<XNodeList>& xNodes )
"lcl_serializeForDisplay: mixed attribute and non-attribute nodes?" );
if ( nAttributeNodes )
// had only attribute nodes
return sResult;
return sResult.makeStringAndClear();
// serialize fragment
CSerializationAppXML aSerialization;
......@@ -808,20 +808,19 @@ static OUString lcl_serializeForDisplay( const Reference<XNodeList>& xNodes )
// well, the serialization prepends XML header(s) that we need to
// remove first.
OUStringBuffer aBuffer;
sResult.setLength(0);
while( ! xTextInputStream->isEOF() )
{
OUString sLine = xTextInputStream->readLine();
if( !sLine.isEmpty()
&& !sLine.startsWith( "<?xml" ) )
{
aBuffer.append( sLine );
aBuffer.append( '\n' );
sResult.append( sLine );
sResult.append( '\n' );
}
}
sResult = aBuffer.makeStringAndClear();
return sResult;
return sResult.makeStringAndClear();
}
static OUString lcl_serializeForDisplay( const Reference<XXPathObject>& xResult )
......
......@@ -47,7 +47,7 @@ OUString SmOoxmlImport::ConvertToStarMath()
OUString SmOoxmlImport::handleStream()
{
m_rStream.ensureOpeningTag( M_TOKEN( oMath ));
OUString ret;
OUStringBuffer ret;
while( !m_rStream.atEnd() && m_rStream.currentToken() != CLOSING( M_TOKEN( oMath )))
{
// strictly speaking, it is not OMathArg here, but currently supported
......@@ -56,92 +56,92 @@ OUString SmOoxmlImport::handleStream()
if( item.isEmpty())
continue;
if( !ret.isEmpty())
ret += " ";
ret += item;
ret.append(" ");
ret.append(item);
}
m_rStream.ensureClosingTag( M_TOKEN( oMath ));
// Placeholders are written out as nothing (i.e. nothing inside e.g. the <e> element),
// which will result in "{}" in the formula text. Fix this up.
ret = ret.replaceAll( "{}", "<?>" );
OUString ret2 = ret.makeStringAndClear().replaceAll( "{}", "<?>" );
// And as a result, empty parts of the formula that are not placeholders are written out
// as a single space, so fix that up too.
ret = ret.replaceAll( "{ }", "{}" );
SAL_INFO( "starmath.ooxml", "Formula: " << ret );
return ret;
ret2 = ret2.replaceAll( "{ }", "{}" );
SAL_INFO( "starmath.ooxml", "Formula: " << ret2 );
return ret2;
}
OUString SmOoxmlImport::readOMathArg( int stoptoken )
{
OUString ret;
OUStringBuffer ret;
while( !m_rStream.atEnd() && m_rStream.currentToken() != CLOSING( stoptoken ))
{
if( !ret.isEmpty())
ret += " ";
ret.append(" ");
switch( m_rStream.currentToken())
{
case OPENING( M_TOKEN( acc )):
ret += handleAcc();
ret.append(handleAcc());
break;
case OPENING( M_TOKEN( bar )):
ret += handleBar();
ret.append(handleBar());
break;
case OPENING( M_TOKEN( box )):
ret += handleBox();
ret.append(handleBox());
break;
case OPENING( M_TOKEN( borderBox )):
ret += handleBorderBox();
ret.append(handleBorderBox());
break;
case OPENING( M_TOKEN( d )):
ret += handleD();
ret.append(handleD());
break;
case OPENING( M_TOKEN( eqArr )):
ret += handleEqArr();
ret.append(handleEqArr());
break;
case OPENING( M_TOKEN( f )):
ret += handleF();
ret.append(handleF());
break;
case OPENING( M_TOKEN( func )):
ret += handleFunc();
ret.append(handleFunc());
break;
case OPENING( M_TOKEN( limLow )):
ret += handleLimLowUpp( LimLow );
ret.append(handleLimLowUpp( LimLow ));
break;
case OPENING( M_TOKEN( limUpp )):
ret += handleLimLowUpp( LimUpp );
ret.append(handleLimLowUpp( LimUpp ));
break;
case OPENING( M_TOKEN( groupChr )):
ret += handleGroupChr();
ret.append(handleGroupChr());
break;
case OPENING( M_TOKEN( m )):
ret += handleM();
ret.append(handleM());
break;
case OPENING( M_TOKEN( nary )):
ret += handleNary();
ret.append(handleNary());
break;
case OPENING( M_TOKEN( r )):
ret += handleR();
ret.append(handleR());
break;
case OPENING( M_TOKEN( rad )):
ret += handleRad();
ret.append(handleRad());
break;
case OPENING( M_TOKEN( sPre )):
ret += handleSpre();
ret.append(handleSpre());
break;
case OPENING( M_TOKEN( sSub )):
ret += handleSsub();
ret.append(handleSsub());
break;
case OPENING( M_TOKEN( sSubSup )):
ret += handleSsubsup();
ret.append(handleSsubsup());
break;
case OPENING( M_TOKEN( sSup )):
ret += handleSsup();
ret.append(handleSsup());
break;
default:
m_rStream.handleUnexpectedTag();
break;
}
}
return ret;
return ret.makeStringAndClear();
}
OUString SmOoxmlImport::readOMathArgInElement( int token )
......@@ -364,17 +364,17 @@ OUString SmOoxmlImport::handleD()
OUString SmOoxmlImport::handleEqArr()
{
m_rStream.ensureOpeningTag( M_TOKEN( eqArr ));
OUString ret;
OUStringBuffer ret;
do
{ // there must be at least one m:e
if( !ret.isEmpty())
ret += "#";
ret += " ";
ret += readOMathArgInElement( M_TOKEN( e ));
ret += " ";
ret.append("#");
ret.append(" ");
ret.append(readOMathArgInElement( M_TOKEN( e )));
ret.append(" ");
} while( !m_rStream.atEnd() && m_rStream.findTag( OPENING( M_TOKEN( e ))));
m_rStream.ensureClosingTag( M_TOKEN( eqArr ));
return "stack {" + ret + "}";
return "stack {" + ret.makeStringAndClear() + "}";
}
OUString SmOoxmlImport::handleF()
......@@ -473,24 +473,24 @@ OUString SmOoxmlImport::handleGroupChr()
OUString SmOoxmlImport::handleM()
{
m_rStream.ensureOpeningTag( M_TOKEN( m ));
OUString allrows;
OUStringBuffer allrows;
do // there must be at least one m:mr
{
m_rStream.ensureOpeningTag( M_TOKEN( mr ));
OUString row;
OUStringBuffer row;
do // there must be at least one m:e
{
if( !row.isEmpty())
row += " # ";
row += readOMathArgInElement( M_TOKEN( e ));
row.append(" # ");
row.append(readOMathArgInElement( M_TOKEN( e )));
} while( !m_rStream.atEnd() && m_rStream.findTag( OPENING( M_TOKEN( e ))));
if( !allrows.isEmpty())
allrows += " ## ";
allrows += row;
allrows.append(" ## ");
allrows.append(row);
m_rStream.ensureClosingTag( M_TOKEN( mr ));
} while( !m_rStream.atEnd() && m_rStream.findTag( OPENING( M_TOKEN( mr ))));
m_rStream.ensureClosingTag( M_TOKEN( m ));
return "matrix {" + allrows + "}";
return "matrix {" + allrows.makeStringAndClear() + "}";
}
OUString SmOoxmlImport::handleNary()
......@@ -584,7 +584,7 @@ OUString SmOoxmlImport::handleR()
}
m_rStream.ensureClosingTag( M_TOKEN( rPr ));
}
OUString text;
OUStringBuffer text;
while( !m_rStream.atEnd() && m_rStream.currentToken() != CLOSING( m_rStream.currentToken()))
{
switch( m_rStream.currentToken())
......@@ -593,9 +593,9 @@ OUString SmOoxmlImport::handleR()
{
XmlStream::Tag rtag = m_rStream.ensureOpeningTag( M_TOKEN( t ));
if( rtag.attribute( OOX_TOKEN( xml, space )) != "preserve" )
text += rtag.text.trim();
text.append(rtag.text.trim());
else
text += rtag.text;
text.append(rtag.text);
m_rStream.ensureClosingTag( M_TOKEN( t ));
break;
}
......@@ -606,8 +606,11 @@ OUString SmOoxmlImport::handleR()
}
m_rStream.ensureClosingTag( M_TOKEN( r ));
if( normal || literal )
text = "\"" + text + "\"";
return text.replaceAll("{", "\\{").replaceAll("}", "\\}");
{
text.insert(0, "\"");
text.append("\"");
}
return text.makeStringAndClear().replaceAll("{", "\\{").replaceAll("}", "\\}");
}
OUString SmOoxmlImport::handleRad()
......
......@@ -361,10 +361,10 @@ StaticModuleInformation* Databases::getStaticInformationForModule( const OUStrin
sal_uInt64 nRead;
sal_Char buffer[2048];
sal_Unicode lineBuffer[1028];
OUString fileContent;
OUStringBuffer fileContent;
while( osl::FileBase::E_None == cfgFile.read( &buffer,2048,nRead ) && nRead )
fileContent += OUString( buffer,sal_Int32( nRead ),RTL_TEXTENCODING_UTF8 );
fileContent.append(OUString( buffer,sal_Int32( nRead ),RTL_TEXTENCODING_UTF8 ));
cfgFile.close();
......
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