diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/EditView.cxx | 26 | ||||
| -rw-r--r-- | src/Editor.cxx | 24 | ||||
| -rw-r--r-- | src/Editor.h | 2 | ||||
| -rw-r--r-- | src/PositionCache.cxx | 13 | ||||
| -rw-r--r-- | src/PositionCache.h | 15 | ||||
| -rw-r--r-- | src/XPM.cxx | 6 | ||||
| -rw-r--r-- | src/XPM.h | 8 | 
7 files changed, 49 insertions, 45 deletions
| diff --git a/src/EditView.cxx b/src/EditView.cxx index 76edf1c68..5b58d367a 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -59,7 +59,7 @@  using namespace Scintilla; -static inline bool IsControlCharacter(int ch) { +static constexpr bool IsControlCharacter(int ch) noexcept {  	// iscntrl returns true for lots of chars > 127 which are displayable  	return ch >= 0 && ch < ' ';  } @@ -95,7 +95,7 @@ static int WidthStyledText(Surface *surface, const ViewStyle &vs, int styleOffse  		while ((endSegment + 1 < len) && (styles[endSegment + 1] == style))  			endSegment++;  		FontAlias fontText = vs.styles[style + styleOffset].font; -		std::string_view sv(text + start, endSegment - start + 1); +		const std::string_view sv(text + start, endSegment - start + 1);  		width += static_cast<int>(surface->WidthText(fontText, sv));  		start = endSegment + 1;  	} @@ -112,7 +112,7 @@ int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, cons  			widthSubLine = WidthStyledText(surface, vs, styleOffset, st.text + start, st.styles + start, lenLine);  		} else {  			FontAlias fontText = vs.styles[styleOffset + st.style].font; -			std::string_view text(st.text + start, lenLine); +			const std::string_view text(st.text + start, lenLine);  			widthSubLine = static_cast<int>(surface->WidthText(fontText, text));  		}  		if (widthSubLine > widthMax) @@ -151,7 +151,7 @@ void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRec  				end++;  			style += styleOffset;  			FontAlias fontText = vs.styles[style].font; -			std::string_view text(st.text + start + i, end - i + 1); +			const std::string_view text(st.text + start + i, end - i + 1);  			const int width = static_cast<int>(surface->WidthText(fontText, text));  			PRectangle rcSegment = rcText;  			rcSegment.left = static_cast<XYPOSITION>(x); @@ -457,7 +457,7 @@ void EditView::LayoutLine(const EditModel &model, Sci::Line line, Surface *surfa  		ll->positions[0] = 0;  		bool lastSegItalics = false; -		BreakFinder bfLayout(ll, NULL, Range(0, numCharsInLine), posLineStart, 0, false, model.pdoc, &model.reprs, NULL); +		BreakFinder bfLayout(ll, nullptr, Range(0, numCharsInLine), posLineStart, 0, false, model.pdoc, &model.reprs, nullptr);  		while (bfLayout.More()) {  			const TextSegment ts = bfLayout.Next(); @@ -931,7 +931,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle  		const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth;  		virtualSpace = model.sel.VirtualSpaceFor(model.pdoc->LineEnd(line)) * spaceWidth;  	} -	XYPOSITION xEol = static_cast<XYPOSITION>(ll->positions[lineEnd] - subLineStart); +	const XYPOSITION xEol = static_cast<XYPOSITION>(ll->positions[lineEnd] - subLineStart);  	// Fill the virtual space and show selections within it  	if (virtualSpace > 0.0f) { @@ -1273,7 +1273,7 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con  	}  } -static bool AnnotationBoxedOrIndented(int annotationVisible) { +static constexpr bool AnnotationBoxedOrIndented(int annotationVisible) noexcept {  	return annotationVisible == ANNOTATION_BOXED || annotationVisible == ANNOTATION_INDENTED;  } @@ -1395,7 +1395,7 @@ static void DrawBlockCaret(Surface *surface, const EditModel &model, const ViewS  	// (inversed) for drawing the caret here.  	const int styleMain = ll->styles[offsetFirstChar];  	FontAlias fontText = vsDraw.styles[styleMain].font; -	std::string_view text(&ll->chars[offsetFirstChar], numCharsToDraw); +	const std::string_view text(&ll->chars[offsetFirstChar], numCharsToDraw);  	surface->DrawTextClipped(rcCaret, fontText,  		rcCaret.top + vsDraw.maxAscent, text, vsDraw.styles[styleMain].back,  		caretColour); @@ -1547,7 +1547,7 @@ void EditView::DrawBackground(Surface *surface, const EditModel &model, const Vi  	// Does not take margin into account but not significant  	const int xStartVisible = static_cast<int>(subLineStart)-xStart; -	BreakFinder bfBack(ll, &model.sel, lineRange, posLineStart, xStartVisible, selBackDrawn, model.pdoc, &model.reprs, NULL); +	BreakFinder bfBack(ll, &model.sel, lineRange, posLineStart, xStartVisible, selBackDrawn, model.pdoc, &model.reprs, nullptr);  	const bool drawWhitespaceBackground = vsDraw.WhitespaceBackgroundDrawn() && !background.isSet; @@ -1859,7 +1859,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi  			} else {  				// Normal text display  				if (vsDraw.styles[styleMain].visible) { -					std::string_view text(&ll->chars[ts.start], i - ts.start + 1); +					const std::string_view text(&ll->chars[ts.start], i - ts.start + 1);  					if (phasesDraw != phasesOne) {  						surface->DrawTextTransparent(rcSegment, textFont,  							rcSegment.top + vsDraw.maxAscent, text, textFore); @@ -2143,7 +2143,7 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan  			(vsDraw.braceBadLightIndicatorSet && (model.bracesMatchStyle == STYLE_BRACEBAD)));  		Sci::Line lineDocPrevious = -1;	// Used to avoid laying out one document line multiple times -		AutoLineLayout ll(llc, 0); +		AutoLineLayout ll(llc, nullptr);  		std::vector<DrawPhase> phases;  		if ((phasesDraw == phasesMultiple) && !bufferedDraw) {  			for (DrawPhase phase = drawBack; phase <= drawCarets; phase = static_cast<DrawPhase>(phase * 2)) { @@ -2172,7 +2172,7 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan  				ElapsedPeriod ep;  #endif  				if (lineDoc != lineDocPrevious) { -					ll.Set(0); +					ll.Set(nullptr);  					ll.Set(RetrieveLineLayout(lineDoc, model));  					LayoutLine(model, lineDoc, surface, vsDraw, ll, model.wrapWidth);  					lineDocPrevious = lineDoc; @@ -2246,7 +2246,7 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan  				visibleLine++;  			}  		} -		ll.Set(0); +		ll.Set(nullptr);  #if defined(TIME_PAINTING)  		if (durPaint < 0.00000001)  			durPaint = 0.00000001; diff --git a/src/Editor.cxx b/src/Editor.cxx index 9e81a2ef3..86c0536a1 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -245,7 +245,7 @@ void Editor::SetRepresentations() {  	} else if (pdoc->dbcsCodePage) {  		// DBCS invalid single lead bytes  		for (int k = 0x80; k < 0x100; k++) { -			char ch = static_cast<char>(k); +			const char ch = static_cast<char>(k);  			if (pdoc->IsDBCSLeadByteNoExcept(ch)  || pdoc->IsDBCSLeadByteInvalid(ch)) {  				const char hiByte[2] = { ch, 0 };  				char hexits[5];	// Really only needs 4 but that causes warning from gcc 7.1 @@ -2284,7 +2284,7 @@ void Editor::DelCharBack(bool allowLineStartDeletion) {  	ShowCaretAtCurrentPosition();  } -int Editor::ModifierFlags(bool shift, bool ctrl, bool alt, bool meta, bool super) { +int Editor::ModifierFlags(bool shift, bool ctrl, bool alt, bool meta, bool super) noexcept {  	return  		(shift ? SCI_SHIFT : 0) |  		(ctrl ? SCI_CTRL : 0) | @@ -3210,11 +3210,11 @@ Sci::Position Editor::StartEndDisplayLine(Sci::Position pos, bool start) {  namespace { -short HighShortFromLong(long x) { +constexpr short HighShortFromWParam(uptr_t x) {  	return static_cast<short>(x >> 16);  } -short LowShortFromLong(long x) { +constexpr short LowShortFromWParam(uptr_t x) {  	return static_cast<short>(x & 0xffff);  } @@ -4072,7 +4072,7 @@ Sci::Position Editor::SearchText(      sptr_t lParam) {			///< The text to search for.  	const char *txt = CharPtrFromSPtr(lParam); -	Sci::Position pos; +	Sci::Position pos = INVALID_POSITION;  	Sci::Position lengthFound = strlen(txt);  	if (!pdoc->HasCaseFolder())  		pdoc->SetCaseFolder(CaseFolderForEncoding()); @@ -4088,9 +4088,9 @@ Sci::Position Editor::SearchText(  		}  	} catch (RegexError &) {  		errorStatus = SC_STATUS_WARN_REGEX; -		return -1; +		return INVALID_POSITION;  	} -	if (pos != -1) { +	if (pos != INVALID_POSITION) {  		SetSelection(pos, pos + lengthFound);  	} @@ -4463,7 +4463,7 @@ void Editor::MouseLeave() {  	}  } -static bool AllowVirtualSpace(int virtualSpaceOptions, bool rectangular) { +static constexpr bool AllowVirtualSpace(int virtualSpaceOptions, bool rectangular) noexcept {  	return (!rectangular && ((virtualSpaceOptions & SCVS_USERACCESSIBLE) != 0))  		|| (rectangular && ((virtualSpaceOptions & SCVS_RECTANGULARSELECTION) != 0));  } @@ -7276,13 +7276,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {  		return vs.caretWidth;  	case SCI_ASSIGNCMDKEY: -		kmap.AssignCmdKey(LowShortFromLong(static_cast<long>(wParam)), -			HighShortFromLong(static_cast<long>(wParam)), static_cast<unsigned int>(lParam)); +		kmap.AssignCmdKey(LowShortFromWParam(wParam), +			HighShortFromWParam(wParam), static_cast<unsigned int>(lParam));  		break;  	case SCI_CLEARCMDKEY: -		kmap.AssignCmdKey(LowShortFromLong(static_cast<long>(wParam)), -			HighShortFromLong(static_cast<long>(wParam)), SCI_NULL); +		kmap.AssignCmdKey(LowShortFromWParam(wParam), +			HighShortFromWParam(wParam), SCI_NULL);  		break;  	case SCI_CLEARALLCMDKEYS: diff --git a/src/Editor.h b/src/Editor.h index 3c21ee092..fb892bdcb 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -412,7 +412,7 @@ protected:	// ScintillaBase subclass needs access to much of Editor  	void DelCharBack(bool allowLineStartDeletion);  	virtual void ClaimSelection() = 0; -	static int ModifierFlags(bool shift, bool ctrl, bool alt, bool meta=false, bool super=false); +	static int ModifierFlags(bool shift, bool ctrl, bool alt, bool meta=false, bool super=false) noexcept;  	virtual void NotifyChange() = 0;  	virtual void NotifyFocus(bool focus);  	virtual void SetCtrlID(int identifier); diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index b218c39e0..44f9caa0c 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -63,12 +63,11 @@ LineLayout::LineLayout(int maxLineLength_) :  	highlightColumn(false),  	containsCaret(false),  	edgeColumn(0), +	bracePreviousStyles{},  	hotspot(0,0),  	widthLine(wrapWidthInfinite),  	lines(1),  	wrapIndent(0) { -	bracePreviousStyles[0] = 0; -	bracePreviousStyles[1] = 0;  	Resize(maxLineLength_);  } @@ -422,7 +421,7 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret,  	}  	allInvalidated = false;  	Sci::Position pos = -1; -	LineLayout *ret = 0; +	LineLayout *ret = nullptr;  	if (level == llcCaret) {  		pos = 0;  	} else if (level == llcPage) { @@ -512,12 +511,12 @@ const Representation *SpecialRepresentations::RepresentationFromCharacter(const  	PLATFORM_ASSERT(len <= 4);  	const unsigned char ucStart = charBytes[0];  	if (!startByteHasReprs[ucStart]) -		return 0; +		return nullptr;  	MapRepresentation::const_iterator it = mapReprs.find(KeyFromString(charBytes, len));  	if (it != mapReprs.end()) {  		return &(it->second);  	} -	return 0; +	return nullptr;  }  bool SpecialRepresentations::Contains(const char *charBytes, size_t len) const { @@ -536,7 +535,7 @@ void SpecialRepresentations::Clear() {  }  void BreakFinder::Insert(Sci::Position val) { -	int posInLine = static_cast<int>(val); +	const int posInLine = static_cast<int>(val);  	if (posInLine > nextBreak) {  		const std::vector<int>::iterator it = std::lower_bound(selAndEdge.begin(), selAndEdge.end(), posInLine);  		if (it == selAndEdge.end()) { @@ -626,7 +625,7 @@ TextSegment BreakFinder::Next() {  					if (nextBreak == prev) {  						nextBreak += charWidth;  					} else { -						repr = 0;	// Optimize -> should remember repr +						repr = nullptr;	// Optimize -> should remember repr  					}  					if ((nextBreak - prev) < lengthStartSubdivision) {  						return TextSegment(prev, nextBreak - prev, repr); diff --git a/src/PositionCache.h b/src/PositionCache.h index 512ec13f5..5657b667c 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -10,10 +10,14 @@  namespace Scintilla { -static inline bool IsEOLChar(char ch) { +inline constexpr bool IsEOLChar(int ch) noexcept {  	return (ch == '\r') || (ch == '\n');  } +inline constexpr bool IsSpaceOrTab(int ch) noexcept { +	return ch == ' ' || ch == '\t'; +} +  /**  * A point in document space.  * Uses double for sufficient resolution in large (>20,000,000 line) documents. @@ -122,6 +126,11 @@ struct ScreenLine : public IScreenLine {  	int tabWidthMinimumPixels;  	ScreenLine(const LineLayout *ll_, int subLine, const ViewStyle &vs, XYPOSITION width_, int tabWidthMinimumPixels_); +	// Deleted so ScreenLine objects can not be copied. +	ScreenLine(const ScreenLine &) = delete; +	ScreenLine(ScreenLine &&) = delete; +	void operator=(const ScreenLine &) = delete; +	void operator=(ScreenLine &&) = delete;  	virtual ~ScreenLine();  	std::string_view Text() const override; @@ -274,10 +283,6 @@ public:  		const char *s, unsigned int len, XYPOSITION *positions, const Document *pdoc);  }; -inline bool IsSpaceOrTab(int ch) { -	return ch == ' ' || ch == '\t'; -} -  }  #endif diff --git a/src/XPM.cxx b/src/XPM.cxx index 0d4a2a068..5df3ea7c9 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -58,9 +58,9 @@ unsigned int ValueOfHex(const char ch) noexcept {  }  ColourDesired ColourFromHex(const char *val) noexcept { -	unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]); -	unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]); -	unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]); +	const unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]); +	const unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]); +	const unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]);  	return ColourDesired(r, g, b);  } @@ -14,12 +14,12 @@ namespace Scintilla {   * Hold a pixmap in XPM format.   */  class XPM { -	int height; -	int width; -	int nColours; +	int height=1; +	int width=1; +	int nColours=1;  	std::vector<unsigned char> pixels;  	ColourDesired colourCodeTable[256]; -	char codeTransparent; +	char codeTransparent=' ';  	ColourDesired ColourFromCode(int ch) const;  	void FillRun(Surface *surface, int code, int startX, int y, int x) const;  public: | 
