diff options
author | mitchell <unknown> | 2020-01-05 21:22:02 -0500 |
---|---|---|
committer | mitchell <unknown> | 2020-01-05 21:22:02 -0500 |
commit | 60e87889d6438e386acf58c3967fb874af9aae82 (patch) | |
tree | 9c5c2660c59aff04ddedea19fa03fd271f8bba5c | |
parent | dbb7374c185718655dd77c294eb281e8b93c538e (diff) | |
download | scintilla-mirror-60e87889d6438e386acf58c3967fb874af9aae82.tar.gz |
Added Sci::make_unique() and Sci::size() for better compatibility with the default branch.
std::make_unique() is c++14 and std::size() is c++17.
-rwxr-xr-x | gtk/ScintillaGTK.cxx | 2 | ||||
-rw-r--r-- | include/Compat.h | 51 | ||||
-rw-r--r-- | include/Scintilla.h | 2 | ||||
-rw-r--r-- | lexers/LexHTML.cxx | 2 | ||||
-rw-r--r-- | src/CallTip.cxx | 5 | ||||
-rw-r--r-- | src/CaseConvert.cxx | 6 | ||||
-rw-r--r-- | src/CellBuffer.cxx | 6 | ||||
-rw-r--r-- | src/ContractionState.cxx | 14 | ||||
-rw-r--r-- | src/Decoration.cxx | 10 | ||||
-rw-r--r-- | src/Document.cxx | 10 | ||||
-rw-r--r-- | src/EditView.cxx | 5 | ||||
-rw-r--r-- | src/Editor.cxx | 7 | ||||
-rw-r--r-- | src/ExternalLexer.cxx | 3 | ||||
-rw-r--r-- | src/Indicator.cxx | 3 | ||||
-rw-r--r-- | src/LineMarker.cxx | 29 | ||||
-rw-r--r-- | src/Partitioning.h | 4 | ||||
-rw-r--r-- | src/PerLine.cxx | 25 | ||||
-rw-r--r-- | src/PositionCache.cxx | 18 | ||||
-rw-r--r-- | src/RunStyles.cxx | 8 | ||||
-rw-r--r-- | src/SparseVector.h | 4 | ||||
-rw-r--r-- | src/UniqueString.cxx | 4 | ||||
-rw-r--r-- | src/UniqueString.h | 2 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 2 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 13 |
24 files changed, 143 insertions, 92 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 277cb4d11..84b073ca3 100755 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -1518,7 +1518,7 @@ void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, Se const char *charSet = ::CharacterSetID(text->characterSet); if (*charSet) { std::string tmputf = ConvertText(text->Data(), text->Length(), "UTF-8", charSet, false); - converted.reset(new SelectionText()); + converted = Sci::make_unique<SelectionText>(); converted->Copy(tmputf, SC_CP_UTF8, 0, text->rectangular, false); text = converted.get(); } diff --git a/include/Compat.h b/include/Compat.h new file mode 100644 index 000000000..712ff1373 --- /dev/null +++ b/include/Compat.h @@ -0,0 +1,51 @@ +// c++11 compatibility with some c++14 features and higher. +// This helps minimize changes from the default branch. + +#ifndef COMPAT_H +#define COMPAT_H + +#ifdef __cplusplus + +#include <cstddef> +#include <memory> +#include <type_traits> +#include <utility> + +namespace Sci { + +// std::make_unique +template<class T> struct _Unique_if { + typedef std::unique_ptr<T> _Single_object; +}; +template<class T> struct _Unique_if<T[]> { + typedef std::unique_ptr<T[]> _Unknown_bound; +}; +template<class T, size_t N> struct _Unique_if<T[N]> { + typedef void _Known_bound; +}; +template<class T, class... Args> + typename _Unique_if<T>::_Single_object + make_unique(Args&&... args) { + return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); + } +template<class T> + typename _Unique_if<T>::_Unknown_bound + make_unique(size_t n) { + typedef typename std::remove_extent<T>::type U; + return std::unique_ptr<T>(new U[n]()); + } +template<class T, class... Args> + typename _Unique_if<T>::_Known_bound + make_unique(Args&&...) = delete; + +// std::size +template <typename T, size_t N> +constexpr size_t size(const T (&)[N]) noexcept { + return N; +} + +} + +#endif + +#endif
\ No newline at end of file diff --git a/include/Scintilla.h b/include/Scintilla.h index db25b4f17..c2ea775b2 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -1266,4 +1266,6 @@ struct SCNotification { #endif +#include "Compat.h" + #endif diff --git a/lexers/LexHTML.cxx b/lexers/LexHTML.cxx index 24e9215da..9d474fb0e 100644 --- a/lexers/LexHTML.cxx +++ b/lexers/LexHTML.cxx @@ -866,7 +866,7 @@ public: isXml_ ? "xml" : (isPHPScript_ ? "phpscript" : "hypertext"), isXml_ ? SCLEX_XML : (isPHPScript_ ? SCLEX_PHPSCRIPT : SCLEX_HTML), isXml_ ? lexicalClassesHTML : lexicalClassesXML, - isXml_ ? ELEMENTS(lexicalClassesHTML) : ELEMENTS(lexicalClassesXML)), + isXml_ ? Sci::size(lexicalClassesHTML) : Sci::size(lexicalClassesXML)), isXml(isXml_), isPHPScript(isPHPScript_), osHTML(isPHPScript_), diff --git a/src/CallTip.cxx b/src/CallTip.cxx index 18c4549bb..db66878ce 100644 --- a/src/CallTip.cxx +++ b/src/CallTip.cxx @@ -21,7 +21,6 @@ #include "Scintilla.h" -#include "StringCopy.h" #include "Position.h" #include "IntegerRectangle.h" #include "CallTip.h" @@ -135,14 +134,14 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s, Point::FromInts(centreX + halfWidth, centreY + quarterWidth), Point::FromInts(centreX, centreY - halfWidth + quarterWidth), }; - surface->Polygon(pts, ELEMENTS(pts), colourBG, colourBG); + surface->Polygon(pts, Sci::size(pts), colourBG, colourBG); } else { // Down arrow Point pts[] = { Point::FromInts(centreX - halfWidth, centreY - quarterWidth), Point::FromInts(centreX + halfWidth, centreY - quarterWidth), Point::FromInts(centreX, centreY + halfWidth - quarterWidth), }; - surface->Polygon(pts, ELEMENTS(pts), colourBG, colourBG); + surface->Polygon(pts, Sci::size(pts), colourBG, colourBG); } } offsetMain = xEnd; diff --git a/src/CaseConvert.cxx b/src/CaseConvert.cxx index ed94a67f1..dd8a25aa1 100644 --- a/src/CaseConvert.cxx +++ b/src/CaseConvert.cxx @@ -19,6 +19,8 @@ #include "CaseConvert.h" #include "UniConversion.h" +#include "Compat.h" + using namespace Scintilla; namespace { @@ -692,7 +694,7 @@ void AddSymmetric(enum CaseConversion conversion, int lower,int upper) { void SetupConversions(enum CaseConversion conversion) { // First initialize for the symmetric ranges - for (size_t i=0; i<ELEMENTS(symmetricCaseConversionRanges);) { + for (size_t i=0; i<Sci::size(symmetricCaseConversionRanges);) { const int lower = symmetricCaseConversionRanges[i++]; const int upper = symmetricCaseConversionRanges[i++]; const int length = symmetricCaseConversionRanges[i++]; @@ -702,7 +704,7 @@ void SetupConversions(enum CaseConversion conversion) { } } // Add the symmetric singletons - for (size_t i=0; i<ELEMENTS(symmetricCaseConversions);) { + for (size_t i=0; i<Sci::size(symmetricCaseConversions);) { const int lower = symmetricCaseConversions[i++]; const int upper = symmetricCaseConversions[i++]; AddSymmetric(conversion, lower, upper); diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 3257e0e6b..0bfe74b52 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -282,7 +282,7 @@ void Action::Create(actionType at_, Sci::Position position_, const char *data_, position = position_; at = at_; if (lenData_) { - data = std::unique_ptr<char []>(new char[lenData_]); + data = Sci::make_unique<char[]>(lenData_); memcpy(&data[0], data_, lenData_); } lenData = lenData_; @@ -534,9 +534,9 @@ CellBuffer::CellBuffer(bool hasStyles_, bool largeDocument_) : utf8LineEnds = 0; collectingUndo = true; if (largeDocument) - plv = std::unique_ptr<LineVector<Sci::Position>>(new LineVector<Sci::Position>()); + plv = Sci::make_unique<LineVector<Sci::Position>>(); else - plv = std::unique_ptr<LineVector<int>>(new LineVector<int>()); + plv = Sci::make_unique<LineVector<int>>(); } CellBuffer::~CellBuffer() { diff --git a/src/ContractionState.cxx b/src/ContractionState.cxx index ebbf9aefe..8d2427629 100644 --- a/src/ContractionState.cxx +++ b/src/ContractionState.cxx @@ -100,11 +100,11 @@ ContractionState<LINE>::~ContractionState() { template <typename LINE> void ContractionState<LINE>::EnsureData() { if (OneToOne()) { - visible = std::unique_ptr<RunStyles<LINE, char>>(new RunStyles<LINE, char>()); - expanded = std::unique_ptr<RunStyles<LINE, char>>(new RunStyles<LINE, char>()); - heights = std::unique_ptr<RunStyles<LINE, int>>(new RunStyles<LINE, int>()); - foldDisplayTexts = std::unique_ptr<SparseVector<UniqueString>>(new SparseVector<UniqueString>()); - displayLines = std::unique_ptr<Partitioning<LINE>>(new Partitioning<LINE>(4)); + visible = Sci::make_unique<RunStyles<LINE, char>>(); + expanded = Sci::make_unique<RunStyles<LINE, char>>(); + heights = Sci::make_unique<RunStyles<LINE, int>>(); + foldDisplayTexts = Sci::make_unique<SparseVector<UniqueString>>(); + displayLines = Sci::make_unique<Partitioning<LINE>>(4); InsertLines(0, linesInDocument); } } @@ -412,9 +412,9 @@ namespace Scintilla { std::unique_ptr<IContractionState> ContractionStateCreate(bool largeDocument) { if (largeDocument) - return std::unique_ptr<ContractionState<Sci::Line>>(new ContractionState<Sci::Line>()); + return Sci::make_unique<ContractionState<Sci::Line>>(); else - return std::unique_ptr<ContractionState<int>>(new ContractionState<int>()); + return Sci::make_unique<ContractionState<int>>(); } } diff --git a/src/Decoration.cxx b/src/Decoration.cxx index 8d60d8935..813e988d0 100644 --- a/src/Decoration.cxx +++ b/src/Decoration.cxx @@ -143,7 +143,7 @@ Decoration<POS> *DecorationList<POS>::DecorationFromIndicator(int indicator) { template <typename POS> Decoration<POS> *DecorationList<POS>::Create(int indicator, Sci::Position length) { currentIndicator = indicator; - std::unique_ptr<Decoration<POS>> decoNew = std::unique_ptr<Decoration<POS>>(new Decoration<POS>(indicator)); + std::unique_ptr<Decoration<POS>> decoNew = Sci::make_unique<Decoration<POS>>(indicator); decoNew->rs.InsertSpace(0, static_cast<POS>(length)); typename std::vector<std::unique_ptr<Decoration<POS>>>::iterator it = std::lower_bound( @@ -300,16 +300,16 @@ namespace Scintilla { std::unique_ptr<IDecoration> DecorationCreate(bool largeDocument, int indicator) { if (largeDocument) - return std::unique_ptr<Decoration<Sci::Position>>(new Decoration<Sci::Position>(indicator)); + return Sci::make_unique<Decoration<Sci::Position>>(indicator); else - return std::unique_ptr<Decoration<int>>(new Decoration<int>(indicator)); + return Sci::make_unique<Decoration<int>>(indicator); } std::unique_ptr<IDecorationList> DecorationListCreate(bool largeDocument) { if (largeDocument) - return std::unique_ptr<DecorationList<Sci::Position>>(new DecorationList<Sci::Position>()); + return Sci::make_unique<DecorationList<Sci::Position>>(); else - return std::unique_ptr<DecorationList<int>>(new DecorationList<int>()); + return Sci::make_unique<DecorationList<int>>(); } } diff --git a/src/Document.cxx b/src/Document.cxx index 43751a716..b889a7d9b 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -135,11 +135,11 @@ Document::Document(int options) : matchesValid = false; - perLineData[ldMarkers].reset(new LineMarkers()); - perLineData[ldLevels].reset(new LineLevels()); - perLineData[ldState].reset(new LineState()); - perLineData[ldMargin].reset(new LineAnnotation()); - perLineData[ldAnnotation].reset(new LineAnnotation()); + perLineData[ldMarkers] = Sci::make_unique<LineMarkers>(); + perLineData[ldLevels] = Sci::make_unique<LineLevels>(); + perLineData[ldState] = Sci::make_unique<LineState>(); + perLineData[ldMargin] = Sci::make_unique<LineAnnotation>(); + perLineData[ldAnnotation] = Sci::make_unique<LineAnnotation>(); decorations = DecorationListCreate(IsLarge()); diff --git a/src/EditView.cxx b/src/EditView.cxx index c16f25ac6..3ae7a5d67 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -28,7 +28,6 @@ #include "ILexer.h" #include "Scintilla.h" -#include "StringCopy.h" #include "CharacterSet.h" #include "CharacterCategory.h" #include "Position.h" @@ -229,7 +228,7 @@ bool EditView::ClearTabstops(Sci::Line line) { bool EditView::AddTabstop(Sci::Line line, int x) { if (!ldTabstops) { - ldTabstops.reset(new LineTabstops()); + ldTabstops = Sci::make_unique<LineTabstops>(); } return ldTabstops && ldTabstops->AddTabstop(line, x); } @@ -287,7 +286,7 @@ static const char *ControlCharacterString(unsigned char ch) noexcept { "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" }; - if (ch < ELEMENTS(reps)) { + if (ch < Sci::size(reps)) { return reps[ch]; } else { return "BAD"; diff --git a/src/Editor.cxx b/src/Editor.cxx index f8dd2ccad..aec983f00 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -28,7 +28,6 @@ #include "ILexer.h" #include "Scintilla.h" -#include "StringCopy.h" #include "CharacterSet.h" #include "CharacterCategory.h" #include "Position.h" @@ -218,7 +217,7 @@ void Editor::SetRepresentations() { "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" }; - for (size_t j=0; j < ELEMENTS(reps); j++) { + for (size_t j=0; j < Sci::size(reps); j++) { const char c[2] = { static_cast<char>(j), 0 }; reprs.SetRepresentation(c, reps[j]); } @@ -232,7 +231,7 @@ void Editor::SetRepresentations() { "DCS", "PU1", "PU2", "STS", "CCH", "MW", "SPA", "EPA", "SOS", "SGCI", "SCI", "CSI", "ST", "OSC", "PM", "APC" }; - for (size_t j=0; j < ELEMENTS(repsC1); j++) { + for (size_t j=0; j < Sci::size(repsC1); j++) { const char c1[3] = { '\xc2', static_cast<char>(0x80+j), 0 }; reprs.SetRepresentation(c1, repsC1[j]); } @@ -1989,7 +1988,7 @@ void Editor::InsertCharacter(const char *s, unsigned int len, CharacterSource ch // characters representing themselves. } else { unsigned int utf32[1] = { 0 }; - UTF32FromUTF8(s, len, utf32, ELEMENTS(utf32)); + UTF32FromUTF8(s, len, utf32, Sci::size(utf32)); ch = utf32[0]; } } diff --git a/src/ExternalLexer.cxx b/src/ExternalLexer.cxx index c6a505007..acb18339d 100644 --- a/src/ExternalLexer.cxx +++ b/src/ExternalLexer.cxx @@ -191,8 +191,7 @@ void LexerManager::Load(const char *path) { if (ll->moduleName == path) return; } - LexerLibrary *lib = new LexerLibrary(path); - libraries.push_back(std::unique_ptr<LexerLibrary>(lib)); + libraries.push_back(Sci::make_unique<LexerLibrary>(path)); } void LexerManager::Clear() noexcept { diff --git a/src/Indicator.cxx b/src/Indicator.cxx index 5b1259fb4..1d594d214 100644 --- a/src/Indicator.cxx +++ b/src/Indicator.cxx @@ -16,7 +16,6 @@ #include "Platform.h" #include "Scintilla.h" -#include "StringCopy.h" #include "IntegerRectangle.h" #include "Indicator.h" #include "XPM.h" @@ -210,7 +209,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r Point(ix + pixelHeight, iy + pixelHeight), // Right Point(ix, iy) // Top }; - surface->Polygon(pts, ELEMENTS(pts), sacDraw.fore, sacDraw.fore); + surface->Polygon(pts, Sci::size(pts), sacDraw.fore, sacDraw.fore); } } else { // Either INDIC_PLAIN or unknown surface->MoveTo(irc.left, ymid); diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx index d2c906d08..e026e4a17 100644 --- a/src/LineMarker.cxx +++ b/src/LineMarker.cxx @@ -18,7 +18,6 @@ #include "Scintilla.h" -#include "StringCopy.h" #include "IntegerRectangle.h" #include "XPM.h" #include "LineMarker.h" @@ -33,11 +32,11 @@ LineMarker::LineMarker(const LineMarker &other) { backSelected = other.backSelected; alpha = other.alpha; if (other.pxpm) - pxpm.reset(new XPM(*other.pxpm)); + pxpm = Sci::make_unique<XPM>(*other.pxpm); else pxpm = nullptr; if (other.image) - image.reset(new RGBAImage(*other.image)); + image = Sci::make_unique<RGBAImage>(*other.image); else image = nullptr; customDraw = other.customDraw; @@ -52,11 +51,11 @@ LineMarker &LineMarker::operator=(const LineMarker &other) { backSelected = other.backSelected; alpha = other.alpha; if (other.pxpm) - pxpm.reset(new XPM(*other.pxpm)); + pxpm = Sci::make_unique<XPM>(*other.pxpm); else pxpm = nullptr; if (other.image) - image.reset(new RGBAImage(*other.image)); + image = Sci::make_unique<RGBAImage>(*other.image); else image = nullptr; customDraw = other.customDraw; @@ -65,17 +64,17 @@ LineMarker &LineMarker::operator=(const LineMarker &other) { } void LineMarker::SetXPM(const char *textForm) { - pxpm.reset(new XPM(textForm)); + pxpm = Sci::make_unique<XPM>(textForm); markType = SC_MARK_PIXMAP; } void LineMarker::SetXPM(const char *const *linesForm) { - pxpm.reset(new XPM(linesForm)); + pxpm = Sci::make_unique<XPM>(linesForm); markType = SC_MARK_PIXMAP; } void LineMarker::SetRGBAImage(Point sizeRGBAImage, float scale, const unsigned char *pixelsRGBAImage) { - image.reset(new RGBAImage(static_cast<int>(sizeRGBAImage.x), static_cast<int>(sizeRGBAImage.y), scale, pixelsRGBAImage)); + image = Sci::make_unique<RGBAImage>(static_cast<int>(sizeRGBAImage.x), static_cast<int>(sizeRGBAImage.y), scale, pixelsRGBAImage); markType = SC_MARK_RGBAIMAGE; } @@ -185,7 +184,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX - dimOn4, centreY + dimOn2), Point::FromInts(centreX + dimOn2 - dimOn4, centreY), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_ARROWDOWN) { Point pts[] = { @@ -193,7 +192,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX + dimOn2, centreY - dimOn4), Point::FromInts(centreX, centreY + dimOn2 - dimOn4), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_PLUS) { Point pts[] = { @@ -210,7 +209,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX - 1, centreY + 1), Point::FromInts(centreX - armSize, centreY + 1), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_MINUS) { Point pts[] = { @@ -219,7 +218,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX + armSize, centreY +1), Point::FromInts(centreX - armSize, centreY + 1), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_SMALLRECT) { PRectangle rcSmall; @@ -415,7 +414,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX, centreY + dimOn4), Point::FromInts(centreX, centreY + dimOn2), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_LEFTRECT) { PRectangle rcLeft = rcWhole; rcLeft.right = rcLeft.left + 4; @@ -429,7 +428,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(ircWhole.right - 3, centreY + halfHeight), Point::FromInts(ircWhole.left, centreY + halfHeight), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else if (markType == SC_MARK_VERTICALBOOKMARK) { const int halfWidth = minDim / 3; Point pts[] = { @@ -439,7 +438,7 @@ void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharac Point::FromInts(centreX, centreY + dimOn2 - halfWidth), Point::FromInts(centreX - halfWidth, centreY + dimOn2), }; - surface->Polygon(pts, ELEMENTS(pts), fore, back); + surface->Polygon(pts, Sci::size(pts), fore, back); } else { // SC_MARK_FULLRECT surface->FillRectangle(rcWhole, back); } diff --git a/src/Partitioning.h b/src/Partitioning.h index 06dc88ade..bb3320b80 100644 --- a/src/Partitioning.h +++ b/src/Partitioning.h @@ -8,6 +8,8 @@ #ifndef PARTITIONING_H #define PARTITIONING_H +#include "Compat.h" + namespace Scintilla { /// A split vector of integers with a method for adding a value to all elements @@ -85,7 +87,7 @@ private: } void Allocate(ptrdiff_t growSize) { - body.reset(new SplitVectorWithRangeAdd<T>(growSize)); + body = Sci::make_unique<SplitVectorWithRangeAdd<T>>(growSize); stepPartition = 0; stepLength = 0; body->Insert(0, 0); // This value stays 0 for ever diff --git a/src/PerLine.cxx b/src/PerLine.cxx index d81f46d3b..e67426ae7 100644 --- a/src/PerLine.cxx +++ b/src/PerLine.cxx @@ -118,7 +118,7 @@ Sci::Line LineMarkers::LineFromHandle(int markerHandle) { void LineMarkers::MergeMarkers(Sci::Line line) { if (markers[line + 1]) { if (!markers[line]) - markers[line].reset(new MarkerHandleSet); + markers[line] = Sci::make_unique<MarkerHandleSet>(); markers[line]->CombineWith(markers[line + 1].get()); markers[line + 1].reset(); } @@ -154,7 +154,7 @@ int LineMarkers::AddMark(Sci::Line line, int markerNum, Sci::Line lines) { } if (!markers[line]) { // Need new structure to hold marker handle - markers[line].reset(new MarkerHandleSet()); + markers[line] = Sci::make_unique<MarkerHandleSet>(); } markers[line]->InsertHandle(handleCurrent, markerNum); @@ -357,17 +357,16 @@ const unsigned char *LineAnnotation::Styles(Sci::Line line) const { return nullptr; } -static char *AllocateAnnotation(int length, int style) { +static std::unique_ptr<char[]>AllocateAnnotation(int length, int style) { const size_t len = sizeof(AnnotationHeader) + length + ((style == IndividualStyles) ? length : 0); - char *ret = new char[len](); - return ret; + return Sci::make_unique<char[]>(len); } void LineAnnotation::SetText(Sci::Line line, const char *text) { if (text && (line >= 0)) { annotations.EnsureLength(line+1); const int style = Style(line); - annotations[line].reset(AllocateAnnotation(static_cast<int>(strlen(text)), style)); + annotations[line] = AllocateAnnotation(static_cast<int>(strlen(text)), style); char *pa = annotations[line].get(); assert(pa); AnnotationHeader *pah = reinterpret_cast<AnnotationHeader *>(pa); @@ -389,7 +388,7 @@ void LineAnnotation::ClearAll() { void LineAnnotation::SetStyle(Sci::Line line, int style) { annotations.EnsureLength(line+1); if (!annotations[line]) { - annotations[line].reset(AllocateAnnotation(0, style)); + annotations[line] = AllocateAnnotation(0, style); } reinterpret_cast<AnnotationHeader *>(annotations[line].get())->style = static_cast<short>(style); } @@ -398,16 +397,16 @@ void LineAnnotation::SetStyles(Sci::Line line, const unsigned char *styles) { if (line >= 0) { annotations.EnsureLength(line+1); if (!annotations[line]) { - annotations[line].reset(AllocateAnnotation(0, IndividualStyles)); + annotations[line] = AllocateAnnotation(0, IndividualStyles); } else { const AnnotationHeader *pahSource = reinterpret_cast<AnnotationHeader *>(annotations[line].get()); if (pahSource->style != IndividualStyles) { - char *allocation = AllocateAnnotation(pahSource->length, IndividualStyles); - AnnotationHeader *pahAlloc = reinterpret_cast<AnnotationHeader *>(allocation); + std::unique_ptr<char[]>allocation = AllocateAnnotation(pahSource->length, IndividualStyles); + AnnotationHeader *pahAlloc = reinterpret_cast<AnnotationHeader *>(allocation.get()); pahAlloc->length = pahSource->length; pahAlloc->lines = pahSource->lines; - memcpy(allocation + sizeof(AnnotationHeader), annotations[line].get() + sizeof(AnnotationHeader), pahSource->length); - annotations[line].reset(allocation); + memcpy(allocation.get() + sizeof(AnnotationHeader), annotations[line].get() + sizeof(AnnotationHeader), pahSource->length); + annotations[line] = std::move(allocation); } } AnnotationHeader *pah = reinterpret_cast<AnnotationHeader *>(annotations[line].get()); @@ -465,7 +464,7 @@ bool LineTabstops::ClearTabstops(Sci::Line line) { bool LineTabstops::AddTabstop(Sci::Line line, int x) { tabstops.EnsureLength(line + 1); if (!tabstops[line]) { - tabstops[line].reset(new TabstopList()); + tabstops[line] = Sci::make_unique<TabstopList>(); } TabstopList *tl = tabstops[line].get(); diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index a1f71fdae..5a6d8dac0 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -74,11 +74,11 @@ LineLayout::~LineLayout() { void LineLayout::Resize(int maxLineLength_) { if (maxLineLength_ > maxLineLength) { Free(); - chars.reset(new char[maxLineLength_ + 1]); - styles.reset(new unsigned char[maxLineLength_ + 1]); + chars = Sci::make_unique<char[]>(maxLineLength_ + 1); + styles = Sci::make_unique<unsigned char []>(maxLineLength_ + 1); // Extra position allocated as sometimes the Windows // GetTextExtentExPoint API writes an extra element. - positions.reset(new XYPOSITION[maxLineLength_ + 1 + 1]); + positions = Sci::make_unique<XYPOSITION []>(maxLineLength_ + 1 + 1); maxLineLength = maxLineLength_; } } @@ -126,15 +126,15 @@ bool LineLayout::InLine(int offset, int line) const { void LineLayout::SetLineStart(int line, int start) { if ((line >= lenLineStarts) && (line != 0)) { - int newMaxLines = line + 20; - int *newLineStarts = new int[newMaxLines]; + const int newMaxLines = line + 20; + std::unique_ptr<int[]> newLineStarts = Sci::make_unique<int[]>(newMaxLines); for (int i = 0; i < newMaxLines; i++) { if (i < lenLineStarts) newLineStarts[i] = lineStarts[i]; else newLineStarts[i] = 0; } - lineStarts.reset(newLineStarts); + lineStarts = std::move(newLineStarts); lenLineStarts = newMaxLines; } lineStarts[line] = start; @@ -341,7 +341,7 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret, } } if (!cache[pos]) { - cache[pos].reset(new LineLayout(maxChars)); + cache[pos] = Sci::make_unique<LineLayout>(maxChars); } cache[pos]->lineNumber = lineNumber; cache[pos]->inCache = true; @@ -570,7 +570,7 @@ PositionCacheEntry::PositionCacheEntry(const PositionCacheEntry &other) : styleNumber(other.styleNumber), len(other.styleNumber), clock(other.styleNumber), positions(nullptr) { if (other.positions) { const size_t lenData = len + (len / sizeof(XYPOSITION)) + 1; - positions.reset(new XYPOSITION[lenData]); + positions = Sci::make_unique<XYPOSITION[]>(lenData); memcpy(positions.get(), other.positions.get(), lenData * sizeof(XYPOSITION)); } } @@ -582,7 +582,7 @@ void PositionCacheEntry::Set(unsigned int styleNumber_, const char *s_, len = len_; clock = clock_; if (s_ && positions_) { - positions.reset(new XYPOSITION[len + (len / sizeof(XYPOSITION)) + 1]); + positions = Sci::make_unique<XYPOSITION[]>(len + (len / sizeof(XYPOSITION)) + 1); for (unsigned int i=0; i<len; i++) { positions[i] = positions_[i]; } diff --git a/src/RunStyles.cxx b/src/RunStyles.cxx index 115f51a9a..da000e69d 100644 --- a/src/RunStyles.cxx +++ b/src/RunStyles.cxx @@ -78,8 +78,8 @@ void RunStyles<DISTANCE, STYLE>::RemoveRunIfSameAsPrevious(DISTANCE run) { template <typename DISTANCE, typename STYLE> RunStyles<DISTANCE, STYLE>::RunStyles() { - starts.reset(new Partitioning<DISTANCE>(8)); - styles.reset(new SplitVector<STYLE>()); + starts = Sci::make_unique<Partitioning<DISTANCE>>(8); + styles = Sci::make_unique<SplitVector<STYLE>>(); styles->InsertValue(0, 2, 0); } @@ -215,8 +215,8 @@ void RunStyles<DISTANCE, STYLE>::InsertSpace(DISTANCE position, DISTANCE insertL template <typename DISTANCE, typename STYLE> void RunStyles<DISTANCE, STYLE>::DeleteAll() { - starts.reset(new Partitioning<DISTANCE>(8)); - styles.reset(new SplitVector<STYLE>()); + starts = Sci::make_unique<Partitioning<DISTANCE>>(8); + styles = Sci::make_unique<SplitVector<STYLE>>(); styles->InsertValue(0, 2, 0); } diff --git a/src/SparseVector.h b/src/SparseVector.h index e508f63da..e6f59e9dc 100644 --- a/src/SparseVector.h +++ b/src/SparseVector.h @@ -27,8 +27,8 @@ private: } public: SparseVector() : empty() { - starts = std::unique_ptr<Partitioning<Sci::Position>>(new Partitioning<Sci::Position>(8)); - values = std::unique_ptr<SplitVector<T>>(new SplitVector<T>()); + starts = Sci::make_unique<Partitioning<Sci::Position>>(8); + values = Sci::make_unique<SplitVector<T>>(); values->InsertEmpty(0, 2); } // Deleted so SparseVector objects can not be copied. diff --git a/src/UniqueString.cxx b/src/UniqueString.cxx index cacc0a7d8..c4d616a10 100644 --- a/src/UniqueString.cxx +++ b/src/UniqueString.cxx @@ -21,8 +21,8 @@ UniqueString UniqueStringCopy(const char *text) { return UniqueString(); } const size_t len = strlen(text); - std::unique_ptr<char[]> upcNew(new char[len + 1]); - memcpy(&upcNew[0], text, len + 1); + std::unique_ptr<char[]> upcNew = Sci::make_unique<char[]>(len + 1); + memcpy(upcNew.get(), text, len + 1); return UniqueString(upcNew.release()); } diff --git a/src/UniqueString.h b/src/UniqueString.h index 442d17c79..18f17029f 100644 --- a/src/UniqueString.h +++ b/src/UniqueString.h @@ -11,6 +11,8 @@ #ifndef UNIQUESTRING_H #define UNIQUESTRING_H +#include "Compat.h" + namespace Scintilla { constexpr bool IsNullOrEmpty(const char *text) noexcept { diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index ec6d8e52c..6ec980af4 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -582,7 +582,7 @@ void ViewStyle::CreateAndAddFont(const FontSpecification &fs) { if (fs.fontName) { FontMap::iterator it = fonts.find(fs); if (it == fonts.end()) { - fonts[fs] = std::unique_ptr<FontRealised>(new FontRealised()); + fonts[fs] = Sci::make_unique<FontRealised>(); } } } diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 2e62a62ca..dbb83d9f6 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -52,7 +52,6 @@ #include "ILexer.h" #include "Scintilla.h" -#include "StringCopy.h" #include "CharacterCategory.h" #include "Position.h" #include "UniqueString.h" @@ -2098,7 +2097,7 @@ public: wchar_t wFolded[20]; const size_t charsConverted = UTF16FromUTF8(foldedUTF8, strlen(foldedUTF8), - wFolded, ELEMENTS(wFolded)); + wFolded, Sci::size(wFolded)); for (size_t j=0; j<charsConverted; j++) utf16Folded[lenFlat++] = wFolded[j]; } else { @@ -2136,19 +2135,19 @@ CaseFolder *ScintillaWin::CaseFolderForEncoding() { sCharacter[0] = static_cast<char>(i); wchar_t wCharacter[20]; const unsigned int lengthUTF16 = ::MultiByteToWideChar(cpDest, 0, sCharacter, 1, - wCharacter, ELEMENTS(wCharacter)); + wCharacter, Sci::size(wCharacter)); if (lengthUTF16 == 1) { const char *caseFolded = CaseConvert(wCharacter[0], CaseConversionFold); if (caseFolded) { wchar_t wLower[20]; const size_t charsConverted = UTF16FromUTF8(caseFolded, strlen(caseFolded), - wLower, ELEMENTS(wLower)); + wLower, Sci::size(wLower)); if (charsConverted == 1) { char sCharacterLowered[20]; const unsigned int lengthConverted = ::WideCharToMultiByte(cpDest, 0, wLower, static_cast<int>(charsConverted), - sCharacterLowered, ELEMENTS(sCharacterLowered), NULL, 0); + sCharacterLowered, Sci::size(sCharacterLowered), NULL, 0); if ((lengthConverted == 1) && (sCharacter[0] != sCharacterLowered[0])) { pcf->SetTranslation(sCharacter[0], sCharacterLowered[0]); } @@ -2578,10 +2577,10 @@ STDMETHODIMP DataObject_EnumFormatEtc(DataObject *pd, DWORD dwDirection, IEnumFO FormatEnumerator *pfe; if (pd->sci->IsUnicodeMode()) { CLIPFORMAT formats[] = {CF_UNICODETEXT, CF_TEXT}; - pfe = new FormatEnumerator(0, formats, ELEMENTS(formats)); + pfe = new FormatEnumerator(0, formats, Sci::size(formats)); } else { CLIPFORMAT formats[] = {CF_TEXT}; - pfe = new FormatEnumerator(0, formats, ELEMENTS(formats)); + pfe = new FormatEnumerator(0, formats, Sci::size(formats)); } return FormatEnumerator_QueryInterface(pfe, IID_IEnumFORMATETC, reinterpret_cast<void **>(ppEnum)); |