Simplify SwPaM::GetTxt

Change-Id: Ic8905ff02852dab7f699c2a9f02a6252a5c42c7f
Reviewed-on: https://gerrit.libreoffice.org/4213
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Michael Stahl <mstahl@redhat.com>
This commit is contained in:
Matteo Casalin
2013-06-09 12:05:10 +02:00
committed by Michael Stahl
parent 3d12036000
commit 21e43f598e

View File

@@ -1066,42 +1066,44 @@ OUString SwPaM::GetTxt() const
SwNodeIndex aNodeIndex = Start()->nNode; SwNodeIndex aNodeIndex = Start()->nNode;
// The first node can be already the end node. // The first node can be already the end node.
// A first end node must be handled, too. Therefore do-while and no // Use a "forever" loop with an exit condition in the middle
// incrementing of aNodeIndex in the first pass. // of its body, in order to correctly handle all cases.
bool bFirst = true; bool bIsStartNode = true;
do for (;;)
{ {
if (! bFirst) const bool bIsEndNode = aNodeIndex == End()->nNode;
{
++aNodeIndex;
}
bFirst = false;
SwTxtNode * pTxtNode = aNodeIndex.GetNode().GetTxtNode(); SwTxtNode * pTxtNode = aNodeIndex.GetNode().GetTxtNode();
if (pTxtNode != NULL) if (pTxtNode != NULL)
{ {
const OUString aTmpStr = pTxtNode->GetTxt(); const OUString aTmpStr = pTxtNode->GetTxt();
if (aNodeIndex == Start()->nNode) if (bIsStartNode || bIsEndNode)
{ {
xub_StrLen nEnd; // Handle corner cases of start/end node(s)
if (End()->nNode == aNodeIndex) const sal_Int32 nStart = bIsStartNode
nEnd = End()->nContent.GetIndex(); ? static_cast<sal_Int32>(Start()->nContent.GetIndex())
else : 0;
nEnd = aTmpStr.getLength(); const sal_Int32 nEnd = bIsEndNode
? static_cast<sal_Int32>(End()->nContent.GetIndex())
: aTmpStr.getLength();
aResult += aTmpStr.copy(Start()->nContent.GetIndex(), aResult += aTmpStr.copy(nStart, nEnd-nStart);
nEnd - Start()->nContent.GetIndex()) ;
} }
else if (aNodeIndex == End()->nNode)
aResult += aTmpStr.copy(0, End()->nContent.GetIndex());
else else
{
aResult += aTmpStr; aResult += aTmpStr;
}
} }
if (bIsEndNode)
{
break;
}
++aNodeIndex;
bIsStartNode = false;
} }
while (aNodeIndex != End()->nNode);
return aResult; return aResult;
} }