summaryrefslogtreecommitdiff
path: root/sw/source/core/text/wrong.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-07-02 15:20:42 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-07-03 08:17:26 +0200
commit09d9419bf2072fdab2d7c1d1c6a8dee70b9f0f8a (patch)
tree605387a086777705ffa8f573b3507c2e732d080b /sw/source/core/text/wrong.cxx
parent1c588317c6e55ede11c577ea16e1af85eee4810a (diff)
loplugin:useuniqueptr in SwWrongList
and simplify, just use copy constructors and operator=, instead of special-case CopyFrom methods Change-Id: I3e14fa08e820cf7ae2c5424ae22ae95516933773 Reviewed-on: https://gerrit.libreoffice.org/56831 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source/core/text/wrong.cxx')
-rw-r--r--sw/source/core/text/wrong.cxx77
1 files changed, 30 insertions, 47 deletions
diff --git a/sw/source/core/text/wrong.cxx b/sw/source/core/text/wrong.cxx
index d85cf9a99bdf..7a6893bafc46 100644
--- a/sw/source/core/text/wrong.cxx
+++ b/sw/source/core/text/wrong.cxx
@@ -24,6 +24,7 @@
#include <txtfrm.hxx>
#include <osl/diagnose.h>
+#include <o3tl/make_unique.hxx>
SwWrongArea::SwWrongArea( const OUString& rType, WrongListType listType,
css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
@@ -49,6 +50,26 @@ SwWrongArea::SwWrongArea( const OUString& rType,
}
}
+SwWrongArea::SwWrongArea( SwWrongArea const & other )
+{
+ this->operator=(other);
+}
+
+SwWrongArea & SwWrongArea::operator=( SwWrongArea const & other )
+{
+ maType = other.maType;
+ mxPropertyBag = other.mxPropertyBag;
+ mnPos = other.mnPos;
+ mnLen= other.mnLen;
+ if (other.mpSubList)
+ mpSubList = other.mpSubList->Clone();
+ else
+ mpSubList.reset();
+ mColor = other.mColor;
+ mLineType = other.mLineType;
+ return *this;
+}
+
SwWrongList::SwWrongList( WrongListType eType ) :
meType (eType),
mnBeginInvalid(COMPLETE_STRING), // everything correct... (the invalid area starts beyond the string)
@@ -57,38 +78,25 @@ SwWrongList::SwWrongList( WrongListType eType ) :
maList.reserve( 5 );
}
-SwWrongList::~SwWrongList()
+SwWrongList::SwWrongList( SwWrongList const & other ) :
+ maList(other.maList),
+ meType(other.meType),
+ mnBeginInvalid(other.mnBeginInvalid),
+ mnEndInvalid (other.mnEndInvalid)
{
- ClearList();
}
-SwWrongList* SwWrongList::Clone()
+SwWrongList::~SwWrongList()
{
- SwWrongList* pClone = new SwWrongList( meType );
- pClone->CopyFrom( *this );
- return pClone;
}
-void SwWrongList::CopyFrom( const SwWrongList& rCopy )
+std::unique_ptr<SwWrongList> SwWrongList::Clone()
{
- maList = rCopy.maList;
- meType = rCopy.meType;
- mnBeginInvalid = rCopy.mnBeginInvalid;
- mnEndInvalid = rCopy.mnEndInvalid;
- for(SwWrongArea & i : maList)
- {
- if( i.mpSubList )
- i.mpSubList = i.mpSubList->Clone();
- }
+ return o3tl::make_unique<SwWrongList>( *this );
}
void SwWrongList::ClearList()
{
- for (SwWrongArea & i : maList)
- {
- delete i.mpSubList;
- i.mpSubList = nullptr;
- }
maList.clear();
}
@@ -562,32 +570,7 @@ void SwWrongList::Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator s
void SwWrongList::Remove(sal_uInt16 nIdx, sal_uInt16 nLen )
{
- if ( nIdx >= maList.size() ) return;
- std::vector<SwWrongArea>::iterator i1 = maList.begin();
- i1 += nIdx;
-
- std::vector<SwWrongArea>::iterator i2 = i1;
- if ( nIdx + nLen >= static_cast<sal_uInt16>(maList.size()) )
- i2 = maList.end(); // robust
- else
- i2 += nLen;
-
- std::vector<SwWrongArea>::iterator iLoop = i1;
- while ( iLoop != i2 )
- {
- delete (*iLoop).mpSubList;
- ++iLoop;
- }
-
-#if OSL_DEBUG_LEVEL > 0
- const int nOldSize = Count();
-#endif
-
- maList.erase(i1, i2);
-
-#if OSL_DEBUG_LEVEL > 0
- OSL_ENSURE( Count() + nLen == nOldSize, "SwWrongList::Remove() trouble" );
-#endif
+ maList.erase(maList.begin() + nIdx, maList.begin() + nIdx + nLen);
}
void SwWrongList::RemoveEntry( sal_Int32 nBegin, sal_Int32 nEnd ) {