diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-04-10 18:01:17 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-04-10 20:09:26 +0200 |
commit | f6fa9c455502e9a00e4a4cff6e19f3e17c5479c3 (patch) | |
tree | 2aec6ab1a00a8be7630b5b189269f076e2b7d2b0 /sc | |
parent | b454107b87ac78096d98fd7ceedcbfac71d247a0 (diff) |
Use more *string_view
Change-Id: I1172febd45da4dba006f8495427fe45c6d9b9fa6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150187
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/excel/excdoc.cxx | 26 | ||||
-rw-r--r-- | sc/source/filter/excel/excrecds.cxx | 35 | ||||
-rw-r--r-- | sc/source/filter/excel/xeescher.cxx | 11 | ||||
-rw-r--r-- | sc/source/filter/excel/xename.cxx | 2 | ||||
-rw-r--r-- | sc/source/filter/excel/xepage.cxx | 16 | ||||
-rw-r--r-- | sc/source/filter/excel/xestream.cxx | 37 | ||||
-rw-r--r-- | sc/source/filter/xcl97/xcl97rec.cxx | 4 |
7 files changed, 65 insertions, 66 deletions
diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx index c01dde32981c..8e394ad73146 100644 --- a/sc/source/filter/excel/excdoc.cxx +++ b/sc/source/filter/excel/excdoc.cxx @@ -692,12 +692,12 @@ void ExcTable::WriteXml( XclExpXmlStream& rStrm ) rStrm.PushStream( pWorksheet ); pWorksheet->startElement( XML_worksheet, - XML_xmlns, rStrm.getNamespaceURL(OOX_NS(xls)).toUtf8(), - FSNS(XML_xmlns, XML_r), rStrm.getNamespaceURL(OOX_NS(officeRel)).toUtf8(), - FSNS(XML_xmlns, XML_xdr), "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing", // rStrm.getNamespaceURL(OOX_NS(xm)).toUtf8() -> "http://schemas.microsoft.com/office/excel/2006/main", - FSNS(XML_xmlns, XML_x14), rStrm.getNamespaceURL(OOX_NS(xls14Lst)).toUtf8(), - FSNS(XML_xmlns, XML_xr2), rStrm.getNamespaceURL(OOX_NS(xr2)).toUtf8(), - FSNS(XML_xmlns, XML_mc), rStrm.getNamespaceURL(OOX_NS(mce)).toUtf8()); + XML_xmlns, rStrm.getNamespaceURL(OOX_NS(xls)), + FSNS(XML_xmlns, XML_r), rStrm.getNamespaceURL(OOX_NS(officeRel)), + FSNS(XML_xmlns, XML_xdr), "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing", // rStrm.getNamespaceURL(OOX_NS(xm)) -> "http://schemas.microsoft.com/office/excel/2006/main", + FSNS(XML_xmlns, XML_x14), rStrm.getNamespaceURL(OOX_NS(xls14Lst)), + FSNS(XML_xmlns, XML_xr2), rStrm.getNamespaceURL(OOX_NS(xr2)), + FSNS(XML_xmlns, XML_mc), rStrm.getNamespaceURL(OOX_NS(mce))); SetCurrScTab( mnScTab ); if (mxCellTable) @@ -835,8 +835,8 @@ void ExcDocument::WriteXml( XclExpXmlStream& rStrm ) sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream(); rWorkbook->startElement( XML_workbook, - XML_xmlns, rStrm.getNamespaceURL(OOX_NS(xls)).toUtf8(), - FSNS(XML_xmlns, XML_r), rStrm.getNamespaceURL(OOX_NS(officeRel)).toUtf8() ); + XML_xmlns, rStrm.getNamespaceURL(OOX_NS(xls)), + FSNS(XML_xmlns, XML_r), rStrm.getNamespaceURL(OOX_NS(officeRel)) ); rWorkbook->singleElement( XML_fileVersion, XML_appName, "Calc" // OOXTODO: XML_codeName @@ -848,14 +848,14 @@ void ExcDocument::WriteXml( XclExpXmlStream& rStrm ) if (bHasPasswordHash) rWorkbook->singleElement(XML_fileSharing, XML_userName, sUserName, - XML_reservationPassword, OString::number(nWriteProtHash, 16).getStr()); + XML_reservationPassword, OString::number(nWriteProtHash, 16)); else if (bHasPasswordInfo) rWorkbook->singleElement(XML_fileSharing, XML_userName, sUserName, - XML_algorithmName, sAlgorithm.toUtf8().getStr(), - XML_hashValue, sHash.toUtf8().getStr(), - XML_saltValue, sSalt.toUtf8().getStr(), - XML_spinCount, OString::number(nCount).getStr()); + XML_algorithmName, sAlgorithm, + XML_hashValue, sHash, + XML_saltValue, sSalt, + XML_spinCount, OString::number(nCount)); if( !maTableList.IsEmpty() ) { diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx index f69a5ca431c8..3c4aa0571fc6 100644 --- a/sc/source/filter/excel/excrecds.cxx +++ b/sc/source/filter/excel/excrecds.cxx @@ -439,7 +439,7 @@ void XclExpSheetProtection::SaveXml( XclExpXmlStream& rStrm ) aPH = rPH; Sequence<sal_Int8> aHash = pTabProtect->getPasswordHash(PASSHASH_XL); - OString sHash; + std::optional<OString> sHash; if (aHash.getLength() >= 2) { sHash = OString::number( @@ -449,12 +449,12 @@ void XclExpSheetProtection::SaveXml( XclExpXmlStream& rStrm ) } sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream(); rWorksheet->singleElement( XML_sheetProtection, - XML_algorithmName, aPH.maAlgorithmName.isEmpty() ? nullptr : aPH.maAlgorithmName.toUtf8().getStr(), - XML_hashValue, aPH.maHashValue.isEmpty() ? nullptr : aPH.maHashValue.toUtf8().getStr(), - XML_saltValue, aPH.maSaltValue.isEmpty() ? nullptr : aPH.maSaltValue.toUtf8().getStr(), - XML_spinCount, aPH.mnSpinCount ? OString::number( aPH.mnSpinCount).getStr() : nullptr, + XML_algorithmName, sax_fastparser::UseIf(aPH.maAlgorithmName, !aPH.maAlgorithmName.isEmpty()), + XML_hashValue, sax_fastparser::UseIf(aPH.maHashValue, !aPH.maHashValue.isEmpty()), + XML_saltValue, sax_fastparser::UseIf(aPH.maSaltValue, !aPH.maSaltValue.isEmpty()), + XML_spinCount, sax_fastparser::UseIf(OString::number(aPH.mnSpinCount), aPH.mnSpinCount != 0), XML_sheet, ToPsz( true ), - XML_password, sHash.isEmpty()? nullptr : sHash.getStr(), + XML_password, sHash, XML_objects, pTabProtect->isOptionEnabled( ScTableProtection::OBJECTS ) ? nullptr : ToPsz( true ), XML_scenarios, pTabProtect->isOptionEnabled( ScTableProtection::SCENARIOS ) ? nullptr : ToPsz( true ), XML_formatCells, pTabProtect->isOptionEnabled( ScTableProtection::FORMAT_CELLS ) ? ToPsz( false ) : nullptr, @@ -481,17 +481,17 @@ void XclExpSheetProtection::SaveXml( XclExpXmlStream& rStrm ) SAL_WARN_IF( rProt.maSecurityDescriptorXML.isEmpty() && !rProt.maSecurityDescriptor.empty(), "sc.filter", "XclExpSheetProtection::SaveXml: losing BIFF security descriptor"); rWorksheet->singleElement( XML_protectedRange, - XML_name, rProt.maTitle.isEmpty() ? nullptr : rProt.maTitle.toUtf8().getStr(), - XML_securityDescriptor, rProt.maSecurityDescriptorXML.isEmpty() ? nullptr : rProt.maSecurityDescriptorXML.toUtf8().getStr(), + XML_name, sax_fastparser::UseIf(rProt.maTitle, !rProt.maTitle.isEmpty()), + XML_securityDescriptor, sax_fastparser::UseIf(rProt.maSecurityDescriptorXML, !rProt.maSecurityDescriptorXML.isEmpty()), /* XXX 'password' is not part of OOXML, but Excel2013 * writes it if loaded from BIFF, in which case * 'algorithmName', 'hashValue', 'saltValue' and * 'spinCount' are absent; so do we if it was present. */ - XML_password, rProt.mnPasswordVerifier ? OString::number( rProt.mnPasswordVerifier, 16).getStr() : nullptr, - XML_algorithmName, rProt.maPasswordHash.maAlgorithmName.isEmpty() ? nullptr : rProt.maPasswordHash.maAlgorithmName.toUtf8().getStr(), - XML_hashValue, rProt.maPasswordHash.maHashValue.isEmpty() ? nullptr : rProt.maPasswordHash.maHashValue.toUtf8().getStr(), - XML_saltValue, rProt.maPasswordHash.maSaltValue.isEmpty() ? nullptr : rProt.maPasswordHash.maSaltValue.toUtf8().getStr(), - XML_spinCount, rProt.maPasswordHash.mnSpinCount ? OString::number( rProt.maPasswordHash.mnSpinCount).getStr() : nullptr, + XML_password, sax_fastparser::UseIf(OString::number(rProt.mnPasswordVerifier, 16), rProt.mnPasswordVerifier != 0), + XML_algorithmName, sax_fastparser::UseIf(rProt.maPasswordHash.maAlgorithmName, !rProt.maPasswordHash.maAlgorithmName.isEmpty()), + XML_hashValue, sax_fastparser::UseIf(rProt.maPasswordHash.maHashValue, !rProt.maPasswordHash.maHashValue.isEmpty()), + XML_saltValue, sax_fastparser::UseIf(rProt.maPasswordHash.maSaltValue, !rProt.maPasswordHash.maSaltValue.isEmpty()), + XML_spinCount, sax_fastparser::UseIf(OString::number(rProt.maPasswordHash.mnSpinCount), rProt.maPasswordHash.mnSpinCount != 0), XML_sqref, rProt.maRangeList.is() ? XclXmlUtils::ToOString( rStrm.GetRoot().GetDoc(), *rProt.maRangeList).getStr() : nullptr); } rWorksheet->endElement( XML_protectedRanges); @@ -888,14 +888,13 @@ void XclExpAutofilter::SaveXml( XclExpXmlStream& rStrm ) for (const auto& rMultiValue : maMultiValues) { - OString aStr = OUStringToOString(rMultiValue.first, RTL_TEXTENCODING_UTF8); if( !rMultiValue.second ) { - const char* pz = aStr.getStr(); - rWorksheet->singleElement(XML_filter, XML_val, pz); + rWorksheet->singleElement(XML_filter, XML_val, rMultiValue.first); } else { + OString aStr = OUStringToOString(rMultiValue.first, RTL_TEXTENCODING_UTF8); rtl::Reference<sax_fastparser::FastAttributeList> pAttrList = sax_fastparser::FastSerializerHelper::createAttrList(); sal_Int32 aDateGroup[3] = { XML_year, XML_month, XML_day }; sal_Int32 idx = 0; @@ -1166,12 +1165,12 @@ void ExcAutoFilterRecs::SaveXml( XclExpXmlStream& rStrm ) XML_ref, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), std::get<0>(rSortCriteria)), XML_descending, "1", - XML_customList, std::get<1>(rSortCriteria).toUtf8().getStr()); + XML_customList, std::get<1>(rSortCriteria)); else rWorksheet->singleElement(XML_sortCondition, XML_ref, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), std::get<0>(rSortCriteria)), - XML_customList, std::get<1>(rSortCriteria).toUtf8().getStr()); + XML_customList, std::get<1>(rSortCriteria)); } rWorksheet->endElement(XML_sortState); diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx index 44e1225cf17c..ed634c1fcf84 100644 --- a/sc/source/filter/excel/xeescher.cxx +++ b/sc/source/filter/excel/xeescher.cxx @@ -1240,7 +1240,7 @@ void XclExpTbxControlObj::SaveXml( XclExpXmlStream& rStrm ) pDrawing->startElement(FSNS(XML_xdr, XML_nvSpPr)); { pDrawing->singleElement(FSNS(XML_xdr, XML_cNvPr), - XML_id, OString::number(mnShapeId).getStr(), + XML_id, OString::number(mnShapeId), XML_name, msCtrlName, // control name XML_descr, msLabel, // description as alt text XML_hidden, mbVisible ? "0" : "1"); @@ -1453,7 +1453,7 @@ void XclExpTbxControlObj::SaveSheetXml(XclExpXmlStream& rStrm, const OUString& a rWorksheet->startElement( XML_control, - XML_shapeId, OString::number(mnShapeId).getStr(), + XML_shapeId, OString::number(mnShapeId), FSNS(XML_r, XML_id), aIdFormControlPr, XML_name, msLabel); // text to display with checkbox button @@ -1498,15 +1498,14 @@ void XclExpTbxControlObj::SaveSheetXml(XclExpXmlStream& rStrm, const OUString& a rStrm.getNamespaceURL(OOX_NS(mce))); rWorksheet->startElement(FSNS(XML_mc, XML_Choice), XML_Requires, "x14"); - rWorksheet->startElement(XML_control, XML_shapeId, OString::number(mnShapeId).getStr(), + rWorksheet->startElement(XML_control, XML_shapeId, OString::number(mnShapeId), FSNS(XML_r, XML_id), aIdFormControlPr, XML_name, msCtrlName); - OString aMacroName = GetMacroName().toUtf8(); + OUString aMacroName = GetMacroName(); // Omit the macro attribute if it would be empty. - const char* pMacroName = aMacroName.isEmpty() ? nullptr : aMacroName.getStr(); rWorksheet->startElement(XML_controlPr, XML_defaultSize, "0", XML_print, mbPrint ? "true" : "false", XML_autoFill, "0", XML_autoPict, - "0", XML_macro, pMacroName); + "0", XML_macro, sax_fastparser::UseIf(aMacroName, !aMacroName.isEmpty())); rWorksheet->startElement(XML_anchor, XML_moveWithCells, "true", XML_sizeWithCells, "false"); diff --git a/sc/source/filter/excel/xename.cxx b/sc/source/filter/excel/xename.cxx index c8fd0ed37036..4e837a97fadf 100644 --- a/sc/source/filter/excel/xename.cxx +++ b/sc/source/filter/excel/xename.cxx @@ -333,7 +333,7 @@ void XclExpName::SaveXml( XclExpXmlStream& rStrm ) // OOXTODO: XML_functionGroupId, "", // OOXTODO: XML_help, "", XML_hidden, ToPsz( ::get_flag( mnFlags, EXC_NAME_HIDDEN ) ), - XML_localSheetId, mnScTab == SCTAB_GLOBAL ? nullptr : OString::number( mnScTab ).getStr(), + XML_localSheetId, sax_fastparser::UseIf(OString::number( mnScTab ), mnScTab != SCTAB_GLOBAL), XML_name, maOrigName.toUtf8(), // OOXTODO: XML_publishToServer, "", // OOXTODO: XML_shortcutKey, "", diff --git a/sc/source/filter/excel/xepage.cxx b/sc/source/filter/excel/xepage.cxx index d9a2b1ed8bdc..144ab51c076e 100644 --- a/sc/source/filter/excel/xepage.cxx +++ b/sc/source/filter/excel/xepage.cxx @@ -101,7 +101,7 @@ void XclExpSetup::SaveXml( XclExpXmlStream& rStrm ) if( rStrm.getVersion() != oox::core::ISOIEC_29500_2008 || mrData.mnStrictPaperSize != EXC_PAPERSIZE_USER ) { - pAttrList->add( XML_paperSize, OString::number( mrData.mnPaperSize ).getStr() ); + pAttrList->add( XML_paperSize, OString::number( mrData.mnPaperSize ) ); } else { @@ -109,9 +109,9 @@ void XclExpSetup::SaveXml( XclExpXmlStream& rStrm ) pAttrList->add( XML_paperHeight, OString::number( mrData.mnPaperHeight ) + "mm" ); // pAttrList->add( XML_paperUnits, "mm" ); } - pAttrList->add( XML_scale, OString::number( mrData.mnScaling ).getStr() ); - pAttrList->add( XML_fitToWidth, OString::number( mrData.mnFitToWidth ).getStr() ); - pAttrList->add( XML_fitToHeight, OString::number( mrData.mnFitToHeight ).getStr() ); + pAttrList->add( XML_scale, OString::number( mrData.mnScaling ) ); + pAttrList->add( XML_fitToWidth, OString::number( mrData.mnFitToWidth ) ); + pAttrList->add( XML_fitToHeight, OString::number( mrData.mnFitToHeight ) ); pAttrList->add( XML_pageOrder, mrData.mbPrintInRows ? "overThenDown" : "downThenOver" ); pAttrList->add( XML_orientation, mrData.mbPortrait ? "portrait" : "landscape" ); // OOXTODO: "default"? // tdf#48767 if XML_usePrinterDefaults field is exist, then XML_orientation is always "portrait" in MS Excel @@ -124,13 +124,13 @@ void XclExpSetup::SaveXml( XclExpXmlStream& rStrm ) if ( mrData.mbManualStart ) { - pAttrList->add( XML_firstPageNumber, OString::number( mrData.mnStartPage ).getStr() ); + pAttrList->add( XML_firstPageNumber, OString::number( mrData.mnStartPage ) ); pAttrList->add( XML_useFirstPageNumber, ToPsz( mrData.mbManualStart ) ); } // OOXTODO: XML_errors, // == displayed|blank|dash|NA - pAttrList->add( XML_horizontalDpi, OString::number( mrData.mnHorPrintRes ).getStr() ); - pAttrList->add( XML_verticalDpi, OString::number( mrData.mnVerPrintRes ).getStr() ); - pAttrList->add( XML_copies, OString::number( mrData.mnCopies ).getStr() ); + pAttrList->add( XML_horizontalDpi, OString::number( mrData.mnHorPrintRes ) ); + pAttrList->add( XML_verticalDpi, OString::number( mrData.mnVerPrintRes ) ); + pAttrList->add( XML_copies, OString::number( mrData.mnCopies ) ); // OOXTODO: devMode settings part RelationshipId: FSNS( XML_r, XML_id ), rStrm.GetCurrentStream()->singleElement( XML_pageSetup, pAttrList ); diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx index 374743786212..75f03dfde94d 100644 --- a/sc/source/filter/excel/xestream.cxx +++ b/sc/source/filter/excel/xestream.cxx @@ -834,13 +834,6 @@ OUString XclXmlUtils::ToOUString( const XclExpString& s ) return ToOUString( s.GetUnicodeBuffer() ); } -static void lcl_WriteValue( const sax_fastparser::FSHelperPtr& rStream, sal_Int32 nElement, const char* pValue ) -{ - if( !pValue ) - return; - rStream->singleElement(nElement, XML_val, pValue); -} - static const char* lcl_GetUnderlineStyle( FontLineStyle eUnderline, bool& bHaveUnderline ) { bHaveUnderline = true; @@ -873,16 +866,23 @@ sax_fastparser::FSHelperPtr XclXmlUtils::WriteFontData( sax_fastparser::FSHelper const char* pUnderline = lcl_GetUnderlineStyle( rFontData.GetScUnderline(), bHaveUnderline ); const char* pVertAlign = lcl_ToVerticalAlignmentRun( rFontData.GetScEscapement(), bHaveVertAlign ); - lcl_WriteValue( pStream, XML_b, rFontData.mnWeight > 400 ? ToPsz( true ) : nullptr ); - lcl_WriteValue( pStream, XML_i, rFontData.mbItalic ? ToPsz( true ) : nullptr ); - lcl_WriteValue( pStream, XML_strike, rFontData.mbStrikeout ? ToPsz( true ) : nullptr ); + if (rFontData.mnWeight > 400) + pStream->singleElement(XML_b, XML_val, ToPsz( true )); + if (rFontData.mbItalic) + pStream->singleElement(XML_i, XML_val, ToPsz( true )); + if (rFontData.mbStrikeout) + pStream->singleElement(XML_strike, XML_val, ToPsz( true )); // OOXTODO: lcl_WriteValue( rStream, XML_condense, ); // mac compatibility setting // OOXTODO: lcl_WriteValue( rStream, XML_extend, ); // compatibility setting - lcl_WriteValue( pStream, XML_outline, rFontData.mbOutline ? ToPsz( true ) : nullptr ); - lcl_WriteValue( pStream, XML_shadow, rFontData.mbShadow ? ToPsz( true ) : nullptr ); - lcl_WriteValue( pStream, XML_u, bHaveUnderline ? pUnderline : nullptr ); - lcl_WriteValue( pStream, XML_vertAlign, bHaveVertAlign ? pVertAlign : nullptr ); - lcl_WriteValue( pStream, XML_sz, OString::number( rFontData.mnHeight / 20.0 ).getStr() ); // Twips->Pt + if (rFontData.mbOutline) + pStream->singleElement(XML_outline, XML_val, ToPsz( true )); + if (rFontData.mbShadow) + pStream->singleElement(XML_shadow, XML_val, ToPsz( true )); + if (bHaveUnderline) + pStream->singleElement(XML_u, XML_val, pUnderline); + if (bHaveVertAlign) + pStream->singleElement(XML_vertAlign, XML_val, pVertAlign); + pStream->singleElement(XML_sz, XML_val, OString::number( rFontData.mnHeight / 20.0 )); // Twips->Pt if( rFontData.maColor != Color( ColorAlpha, 0, 0xFF, 0xFF, 0xFF ) ) pStream->singleElement( XML_color, // OOXTODO: XML_auto, bool @@ -891,9 +891,10 @@ sax_fastparser::FSHelperPtr XclXmlUtils::WriteFontData( sax_fastparser::FSHelper // OOXTODO: XML_theme, index into <clrScheme/> // OOXTODO: XML_tint, double ); - lcl_WriteValue( pStream, nFontId, rFontData.maName.toUtf8().getStr() ); - lcl_WriteValue( pStream, XML_family, OString::number( rFontData.mnFamily ).getStr() ); - lcl_WriteValue( pStream, XML_charset, rFontData.mnCharSet != 0 ? OString::number( rFontData.mnCharSet ).getStr() : nullptr ); + pStream->singleElement(nFontId, XML_val, rFontData.maName); + pStream->singleElement(XML_family, XML_val, OString::number( rFontData.mnFamily )); + if (rFontData.mnCharSet != 0) + pStream->singleElement(XML_charset, XML_val, OString::number(rFontData.mnCharSet)); return pStream; } diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx index 8f930c80993b..f9031449bf70 100644 --- a/sc/source/filter/xcl97/xcl97rec.cxx +++ b/sc/source/filter/xcl97/xcl97rec.cxx @@ -1591,10 +1591,10 @@ void ExcEScenario::SaveXml( XclExpXmlStream& rStrm ) { sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream(); rWorkbook->startElement( XML_scenario, - XML_name, XclXmlUtils::ToOString( sName ).getStr(), + XML_name, XclXmlUtils::ToOString( sName ), XML_locked, ToPsz( bProtected ), // OOXTODO: XML_hidden, - XML_count, OString::number( aCells.size() ).getStr(), + XML_count, OString::number( aCells.size() ), XML_user, XESTRING_TO_PSZ( sUserName ), XML_comment, XESTRING_TO_PSZ( sComment ) ); |