sw/inc/docstat.hxx | 24 +++---- sw/qa/core/uwriter.cxx | 118 +++++++++++++++++++-------------------- sw/source/core/bastyp/calc.cxx | 23 +++---- sw/source/filter/xml/xmlmeta.cxx | 32 ++++------ 4 files changed, 95 insertions(+), 102 deletions(-)
New commits: commit 6cbb7ae346966bc3f568972ce9ce0dd6e232a1c4 Author: codemaestro <[email protected]> AuthorDate: Wed Nov 5 15:15:05 2025 +0530 Commit: Ilmari Lauhakangas <[email protected]> CommitDate: Thu Nov 27 08:45:15 2025 +0100 tdf#114441: Convert use of sal_uLong to sal_uInt32 Using sal_uInt32 safely covers all possible counts. Change-Id: Ia80747d21b1f84541693cfff44bfcc8891544b00 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193370 Reviewed-by: Hossein <[email protected]> Code-Style: Hossein <[email protected]> Tested-by: Jenkins diff --git a/sw/inc/docstat.hxx b/sw/inc/docstat.hxx index ba01ac57c220..16b017f9262e 100644 --- a/sw/inc/docstat.hxx +++ b/sw/inc/docstat.hxx @@ -23,20 +23,20 @@ struct SW_DLLPUBLIC SwDocStat { - sal_uInt16 nTable; - sal_uInt16 nGrf; - sal_uInt16 nOLE; - sal_uLong nPage; + sal_uInt32 nTable; + sal_uInt32 nGrf; + sal_uInt32 nOLE; + sal_uInt32 nPage; /// paragraphs for document statistic: non-empty and non-hidden ones - sal_uLong nPara; + sal_uInt32 nPara; /// all paragraphs, including empty/hidden ones - sal_uLong nAllPara; - sal_uLong nWord; - sal_uLong nAsianWord; - sal_uLong nChar; - sal_uLong nCharExcludingSpaces; - sal_uLong nComments; - bool bModified; + sal_uInt32 nAllPara; + sal_uInt32 nWord; + sal_uInt32 nAsianWord; + sal_uInt32 nChar; + sal_uInt32 nCharExcludingSpaces; + sal_uInt32 nComments; + bool bModified; SwDocStat(); void Reset(); diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index 9a2d06845394..b0f866386f23 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -261,7 +261,7 @@ void SwDocTest::testFileNameFields() //motivation void SwDocTest::testDocStat() { - CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected initial 0 count", static_cast<sal_uLong>(0), m_pDoc->getIDocumentStatistics().GetDocStat().nChar); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected initial 0 count", static_cast<sal_uInt32>(0), m_pDoc->getIDocumentStatistics().GetDocStat().nChar); SwNodeIndex aIdx(m_pDoc->GetNodes().GetEndOfContent(), -1); SwPaM aPaM(aIdx); @@ -269,10 +269,10 @@ void SwDocTest::testDocStat() OUString sText(u"Hello World"_ustr); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sText); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Should still be non-updated 0 count", static_cast<sal_uLong>(0), m_pDoc->getIDocumentStatistics().GetDocStat().nChar); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Should still be non-updated 0 count", static_cast<sal_uInt32>(0), m_pDoc->getIDocumentStatistics().GetDocStat().nChar); SwDocStat aDocStat = m_pDoc->getIDocumentStatistics().GetUpdatedDocStat( false, true ); - sal_uLong nLen = static_cast<sal_uLong>(sText.getLength()); + sal_uInt32 nLen = static_cast<sal_uInt32>(sText.getLength()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should now have updated count", nLen, aDocStat.nChar); @@ -628,8 +628,8 @@ void SwDocTest::testSwScanner() pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, IDEOGRAPHICFULLSTOP_D.getLength()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(2), aDocStat.nChar); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(2), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(2), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(2), aDocStat.nCharExcludingSpaces); } { static constexpr OUString test = @@ -660,10 +660,10 @@ void SwDocTest::testSwScanner() SwDocStat aDocStat; pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, test.getLength()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("words", static_cast<sal_uLong>(58), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Asian characters and Korean words", static_cast<sal_uLong>(43), aDocStat.nAsianWord); - CPPUNIT_ASSERT_EQUAL_MESSAGE("non-whitespace chars", static_cast<sal_uLong>(105), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL_MESSAGE("characters", static_cast<sal_uLong>(128), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL_MESSAGE("words", static_cast<sal_uInt32>(58), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Asian characters and Korean words", static_cast<sal_uInt32>(43), aDocStat.nAsianWord); + CPPUNIT_ASSERT_EQUAL_MESSAGE("non-whitespace chars", static_cast<sal_uInt32>(105), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL_MESSAGE("characters", static_cast<sal_uInt32>(128), aDocStat.nChar); } //See https://bz.apache.org/ooo/show_bug.cgi?id=89042 @@ -680,7 +680,7 @@ void SwDocTest::testSwScanner() m_pDoc->getIDocumentContentOperations().InsertString(aPaM, aShouldBeThree); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, aShouldBeThree.getLength()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(3), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(3), aDocStat.nWord); static constexpr OUString aShouldBeFive = u"french " @@ -696,7 +696,7 @@ void SwDocTest::testSwScanner() pTextNode = aPaM.GetPointNode().GetTextNode(); aDocStat.Reset(); pTextNode->CountWords(aDocStat, 0, aShouldBeFive.getLength()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(5), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(5), aDocStat.nWord); } //See https://bugs.libreoffice.org/show_bug.cgi?id=49629 @@ -713,8 +713,8 @@ void SwDocTest::testSwScanner() CPPUNIT_ASSERT(pTA); CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), pTextNode->Len()); //Apple + 0x02 pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(1), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL_MESSAGE("footnote should be expanded", static_cast<sal_uLong>(11), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(1), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL_MESSAGE("footnote should be expanded", static_cast<sal_uInt32>(11), aDocStat.nChar); const sal_Int32 nNextPos = aPaM.GetPoint()->GetContentIndex(); CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(nPos+1), nNextPos); @@ -725,8 +725,8 @@ void SwDocTest::testSwScanner() aDocStat.Reset(); pTextNode->SetWordCountDirty(true); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(1), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL_MESSAGE("refmark anchor should not be counted", static_cast<sal_uLong>(11), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(1), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL_MESSAGE("refmark anchor should not be counted", static_cast<sal_uInt32>(11), aDocStat.nChar); m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, u"Apple"_ustr); @@ -741,8 +741,8 @@ void SwDocTest::testSwScanner() pTextNode = aPaM.GetPointNode().GetTextNode(); aDocStat.Reset(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(1), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL_MESSAGE("postit anchor should effectively not exist", static_cast<sal_uLong>(10), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(1), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL_MESSAGE("postit anchor should effectively not exist", static_cast<sal_uInt32>(10), aDocStat.nChar); CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(11), pTextNode->Len()); aDocStat.Reset(); @@ -757,7 +757,7 @@ void SwDocTest::testSwScanner() m_pDoc->getIDocumentContentOperations().InsertString(aPaM, aString); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(2), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(2), aDocStat.nWord); //turn on red-lining and show changes m_pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete|RedlineFlags::ShowInsert); @@ -774,7 +774,7 @@ void SwDocTest::testSwScanner() aDocStat.Reset(); pTextNode->SetWordCountDirty(true); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); //but word-counting the text should only count the non-deleted text - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(1), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(1), aDocStat.nWord); pTextNode->SetWordCountDirty(true); @@ -785,7 +785,7 @@ void SwDocTest::testSwScanner() aDocStat.Reset(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); //but word-counting the text should only count the non-deleted text - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(1), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(1), aDocStat.nWord); OUString sLorem = pTextNode->GetText(); CPPUNIT_ASSERT_EQUAL(u"Lorem"_ustr, sLorem); @@ -806,8 +806,8 @@ void SwDocTest::testSwScanner() aDocStat.Reset(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); //word-counting the text should only count the non-deleted text, and this whole chunk should be ignored - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(0), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(0), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), aDocStat.nChar); // https://bugs.libreoffice.org/show_bug.cgi?id=68347 we do want to count // redline *added* text though @@ -819,13 +819,13 @@ void SwDocTest::testSwScanner() pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->SetWordCountDirty(true); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(2), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(2), aDocStat.nWord); //redline-new-text Lorem ipsum //+++++++++++++++++ ------ //select start of original text and part of deleted text aDocStat.Reset(); pTextNode->CountWords(aDocStat, 17, 25); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(5), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(5), aDocStat.nChar); } //See https://bugs.libreoffice.org/show_bug.cgi?id=38983 @@ -838,72 +838,72 @@ void SwDocTest::testSwScanner() m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replace('X', ' ')); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(4), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(12), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(15), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(12), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(15), aDocStat.nChar); aDocStat.Reset(); m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replaceAll("X", " = ")); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(5), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(13), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(17), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(5), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(13), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(17), aDocStat.nChar); aDocStat.Reset(); m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replaceAll("X", " _ ")); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(5), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(13), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(17), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(5), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(13), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(17), aDocStat.nChar); aDocStat.Reset(); m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replaceAll("X", " -- ")); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(5), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(14), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(18), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(5), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(14), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(18), aDocStat.nChar); aDocStat.Reset(); m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replace('X', '_')); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(3), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(13), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(15), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(3), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(13), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(15), aDocStat.nChar); aDocStat.Reset(); m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replace('X', '-')); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(3), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(13), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(15), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(3), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(13), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(15), aDocStat.nChar); aDocStat.Reset(); m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replace('X', 0x2012)); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(3), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(13), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(15), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(3), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(13), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(15), aDocStat.nChar); aDocStat.Reset(); m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replace('X', 0x2015)); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(3), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(13), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(15), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(3), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(13), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(15), aDocStat.nChar); aDocStat.Reset(); //But default configuration should, msword-alike treat emdash @@ -912,18 +912,18 @@ void SwDocTest::testSwScanner() m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replace('X', 0x2013)); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(4), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(13), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(15), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(13), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(15), aDocStat.nChar); aDocStat.Reset(); m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replace('X', 0x2014)); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(4), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(13), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(15), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(13), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(15), aDocStat.nChar); aDocStat.Reset(); static constexpr OUStringLiteral sChunk = u" \u2013 "; @@ -931,9 +931,9 @@ void SwDocTest::testSwScanner() m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replaceAll("X", sChunk)); pTextNode = aPaM.GetPointNode().GetTextNode(); pTextNode->CountWords(aDocStat, 0, pTextNode->Len()); - CPPUNIT_ASSERT_EQUAL(sal_uLong(4), aDocStat.nWord); - CPPUNIT_ASSERT_EQUAL(sal_uLong(13), aDocStat.nCharExcludingSpaces); - CPPUNIT_ASSERT_EQUAL(sal_uLong(17), aDocStat.nChar); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aDocStat.nWord); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(13), aDocStat.nCharExcludingSpaces); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(17), aDocStat.nChar); aDocStat.Reset(); } @@ -941,7 +941,7 @@ void SwDocTest::testSwScanner() // // Per i#80815, the intention for the word count feature is to emulate the behavior of MS Word. { - auto fnAssertWords = [&](const OUString& aStr, sal_uLong nWords, sal_uLong nAsianWords) + auto fnAssertWords = [&](const OUString& aStr, sal_uInt32 nWords, sal_uInt32 nAsianWords) { m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); @@ -1009,7 +1009,7 @@ void SwDocTest::testMergePortionsDeleteNotSorted() //See https://bugs.libreoffice.org/show_bug.cgi?id=40599 void SwDocTest::testGraphicAnchorDeletion() { - CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected initial 0 count", static_cast<sal_uLong>(0), m_pDoc->getIDocumentStatistics().GetDocStat().nChar); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected initial 0 count", static_cast<sal_uInt32>(0), m_pDoc->getIDocumentStatistics().GetDocStat().nChar); SwNodeIndex aIdx(m_pDoc->GetNodes().GetEndOfContent(), -1); SwPaM aPaM(aIdx); diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx index d73bb64cc7ac..170b5aa2561d 100644 --- a/sw/source/core/bastyp/calc.cxx +++ b/sw/source/core/bastyp/calc.cxx @@ -244,20 +244,21 @@ SwCalc::SwCalc( SwDoc& rD ) UserOptToken::TelephoneHome, UserOptToken::Fax, UserOptToken::Email, UserOptToken::State }; - static sal_uInt16 SwDocStat::* const aDocStat1[ 3 ] = + static sal_uInt32 SwDocStat::* const aDocStat[ 7 ] = { - &SwDocStat::nTable, &SwDocStat::nGrf, &SwDocStat::nOLE - }; - static sal_uLong SwDocStat::* const aDocStat2[ 4 ] = - { - &SwDocStat::nPage, &SwDocStat::nPara, - &SwDocStat::nWord, &SwDocStat::nChar + &SwDocStat::nTable, + &SwDocStat::nGrf, + &SwDocStat::nOLE, + &SwDocStat::nPage, + &SwDocStat::nPara, + &SwDocStat::nWord, + &SwDocStat::nChar }; const SwDocStat& rDocStat = m_rDoc.getIDocumentStatistics().GetDocStat(); SwSbxValue nVal; - sal_uInt16 n; + sal_uInt32 n; for( n = 0; n < 25; ++n ) m_aVarTable.insert( { sNTypeTab[n], SwCalcExp( nVal, nullptr ) } ); @@ -267,10 +268,8 @@ SwCalc::SwCalc( SwDoc& rD ) lcl_GetCalcExp(m_aVarTable, sNTypeTab[2]).nValue.PutDouble( M_PI ); lcl_GetCalcExp(m_aVarTable, sNTypeTab[3]).nValue.PutDouble( M_E ); - for( n = 0; n < 3; ++n ) - lcl_GetCalcExp(m_aVarTable, sNTypeTab[n + 4]).nValue.PutLong( rDocStat.*aDocStat1[ n ] ); - for( n = 0; n < 4; ++n ) - lcl_GetCalcExp(m_aVarTable, sNTypeTab[n + 7]).nValue.PutLong( rDocStat.*aDocStat2[ n ] ); + for( n = 0; n < 7; ++n ) + lcl_GetCalcExp(m_aVarTable, sNTypeTab[n + 4]).nValue.PutLong( rDocStat.*aDocStat[ n ] ); SvtUserOptions& rUserOptions = SwModule::get()->GetUserOptions(); diff --git a/sw/source/filter/xml/xmlmeta.cxx b/sw/source/filter/xml/xmlmeta.cxx index 21f79d61f474..c903b237ac17 100644 --- a/sw/source/filter/xml/xmlmeta.cxx +++ b/sw/source/filter/xml/xmlmeta.cxx @@ -80,22 +80,21 @@ enum SvXMLTokenMapAttrs struct statistic { SvXMLTokenMapAttrs token; const char* name; - sal_uInt16 SwDocStat::* target16; - sal_uLong SwDocStat::* target32; /* or 64, on LP64 platforms */ + sal_uInt32 SwDocStat::* target32; }; } -const struct statistic s_stats [] = { - { XML_TOK_META_STAT_TABLE, "TableCount", &SwDocStat::nTable, nullptr }, - { XML_TOK_META_STAT_IMAGE, "ImageCount", &SwDocStat::nGrf, nullptr }, - { XML_TOK_META_STAT_OLE, "ObjectCount", &SwDocStat::nOLE, nullptr }, - { XML_TOK_META_STAT_PAGE, "PageCount", nullptr, &SwDocStat::nPage }, - { XML_TOK_META_STAT_PARA, "ParagraphCount", nullptr, &SwDocStat::nPara }, - { XML_TOK_META_STAT_WORD, "WordCount", nullptr, &SwDocStat::nWord }, - { XML_TOK_META_STAT_CHAR, "CharacterCount", nullptr, &SwDocStat::nChar }, - { XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR, "NonWhitespaceCharacterCount", nullptr, &SwDocStat::nCharExcludingSpaces }, - { XML_TOK_META_STAT_END, nullptr, nullptr, nullptr } +const struct statistic s_stats[] = { + { XML_TOK_META_STAT_TABLE, "TableCount", &SwDocStat::nTable }, + { XML_TOK_META_STAT_IMAGE, "ImageCount", &SwDocStat::nGrf }, + { XML_TOK_META_STAT_OLE, "ObjectCount", &SwDocStat::nOLE }, + { XML_TOK_META_STAT_PAGE, "PageCount", &SwDocStat::nPage }, + { XML_TOK_META_STAT_PARA, "ParagraphCount", &SwDocStat::nPara }, + { XML_TOK_META_STAT_WORD, "WordCount", &SwDocStat::nWord }, + { XML_TOK_META_STAT_CHAR, "CharacterCount", &SwDocStat::nChar }, + { XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR, "NonWhitespaceCharacterCount", &SwDocStat::nCharExcludingSpaces }, + { XML_TOK_META_STAT_END, nullptr, nullptr } }; void SwXMLImport::SetStatistics( @@ -117,13 +116,8 @@ void SwXMLImport::SetStatistics( if (rStat.Name.equalsAscii(pStat->name)) { sal_Int32 val = 0; if (rStat.Value >>= val) { - if (pStat->target16 != nullptr) { - aDocStat.*(pStat->target16) - = o3tl::narrowing<sal_uInt16> (val); - } else { - aDocStat.*(pStat->target32) - = static_cast<sal_uInt32> (val); - } + aDocStat.*(pStat->target32) + = static_cast<sal_uInt32> (val); nTokens |= pStat->token; } else { OSL_FAIL("SwXMLImport::SetStatistics: invalid entry");
