summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Casalin <matteo.casalin@yahoo.com>2013-12-16 22:30:41 +0100
committerMatteo Casalin <matteo.casalin@yahoo.com>2013-12-19 12:55:26 +0000
commit79932eccec436efbff41d5352c58d8ab224b0581 (patch)
tree58ebbb079a28797f3b140f8702e6dbf6e9cb716f
parentacee1b8b8c68c5c9d7492dbcc95635e68551713f (diff)
Do not expose TXTNODE_MAX and cleanup related code/comments
Change-Id: Ia114688ebbdf81122b81183456924c6b9cff835d Reviewed-on: https://gerrit.libreoffice.org/7105 Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org> Reviewed-by: Matteo Casalin <matteo.casalin@yahoo.com> Tested-by: Matteo Casalin <matteo.casalin@yahoo.com>
-rw-r--r--sw/inc/ndtxt.hxx21
-rw-r--r--sw/source/core/doc/docedt.cxx4
-rw-r--r--sw/source/core/docnode/node.cxx7
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx14
-rw-r--r--sw/source/core/txtnode/txtedt.cxx8
5 files changed, 29 insertions, 25 deletions
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index 3268232673a8..ea5982812185 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -69,10 +69,6 @@ namespace com { namespace sun { namespace star {
typedef std::set< sal_Int32 > SwSoftPageBreakList;
-// do not fill the String up to the max - need to be able to have a
-// SwPosition "behind" the last character, i.e., at index TXTNODE_MAX + 1
-static const sal_Int32 TXTNODE_MAX = SAL_MAX_INT32 - 2;
-
/// SwTxtNode is a paragraph in the document model.
class SW_DLLPUBLIC SwTxtNode: public SwCntntNode, public ::sfx2::Metadatable
{
@@ -215,6 +211,9 @@ public:
const OUString& GetTxt() const { return m_Text; }
+ // returns the maximum number of characters that can still be added to the node
+ inline sal_Int32 GetSpaceLeft() const;
+
/// getters for SwpHints
inline SwpHints &GetSwpHints();
inline const SwpHints &GetSwpHints() const;
@@ -239,8 +238,8 @@ public:
virtual sal_uInt16 ResetAllAttr();
/// insert text content
- /// @param rStr text to insert; in case it does not fit into the limit of
- /// TXTNODE_MAX, the longest prefix that fits is inserted
+ /// @param rStr text to insert; in case it does not fit into the capacity
+ /// of the node, the longest prefix that fits is inserted
/// @return the prefix of rStr that was actually inserted
OUString InsertText( const OUString & rStr, const SwIndex & rIdx,
const enum IDocumentContentOperations::InsertFlags nMode
@@ -333,7 +332,7 @@ public:
/// replace nDelLen characters at rStart with rText
/// in case the replacement does not fit, it is partially inserted up to
- /// TXTNODE_MAX
+ /// the capacity of the node
void ReplaceText( const SwIndex& rStart, const sal_Int32 nDelLen,
const OUString & rText );
void ReplaceTextOnly( sal_Int32 nPos, sal_Int32 nLen,
@@ -855,6 +854,14 @@ SwTxtNode::CutText(SwTxtNode * const pDest, const SwIndex & rDestStart,
CutImpl( pDest, rDestStart, rStart, nLen, true );
}
+inline sal_Int32 SwTxtNode::GetSpaceLeft() const
+{
+ // do not fill the String up to the max - need to be able to have a
+ // SwPosition "behind" the last character, i.e., at index TXTNODE_MAX + 1
+ const sal_Int32 TXTNODE_MAX = SAL_MAX_INT32 - 2;
+ return TXTNODE_MAX-m_Text.getLength();
+}
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index 8171500b0c6e..556f3c8d3bd5 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -713,9 +713,7 @@ bool SwDoc::Overwrite( const SwPaM &rRg, const OUString &rStr )
}
SwTxtNode *pNode = rPt.nNode.GetNode().GetTxtNode();
- if (!pNode || ( static_cast<size_t>(rStr.getLength()) // worst case: no erase
- + static_cast<size_t>(pNode->GetTxt().getLength())
- > static_cast<size_t>(TXTNODE_MAX)))
+ if (!pNode || rStr.getLength() > pNode->GetSpaceLeft()) // worst case: no erase
{
return false;
}
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index acdc7c736c49..b0519fb2a7f2 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -1646,9 +1646,10 @@ static bool lcl_CheckMaxLength(SwNode const& rPrev, SwNode const& rNext)
{
return true;
}
- size_t const nSum(static_cast<const SwTxtNode&>(rPrev).GetTxt().getLength()
- + static_cast<const SwTxtNode&>(rNext).GetTxt().getLength());
- return (nSum <= static_cast<size_t>(TXTNODE_MAX));
+
+ // Check if a node can contain the other (order is not significant)
+ return static_cast<const SwTxtNode&>(rPrev).GetSpaceLeft() >
+ static_cast<const SwTxtNode&>(rNext).Len();
}
/// Can we join two Nodes?
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index f1aea8da3159..1704fa2f2a08 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1796,10 +1796,9 @@ OUString SwTxtNode::InsertText( const OUString & rStr, const SwIndex & rIdx,
const sal_Int32 aPos = rIdx.GetIndex();
sal_Int32 nLen = m_Text.getLength() - aPos;
- sal_Int32 const nOverflow(
- m_Text.getLength() + rStr.getLength() - TXTNODE_MAX);
+ sal_Int32 const nOverflow(rStr.getLength() - GetSpaceLeft());
SAL_WARN_IF(nOverflow > 0, "sw.core",
- "SwTxtNode::InsertText: node text with insertion > TXTNODE_MAX.");
+ "SwTxtNode::InsertText: node text with insertion > capacity.");
OUString const sInserted(
(nOverflow > 0) ? rStr.copy(0, rStr.getLength() - nOverflow) : rStr);
if (sInserted.isEmpty())
@@ -1807,7 +1806,7 @@ OUString SwTxtNode::InsertText( const OUString & rStr, const SwIndex & rIdx,
return sInserted;
}
m_Text = m_Text.replaceAt(aPos, 0, sInserted);
- assert(m_Text.getLength() <= TXTNODE_MAX);
+ assert(GetSpaceLeft()>=0);
nLen = m_Text.getLength() - aPos - nLen;
assert(nLen != 0);
@@ -2088,7 +2087,7 @@ void SwTxtNode::CutImpl( SwTxtNode * const pDest, const SwIndex & rDestStart,
pDest->m_Text = pDest->m_Text.replaceAt(nDestStart, 0,
m_Text.copy(nTxtStartIdx, nLen));
m_Text = m_Text.replaceAt(nTxtStartIdx, nLen, "");
- if (m_Text.getLength() > TXTNODE_MAX)
+ if (GetSpaceLeft()<0)
{ // FIXME: could only happen when called from SwRedline::Show.
// unfortunately can't really do anything here to handle that...
abort();
@@ -3394,10 +3393,9 @@ void SwTxtNode::ReplaceText( const SwIndex& rStart, const sal_Int32 nDelLen,
assert( rStart.GetIndex() < m_Text.getLength() // index out of bounds
&& rStart.GetIndex() + nDelLen <= m_Text.getLength());
- long const nOverflow(
- m_Text.getLength() + rStr.getLength() - nDelLen - TXTNODE_MAX);
+ sal_Int32 const nOverflow(rStr.getLength() - nDelLen - GetSpaceLeft());
SAL_WARN_IF(nOverflow > 0, "sw.core",
- "SwTxtNode::ReplaceText: node text with insertion > TXTNODE_MAX.");
+ "SwTxtNode::ReplaceText: node text with insertion > node capacity.");
OUString const sInserted(
(nOverflow > 0) ? rStr.copy(0, rStr.getLength() - nOverflow) : rStr);
if (sInserted.isEmpty() && 0 == nDelLen)
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 2fba6e9e2c2b..6e94f608551d 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -1854,17 +1854,17 @@ void SwTxtNode::TransliterateText(
{
// now apply the changes from end to start to leave the offsets of the
// yet unchanged text parts remain the same.
- size_t nSum(m_Text.getLength());
+ size_t nSum(0);
for (size_t i = 0; i < aChanges.size(); ++i)
{ // check this here since AddChanges cannot be moved below
// call to ReplaceTextOnly
swTransliterationChgData & rData =
aChanges[ aChanges.size() - 1 - i ];
nSum += rData.sChanged.getLength() - rData.nLen;
- if (nSum > static_cast<size_t>(TXTNODE_MAX))
+ if (nSum > static_cast<size_t>(GetSpaceLeft()))
{
SAL_WARN("sw.core", "SwTxtNode::ReplaceTextOnly: "
- "node text with insertion > TXTNODE_MAX.");
+ "node text with insertion > node capacity.");
return;
}
if (pUndo)
@@ -1879,7 +1879,7 @@ void SwTxtNode::ReplaceTextOnly( sal_Int32 nPos, sal_Int32 nLen,
const OUString & rText,
const Sequence<sal_Int32>& rOffsets )
{
- assert(m_Text.getLength() + rText.getLength() - nLen <= TXTNODE_MAX);
+ assert(rText.getLength() - nLen <= GetSpaceLeft());
m_Text = m_Text.replaceAt(nPos, nLen, rText);