diff options
| author | Neil <nyamatongwe@gmail.com> | 2018-04-20 13:35:24 +1000 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2018-04-20 13:35:24 +1000 | 
| commit | 9aa7e7b0559cbf2b4d6d298fe2d546eb5a5a956e (patch) | |
| tree | b650fd03941bbae83cd6739dc7f020dcf62162d9 /src | |
| parent | f81ae988af0acf5ffb503845f2354b18c411ddca (diff) | |
| download | scintilla-mirror-9aa7e7b0559cbf2b4d6d298fe2d546eb5a5a956e.tar.gz | |
More const and cast avoidance.
Diffstat (limited to 'src')
| -rw-r--r-- | src/EditView.cxx | 11 | ||||
| -rw-r--r-- | src/Editor.cxx | 20 | ||||
| -rw-r--r-- | src/Editor.h | 2 | 
3 files changed, 17 insertions, 16 deletions
| diff --git a/src/EditView.cxx b/src/EditView.cxx index addcaf1f3..8522ba419 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -19,6 +19,7 @@  #include <map>  #include <forward_list>  #include <algorithm> +#include <iterator>  #include <memory>  #include "Platform.h" @@ -86,9 +87,9 @@ static int WidthStyledText(Surface *surface, const ViewStyle &vs, int styleOffse  	int width = 0;  	size_t start = 0;  	while (start < len) { -		const size_t style = styles[start]; +		const unsigned char style = styles[start];  		size_t endSegment = start; -		while ((endSegment + 1 < len) && (static_cast<size_t>(styles[endSegment + 1]) == style)) +		while ((endSegment + 1 < len) && (styles[endSegment + 1] == style))  			endSegment++;  		FontAlias fontText = vs.styles[style + styleOffset].font;  		width += static_cast<int>(surface->WidthText(fontText, text + start, @@ -280,13 +281,13 @@ void EditView::AllocateGraphics(const ViewStyle &vsDraw) {  }  static const char *ControlCharacterString(unsigned char ch) { -	const char *reps[] = { +	const char * const reps[] = {  		"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",  		"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",  		"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",  		"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"  	}; -	if (ch < ELEMENTS(reps)) { +	if (ch < std::size(reps)) {  		return reps[ch];  	} else {  		return "BAD"; @@ -913,7 +914,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle  			rcSegment.left = xStart + ll->positions[eolPos] - static_cast<XYPOSITION>(subLineStart)+virtualSpace;  			rcSegment.right = xStart + ll->positions[eolPos + 1] - static_cast<XYPOSITION>(subLineStart)+virtualSpace;  			blobsWidth += rcSegment.Width(); -			char hexits[4]; +			char hexits[4] = "";  			const char *ctrlChar;  			const unsigned char chEOL = ll->chars[eolPos];  			const int styleMain = ll->styles[eolPos]; diff --git a/src/Editor.cxx b/src/Editor.cxx index a2cd99770..730c47d00 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -19,6 +19,7 @@  #include <map>  #include <forward_list>  #include <algorithm> +#include <iterator>  #include <memory>  #include "Platform.h" @@ -28,6 +29,7 @@  #include "Scintilla.h"  #include "StringCopy.h" +#include "CharacterSet.h"  #include "Position.h"  #include "UniqueString.h"  #include "SplitVector.h" @@ -204,13 +206,13 @@ void Editor::SetRepresentations() {  	reprs.Clear();  	// C0 control set -	const char *reps[] = { +	const char * const reps[] = {  		"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",  		"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",  		"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 < std::size(reps); j++) {  		const char c[2] = { static_cast<char>(j), 0 };  		reprs.SetRepresentation(c, reps[j]);  	} @@ -218,13 +220,13 @@ void Editor::SetRepresentations() {  	// C1 control set  	// As well as Unicode mode, ISO-8859-1 should use these  	if (IsUnicodeMode()) { -		const char *repsC1[] = { +		const char * const repsC1[] = {  			"PAD", "HOP", "BPH", "NBH", "IND", "NEL", "SSA", "ESA",  			"HTS", "HTJ", "VTS", "PLD", "PLU", "RI", "SS2", "SS3",  			"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 < std::size(repsC1); j++) {  			const char c1[3] = { '\xc2',  static_cast<char>(0x80+j), 0 };  			reprs.SetRepresentation(c1, repsC1[j]);  		} @@ -1632,7 +1634,7 @@ void Editor::LinesSplit(int pixelWidth) {  	}  } -void Editor::PaintSelMargin(Surface *surfaceWindow, PRectangle &rc) { +void Editor::PaintSelMargin(Surface *surfaceWindow, const PRectangle &rc) {  	if (vs.fixedColumnWidth == 0)  		return; @@ -2612,7 +2614,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) {  		if (mh.modificationType & SC_MOD_CHANGEANNOTATION) {  			const Sci::Line lineDoc = pdoc->SciLineFromPosition(mh.position);  			if (vs.annotationVisible) { -				if (pcs->SetHeight(lineDoc, static_cast<int>(pcs->GetHeight(lineDoc) + mh.annotationLinesAdded))) { +				if (pcs->SetHeight(lineDoc, pcs->GetHeight(lineDoc) + static_cast<int>(mh.annotationLinesAdded))) {  					SetScrollBars();  				}  				Redraw(); @@ -4092,12 +4094,10 @@ std::string Editor::CaseMapString(const std::string &s, int caseMapping) {  	for (char &ch : ret) {  		switch (caseMapping) {  			case cmUpper: -				if (ch >= 'a' && ch <= 'z') -					ch = static_cast<char>(ch - 'a' + 'A'); +				ch = MakeUpperCase(ch);  				break;  			case cmLower: -				if (ch >= 'A' && ch <= 'Z') -					ch = static_cast<char>(ch - 'A' + 'a'); +				ch = MakeLowerCase(ch);  				break;  		}  	} diff --git a/src/Editor.h b/src/Editor.h index 7e763d7db..defb5aea7 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -375,7 +375,7 @@ protected:	// ScintillaBase subclass needs access to much of Editor  	void LinesJoin();  	void LinesSplit(int pixelWidth); -	void PaintSelMargin(Surface *surfaceWindow, PRectangle &rc); +	void PaintSelMargin(Surface *surfaceWindow, const PRectangle &rc);  	void RefreshPixMaps(Surface *surfaceWindow);  	void Paint(Surface *surfaceWindow, PRectangle rcArea);  	Sci::Position FormatRange(bool draw, const Sci_RangeToFormat *pfr); | 
