Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/4213
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/13/4213/1
Simplify SwPaM::GetTxt
Change-Id: Ic8905ff02852dab7f699c2a9f02a6252a5c42c7f
---
M sw/source/core/crsr/pam.cxx
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index c1b059b..9d7761d 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -1066,42 +1066,44 @@
SwNodeIndex aNodeIndex = Start()->nNode;
// The first node can be already the end node.
- // A first end node must be handled, too. Therefore do-while and no
- // incrementing of aNodeIndex in the first pass.
- bool bFirst = true;
- do
+ // Use a "forever" loop with an exit condition in the middle
+ // of its body, in order to correctly handle all cases.
+ bool bIsStartNode = true;
+ for (;;)
{
- if (! bFirst)
- {
- ++aNodeIndex;
- }
-
- bFirst = false;
-
+ const bool bIsEndNode = aNodeIndex == End()->nNode;
SwTxtNode * pTxtNode = aNodeIndex.GetNode().GetTxtNode();
if (pTxtNode != NULL)
{
const OUString aTmpStr = pTxtNode->GetTxt();
- if (aNodeIndex == Start()->nNode)
+ if (bIsStartNode || bIsEndNode)
{
- xub_StrLen nEnd;
- if (End()->nNode == aNodeIndex)
- nEnd = End()->nContent.GetIndex();
- else
- nEnd = aTmpStr.getLength();
+ // Handle corner cases of start/end node(s)
+ const sal_Int32 nStart = bIsStartNode
+ ? static_cast<sal_Int32>(Start()->nContent.GetIndex())
+ : 0;
+ const sal_Int32 nEnd = bIsEndNode
+ ? static_cast<sal_Int32>(End()->nContent.GetIndex())
+ : aTmpStr.getLength();
- aResult += aTmpStr.copy(Start()->nContent.GetIndex(),
- nEnd - Start()->nContent.GetIndex()) ;
+ aResult += aTmpStr.copy(nStart, nEnd-nStart);
}
- else if (aNodeIndex == End()->nNode)
- aResult += aTmpStr.copy(0, End()->nContent.GetIndex());
else
+ {
aResult += aTmpStr;
+ }
}
+
+ if (bIsEndNode)
+ {
+ break;
+ }
+
+ ++aNodeIndex;
+ bIsStartNode = false;
}
- while (aNodeIndex != End()->nNode);
return aResult;
}
--
To view, visit https://gerrit.libreoffice.org/4213
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic8905ff02852dab7f699c2a9f02a6252a5c42c7f
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Matteo Casalin <matteo.casalin@yahoo.com>
Context
- [PATCH] Simplify SwPaM::GetTxt · Matteo Casalin (via Code Review)
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.