diff options
author | Matteo Casalin <matteo.casalin@yahoo.com> | 2013-06-09 12:05:10 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2013-06-16 15:45:05 +0000 |
commit | 21e43f598eb8ff7347876d8a61d7b2de29b8e7fe (patch) | |
tree | 85be63bc666fa42fc548d3124addf710e5ec9ffe | |
parent | 3d12036000f4e13127affc0cb764fc65cf89af44 (diff) |
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>
-rw-r--r-- | sw/source/core/crsr/pam.cxx | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index c1b059b724ef..9d7761dc794e 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -1066,42 +1066,44 @@ OUString SwPaM::GetTxt() const 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(); - - aResult += aTmpStr.copy(Start()->nContent.GetIndex(), - nEnd - Start()->nContent.GetIndex()) ; + // 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(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; } |