Kaydet (Commit) 79932ecc authored tarafından Matteo Casalin's avatar Matteo Casalin

Do not expose TXTNODE_MAX and cleanup related code/comments

Change-Id: Ia114688ebbdf81122b81183456924c6b9cff835d
Reviewed-on: https://gerrit.libreoffice.org/7105Tested-by: 's avatarLibreOffice gerrit bot <gerrit@libreoffice.org>
Reviewed-by: 's avatarMatteo Casalin <matteo.casalin@yahoo.com>
Tested-by: 's avatarMatteo Casalin <matteo.casalin@yahoo.com>
üst acee1b8b
......@@ -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: */
......@@ -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;
}
......
......@@ -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?
......
......@@ -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)
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment