diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CellBuffer.cxx | 26 | ||||
| -rw-r--r-- | src/CellBuffer.h | 14 | ||||
| -rw-r--r-- | src/DBCS.cxx | 2 | ||||
| -rw-r--r-- | src/DBCS.h | 2 | ||||
| -rw-r--r-- | src/Document.cxx | 165 | ||||
| -rw-r--r-- | src/Document.h | 19 | ||||
| -rw-r--r-- | src/Partitioning.h | 6 | ||||
| -rw-r--r-- | src/PositionCache.cxx | 2 | ||||
| -rw-r--r-- | src/SplitVector.h | 8 | ||||
| -rw-r--r-- | src/UniConversion.cxx | 6 | ||||
| -rw-r--r-- | src/UniConversion.h | 20 | 
11 files changed, 150 insertions, 120 deletions
| diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 177aa60e8..58ab3b3f4 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -35,9 +35,9 @@ public:  	virtual void InsertLine(Sci::Line line, Sci::Position position, bool lineStart) = 0;  	virtual void SetLineStart(Sci::Line line, Sci::Position position) = 0;  	virtual void RemoveLine(Sci::Line line) = 0; -	virtual Sci::Line Lines() const = 0; -	virtual Sci::Line LineFromPosition(Sci::Position pos) const = 0; -	virtual Sci::Position LineStart(Sci::Line line) const = 0; +	virtual Sci::Line Lines() const noexcept = 0; +	virtual Sci::Line LineFromPosition(Sci::Position pos) const noexcept = 0; +	virtual Sci::Position LineStart(Sci::Line line) const noexcept = 0;  	virtual ~ILineVector() {}  }; @@ -84,13 +84,13 @@ public:  			perLine->RemoveLine(line);  		}  	} -	Sci::Line Lines() const override { +	Sci::Line Lines() const noexcept override {  		return static_cast<Sci::Line>(starts.Partitions());  	} -	Sci::Line LineFromPosition(Sci::Position pos) const override { +	Sci::Line LineFromPosition(Sci::Position pos) const noexcept override {  		return static_cast<Sci::Line>(starts.PartitionFromPosition(static_cast<POS>(pos)));  	} -	Sci::Position LineStart(Sci::Line line) const override { +	Sci::Position LineStart(Sci::Line line) const noexcept override {  		return starts.PositionFromPartition(static_cast<POS>(line));  	}  }; @@ -377,11 +377,11 @@ CellBuffer::CellBuffer(bool hasStyles_, bool largeDocument_) :  CellBuffer::~CellBuffer() {  } -char CellBuffer::CharAt(Sci::Position position) const { +char CellBuffer::CharAt(Sci::Position position) const noexcept {  	return substance.ValueAt(position);  } -unsigned char CellBuffer::UCharAt(Sci::Position position) const { +unsigned char CellBuffer::UCharAt(Sci::Position position) const noexcept {  	return static_cast<unsigned char>(substance.ValueAt(position));  } @@ -398,7 +398,7 @@ void CellBuffer::GetCharRange(char *buffer, Sci::Position position, Sci::Positio  	substance.GetRange(buffer, position, lengthRetrieve);  } -char CellBuffer::StyleAt(Sci::Position position) const { +char CellBuffer::StyleAt(Sci::Position position) const noexcept {  	return hasStyles ? style.ValueAt(position) : 0;  } @@ -496,7 +496,7 @@ const char *CellBuffer::DeleteChars(Sci::Position position, Sci::Position delete  	return data;  } -Sci::Position CellBuffer::Length() const { +Sci::Position CellBuffer::Length() const noexcept {  	return substance.Length();  } @@ -537,11 +537,11 @@ void CellBuffer::SetPerLine(PerLine *pl) {  	plv->SetPerLine(pl);  } -Sci::Line CellBuffer::Lines() const { +Sci::Line CellBuffer::Lines() const noexcept {  	return plv->Lines();  } -Sci::Position CellBuffer::LineStart(Sci::Line line) const { +Sci::Position CellBuffer::LineStart(Sci::Line line) const noexcept {  	if (line < 0)  		return 0;  	else if (line >= Lines()) @@ -550,7 +550,7 @@ Sci::Position CellBuffer::LineStart(Sci::Line line) const {  		return plv->LineStart(line);  } -Sci::Line CellBuffer::LineFromPosition(Sci::Position pos) const { +Sci::Line CellBuffer::LineFromPosition(Sci::Position pos) const noexcept {  	return plv->LineFromPosition(pos);  } diff --git a/src/CellBuffer.h b/src/CellBuffer.h index 065c73795..20e81def6 100644 --- a/src/CellBuffer.h +++ b/src/CellBuffer.h @@ -134,24 +134,24 @@ public:  	~CellBuffer();  	/// Retrieving positions outside the range of the buffer works and returns 0 -	char CharAt(Sci::Position position) const; -	unsigned char UCharAt(Sci::Position position) const; +	char CharAt(Sci::Position position) const noexcept; +	unsigned char UCharAt(Sci::Position position) const noexcept;  	void GetCharRange(char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const; -	char StyleAt(Sci::Position position) const; +	char StyleAt(Sci::Position position) const noexcept;  	void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const;  	const char *BufferPointer();  	const char *RangePointer(Sci::Position position, Sci::Position rangeLength);  	Sci::Position GapPosition() const; -	Sci::Position Length() const; +	Sci::Position Length() const noexcept;  	void Allocate(Sci::Position newSize);  	int GetLineEndTypes() const { return utf8LineEnds; }  	void SetLineEndTypes(int utf8LineEnds_);  	bool ContainsLineEnd(const char *s, Sci::Position length) const;  	void SetPerLine(PerLine *pl); -	Sci::Line Lines() const; -	Sci::Position LineStart(Sci::Line line) const; -	Sci::Line LineFromPosition(Sci::Position pos) const; +	Sci::Line Lines() const noexcept; +	Sci::Position LineStart(Sci::Line line) const noexcept; +	Sci::Line LineFromPosition(Sci::Position pos) const noexcept;  	void InsertLine(Sci::Line line, Sci::Position position, bool lineStart);  	void RemoveLine(Sci::Line line);  	const char *InsertString(Sci::Position position, const char *s, Sci::Position insertLength, bool &startSequence); diff --git a/src/DBCS.cxx b/src/DBCS.cxx index 0fb7ef0af..644cad04d 100644 --- a/src/DBCS.cxx +++ b/src/DBCS.cxx @@ -11,7 +11,7 @@ using namespace Scintilla;  namespace Scintilla { -bool DBCSIsLeadByte(int codePage, char ch) { +bool DBCSIsLeadByte(int codePage, char ch) noexcept {  	// Byte ranges found in Wikipedia articles with relevant search strings in each case  	const unsigned char uch = static_cast<unsigned char>(ch);  	switch (codePage) { diff --git a/src/DBCS.h b/src/DBCS.h index 531437f45..ff3f9f22f 100644 --- a/src/DBCS.h +++ b/src/DBCS.h @@ -10,7 +10,7 @@  namespace Scintilla { -bool DBCSIsLeadByte(int codePage, char ch); +bool DBCSIsLeadByte(int codePage, char ch) noexcept;  } diff --git a/src/Document.cxx b/src/Document.cxx index b0efee5e7..127b6872a 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -387,7 +387,7 @@ Sci_Position SCI_METHOD Document::LineFromPosition(Sci_Position pos) const {  	return cb.LineFromPosition(pos);  } -Sci::Line Document::SciLineFromPosition(Sci::Position pos) const { +Sci::Line Document::SciLineFromPosition(Sci::Position pos) const noexcept {  	// Avoids casting in callers for this very common function  	return cb.LineFromPosition(pos);  } @@ -582,13 +582,13 @@ int Document::LenChar(Sci::Position pos) {  		else  			return widthCharBytes;  	} else if (dbcsCodePage) { -		return IsDBCSLeadByte(cb.CharAt(pos)) ? 2 : 1; +		return IsDBCSLeadByteNoExcept(cb.CharAt(pos)) ? 2 : 1;  	} else {  		return 1;  	}  } -bool Document::InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position &end) const { +bool Document::InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position &end) const noexcept {  	Sci::Position trail = pos;  	while ((trail>0) && (pos-trail < UTF8MaxBytes) && UTF8IsTrailByte(cb.UCharAt(trail-1)))  		trail--; @@ -661,12 +661,12 @@ Sci::Position Document::MovePositionOutsideChar(Sci::Position pos, Sci::Position  			// Step back until a non-lead-byte is found.  			Sci::Position posCheck = pos; -			while ((posCheck > posStartLine) && IsDBCSLeadByte(cb.CharAt(posCheck-1))) +			while ((posCheck > posStartLine) && IsDBCSLeadByteNoExcept(cb.CharAt(posCheck-1)))  				posCheck--;  			// Check from known start of character.  			while (posCheck < pos) { -				const int mbsize = IsDBCSLeadByte(cb.CharAt(posCheck)) ? 2 : 1; +				const int mbsize = IsDBCSLeadByteNoExcept(cb.CharAt(posCheck)) ? 2 : 1;  				if (posCheck + mbsize == pos) {  					return pos;  				} else if (posCheck + mbsize > pos) { @@ -687,13 +687,13 @@ Sci::Position Document::MovePositionOutsideChar(Sci::Position pos, Sci::Position  // NextPosition moves between valid positions - it can not handle a position in the middle of a  // multi-byte character. It is used to iterate through text more efficiently than MovePositionOutsideChar.  // A \r\n pair is treated as two characters. -Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const { +Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const noexcept {  	// If out of range, just return minimum/maximum value.  	const int increment = (moveDir > 0) ? 1 : -1;  	if (pos + increment <= 0)  		return 0; -	if (pos + increment >= Length()) -		return Length(); +	if (pos + increment >= cb.Length()) +		return cb.Length();  	if (dbcsCodePage) {  		if (SC_CP_UTF8 == dbcsCodePage) { @@ -731,25 +731,25 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const {  			}  		} else {  			if (moveDir > 0) { -				const int mbsize = IsDBCSLeadByte(cb.CharAt(pos)) ? 2 : 1; +				const int mbsize = IsDBCSLeadByteNoExcept(cb.CharAt(pos)) ? 2 : 1;  				pos += mbsize; -				if (pos > Length()) -					pos = Length(); +				if (pos > cb.Length()) +					pos = cb.Length();  			} else {  				// Anchor DBCS calculations at start of line because start of line can  				// not be a DBCS trail byte. -				const Sci::Position posStartLine = LineStart(LineFromPosition(pos)); +				const Sci::Position posStartLine = cb.LineStart(cb.LineFromPosition(pos));  				// See http://msdn.microsoft.com/en-us/library/cc194792%28v=MSDN.10%29.aspx  				// http://msdn.microsoft.com/en-us/library/cc194790.aspx  				if ((pos - 1) <= posStartLine) {  					return pos - 1; -				} else if (IsDBCSLeadByte(cb.CharAt(pos - 1))) { +				} else if (IsDBCSLeadByteNoExcept(cb.CharAt(pos - 1))) {  					// Must actually be trail byte  					return pos - 2;  				} else {  					// Otherwise, step back until a non-lead-byte is found.  					Sci::Position posTemp = pos - 1; -					while (posStartLine <= --posTemp && IsDBCSLeadByte(cb.CharAt(posTemp))) +					while (posStartLine <= --posTemp && IsDBCSLeadByteNoExcept(cb.CharAt(posTemp)))  						;  					// Now posTemp+1 must point to the beginning of a character,  					// so figure out whether we went back an even or an odd @@ -765,7 +765,7 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const {  	return pos;  } -bool Document::NextCharacter(Sci::Position &pos, int moveDir) const { +bool Document::NextCharacter(Sci::Position &pos, int moveDir) const noexcept {  	// Returns true if pos changed  	Sci::Position posNext = NextPosition(pos, moveDir);  	if (posNext == pos) { @@ -798,7 +798,7 @@ Document::CharacterExtracted Document::CharacterAfter(Sci::Position position) co  			return CharacterExtracted(UnicodeFromUTF8(charBytes), utf8status & UTF8MaskWidth);  		}  	} else { -		if (IsDBCSLeadByte(leadByte) && ((position + 1) < Length())) { +		if (IsDBCSLeadByteNoExcept(leadByte) && ((position + 1) < Length())) {  			return CharacterExtracted::DBCS(leadByte, cb.UCharAt(position + 1));  		} else {  			return CharacterExtracted(leadByte, 1); @@ -912,7 +912,7 @@ int SCI_METHOD Document::GetCharacterAndWidth(Sci_Position position, Sci_Positio  				}  			}  		} else { -			if (IsDBCSLeadByte(leadByte)) { +			if (IsDBCSLeadByteNoExcept(leadByte)) {  				bytesInCharacter = 2;  				character = (leadByte << 8) | cb.UCharAt(position+1);  			} else { @@ -933,6 +933,12 @@ int SCI_METHOD Document::CodePage() const {  }  bool SCI_METHOD Document::IsDBCSLeadByte(char ch) const { +	// Used by lexers so must match IDocument method exactly +	return IsDBCSLeadByteNoExcept(ch); +} + +bool Document::IsDBCSLeadByteNoExcept(char ch) const noexcept { +	// Used inside core Scintilla  	// Byte ranges found in Wikipedia articles with relevant search strings in each case  	const unsigned char uch = static_cast<unsigned char>(ch);  	switch (dbcsCodePage) { @@ -960,7 +966,7 @@ bool SCI_METHOD Document::IsDBCSLeadByte(char ch) const {  	return false;  } -static inline bool IsSpaceOrTab(int ch) { +static inline bool IsSpaceOrTab(int ch) noexcept {  	return ch == ' ' || ch == '\t';  } @@ -996,7 +1002,7 @@ int Document::SafeSegment(const char *text, int length, int lengthSegment) const  		if (dbcsCodePage == SC_CP_UTF8) {  			j += UTF8BytesOfLead[ch];  		} else if (dbcsCodePage) { -			j += IsDBCSLeadByte(ch) ? 2 : 1; +			j += IsDBCSLeadByteNoExcept(ch) ? 2 : 1;  		} else {  			j++;  		} @@ -1306,7 +1312,7 @@ void Document::DelCharBack(Sci::Position pos) {  	}  } -static Sci::Position NextTab(Sci::Position pos, Sci::Position tabSize) { +static Sci::Position NextTab(Sci::Position pos, Sci::Position tabSize) noexcept {  	return ((pos / tabSize) + 1) * tabSize;  } @@ -1818,7 +1824,7 @@ void Document::SetCaseFolder(CaseFolder *pcf_) {  	pcf.reset(pcf_);  } -Document::CharacterExtracted Document::ExtractCharacter(Sci::Position position) const { +Document::CharacterExtracted Document::ExtractCharacter(Sci::Position position) const noexcept {  	const unsigned char leadByte = cb.UCharAt(position);  	if (UTF8IsAscii(leadByte)) {  		// Common case: ASCII character @@ -1894,8 +1900,8 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con  			std::vector<char> searchThing((lengthFind+1) * UTF8MaxBytes * maxFoldingExpansion + 1);  			const size_t lenSearch =  				pcf->Fold(&searchThing[0], searchThing.size(), search, lengthFind); -			char bytes[UTF8MaxBytes + 1]; -			char folded[UTF8MaxBytes * maxFoldingExpansion + 1]; +			char bytes[UTF8MaxBytes + 1] = ""; +			char folded[UTF8MaxBytes * maxFoldingExpansion + 1] = "";  			while (forward ? (pos < endPos) : (pos >= endPos)) {  				int widthFirstCharacter = 0;  				Sci::Position posIndexDocument = pos; @@ -1955,7 +1961,7 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con  					(indexSearch < lenSearch)) {  					char bytes[maxBytesCharacter + 1];  					bytes[0] = cb.CharAt(pos + indexDocument); -					const Sci::Position widthChar = IsDBCSLeadByte(bytes[0]) ? 2 : 1; +					const Sci::Position widthChar = IsDBCSLeadByteNoExcept(bytes[0]) ? 2 : 1;  					if (widthChar == 2)  						bytes[1] = cb.CharAt(pos + indexDocument + 1);  					if ((pos + indexDocument + widthChar) > limitPos) @@ -2295,7 +2301,7 @@ void Document::NotifyModified(DocModification mh) {  }  // Used for word part navigation. -static bool IsASCIIPunctuationCharacter(unsigned int ch) { +static bool IsASCIIPunctuationCharacter(unsigned int ch) noexcept {  	switch (ch) {  	case '!':  	case '"': @@ -2429,7 +2435,7 @@ Sci::Position Document::WordPartRight(Sci::Position pos) const {  	return pos;  } -static bool IsLineEndChar(char c) { +static bool IsLineEndChar(char c) noexcept {  	return (c == '\n' || c == '\r');  } @@ -2446,7 +2452,7 @@ Sci::Position Document::ExtendStyleRange(Sci::Position pos, int delta, bool sing  	return pos;  } -static char BraceOpposite(char ch) { +static char BraceOpposite(char ch) noexcept {  	switch (ch) {  	case '(':  		return ')'; @@ -2506,9 +2512,11 @@ Sci::Position Document::BraceMatch(Sci::Position position, Sci::Position /*maxRe  class BuiltinRegex : public RegexSearchBase {  public:  	explicit BuiltinRegex(CharClassify *charClassTable) : search(charClassTable) {} - -	~BuiltinRegex() override { -	} +	BuiltinRegex(const BuiltinRegex &) = delete; +	BuiltinRegex(BuiltinRegex &&) = delete; +	BuiltinRegex &operator=(const BuiltinRegex &) = delete; +	BuiltinRegex &operator=(BuiltinRegex &&) = delete; +	~BuiltinRegex() override = default;  	Sci::Position FindText(Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *s,                          bool caseSensitive, bool word, bool wordStart, int flags, @@ -2569,14 +2577,18 @@ class DocumentIndexer : public CharacterIndexer {  	Document *pdoc;  	Sci::Position end;  public: -	DocumentIndexer(Document *pdoc_, Sci::Position end_) : +	DocumentIndexer(Document *pdoc_, Sci::Position end_) noexcept :  		pdoc(pdoc_), end(end_) {  	} -	~DocumentIndexer() override { -	} +	DocumentIndexer(const DocumentIndexer &) = delete; +	DocumentIndexer(DocumentIndexer &&) = delete; +	DocumentIndexer &operator=(const DocumentIndexer &) = delete; +	DocumentIndexer &operator=(DocumentIndexer &&) = delete; -	char CharAt(Sci::Position index) const override { +	~DocumentIndexer() override = default; + +	char CharAt(Sci::Position index) const noexcept override {  		if (index < 0 || index >= end)  			return 0;  		else @@ -2596,45 +2608,53 @@ public:  	const Document *doc;  	Sci::Position position; -	ByteIterator(const Document *doc_ = 0, Sci::Position position_ = 0) : doc(doc_), position(position_) { + +	ByteIterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept :  +		doc(doc_), position(position_) {  	}  	ByteIterator(const ByteIterator &other) noexcept {  		doc = other.doc;  		position = other.position;  	} -	ByteIterator &operator=(const ByteIterator &other) { +	ByteIterator(ByteIterator &&other) noexcept { +		doc = other.doc; +		position = other.position; +	} +	ByteIterator &operator=(const ByteIterator &other) noexcept {  		if (this != &other) {  			doc = other.doc;  			position = other.position;  		}  		return *this;  	} -	char operator*() const { +	ByteIterator &operator=(ByteIterator &&) noexcept = default; +	~ByteIterator() = default; +	char operator*() const noexcept {  		return doc->CharAt(position);  	} -	ByteIterator &operator++() { +	ByteIterator &operator++() noexcept {  		position++;  		return *this;  	} -	ByteIterator operator++(int) { +	ByteIterator operator++(int) noexcept {  		ByteIterator retVal(*this);  		position++;  		return retVal;  	} -	ByteIterator &operator--() { +	ByteIterator &operator--() noexcept {  		position--;  		return *this;  	} -	bool operator==(const ByteIterator &other) const { +	bool operator==(const ByteIterator &other) const noexcept {  		return doc == other.doc && position == other.position;  	} -	bool operator!=(const ByteIterator &other) const { +	bool operator!=(const ByteIterator &other) const noexcept {  		return doc != other.doc || position != other.position;  	} -	Sci::Position Pos() const { +	Sci::Position Pos() const noexcept {  		return position;  	} -	Sci::Position PosRoundUp() const { +	Sci::Position PosRoundUp() const noexcept {  		return position;  	}  }; @@ -2671,15 +2691,15 @@ public:  	typedef wchar_t* pointer;  	typedef wchar_t& reference; -	UTF8Iterator(const Document *doc_ = 0, Sci::Position position_ = 0) : -		doc(doc_), position(position_), characterIndex(0), lenBytes(0), lenCharacters(0) { +	UTF8Iterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept : +		doc(doc_), position(position_), characterIndex(0), lenBytes(0), lenCharacters(0), buffered{} {  		buffered[0] = 0;  		buffered[1] = 0;  		if (doc) {  			ReadCharacter();  		}  	} -	UTF8Iterator(const UTF8Iterator &other) { +	UTF8Iterator(const UTF8Iterator &other) noexcept : buffered{} {  		doc = other.doc;  		position = other.position;  		characterIndex = other.characterIndex; @@ -2688,7 +2708,8 @@ public:  		buffered[0] = other.buffered[0];  		buffered[1] = other.buffered[1];  	} -	UTF8Iterator &operator=(const UTF8Iterator &other) { +	UTF8Iterator(UTF8Iterator &&other) noexcept = default; +	UTF8Iterator &operator=(const UTF8Iterator &other) noexcept {  		if (this != &other) {  			doc = other.doc;  			position = other.position; @@ -2700,11 +2721,13 @@ public:  		}  		return *this;  	} -	wchar_t operator*() const { +	UTF8Iterator &operator=(UTF8Iterator &&) noexcept = default; +	~UTF8Iterator() = default; +	wchar_t operator*() const noexcept {  		assert(lenCharacters != 0);  		return buffered[characterIndex];  	} -	UTF8Iterator &operator++() { +	UTF8Iterator &operator++() noexcept {  		if ((characterIndex + 1) < (lenCharacters)) {  			characterIndex++;  		} else { @@ -2714,7 +2737,7 @@ public:  		}  		return *this;  	} -	UTF8Iterator operator++(int) { +	UTF8Iterator operator++(int) noexcept {  		UTF8Iterator retVal(*this);  		if ((characterIndex + 1) < (lenCharacters)) {  			characterIndex++; @@ -2725,7 +2748,7 @@ public:  		}  		return retVal;  	} -	UTF8Iterator &operator--() { +	UTF8Iterator &operator--() noexcept {  		if (characterIndex) {  			characterIndex--;  		} else { @@ -2735,29 +2758,29 @@ public:  		}  		return *this;  	} -	bool operator==(const UTF8Iterator &other) const { +	bool operator==(const UTF8Iterator &other) const noexcept {  		// Only test the determining fields, not the character widths and values derived from this  		return doc == other.doc &&  			position == other.position &&  			characterIndex == other.characterIndex;  	} -	bool operator!=(const UTF8Iterator &other) const { +	bool operator!=(const UTF8Iterator &other) const noexcept {  		// Only test the determining fields, not the character widths and values derived from this  		return doc != other.doc ||  			position != other.position ||  			characterIndex != other.characterIndex;  	} -	Sci::Position Pos() const { +	Sci::Position Pos() const noexcept {  		return position;  	} -	Sci::Position PosRoundUp() const { +	Sci::Position PosRoundUp() const noexcept {  		if (characterIndex)  			return position + lenBytes;	// Force to end of character  		else  			return position;  	}  private: -	void ReadCharacter() { +	void ReadCharacter() noexcept {  		const Document::CharacterExtracted charExtracted = doc->ExtractCharacter(position);  		lenBytes = charExtracted.widthBytes;  		if (charExtracted.character == unicodeReplacementChar) { @@ -2783,46 +2806,50 @@ public:  	typedef wchar_t* pointer;  	typedef wchar_t& reference; -	UTF8Iterator(const Document *doc_=0, Sci::Position position_=0) : doc(doc_), position(position_) { +	UTF8Iterator(const Document *doc_=nullptr, Sci::Position position_=0) noexcept : +		doc(doc_), position(position_) {  	}  	UTF8Iterator(const UTF8Iterator &other) noexcept {  		doc = other.doc;  		position = other.position;  	} -	UTF8Iterator &operator=(const UTF8Iterator &other) { +	UTF8Iterator(UTF8Iterator &&other) noexcept = default; +	UTF8Iterator &operator=(const UTF8Iterator &other) noexcept {  		if (this != &other) {  			doc = other.doc;  			position = other.position;  		}  		return *this;  	} -	wchar_t operator*() const { -		Document::CharacterExtracted charExtracted = doc->ExtractCharacter(position); +	UTF8Iterator &operator=(UTF8Iterator &&) noexcept = default; +	~UTF8Iterator() = default; +	wchar_t operator*() const noexcept { +		const Document::CharacterExtracted charExtracted = doc->ExtractCharacter(position);  		return charExtracted.character;  	} -	UTF8Iterator &operator++() { +	UTF8Iterator &operator++() noexcept {  		position = doc->NextPosition(position, 1);  		return *this;  	} -	UTF8Iterator operator++(int) { +	UTF8Iterator operator++(int) noexcept {  		UTF8Iterator retVal(*this);  		position = doc->NextPosition(position, 1);  		return retVal;  	} -	UTF8Iterator &operator--() { +	UTF8Iterator &operator--() noexcept {  		position = doc->NextPosition(position, -1);  		return *this;  	} -	bool operator==(const UTF8Iterator &other) const { +	bool operator==(const UTF8Iterator &other) const noexcept {  		return doc == other.doc && position == other.position;  	} -	bool operator!=(const UTF8Iterator &other) const { +	bool operator!=(const UTF8Iterator &other) const noexcept {  		return doc != other.doc || position != other.position;  	} -	Sci::Position Pos() const { +	Sci::Position Pos() const noexcept {  		return position;  	} -	Sci::Position PosRoundUp() const { +	Sci::Position PosRoundUp() const noexcept {  		return position;  	}  }; @@ -2893,7 +2920,7 @@ bool MatchOnLines(const Document *doc, const Regex ®exp, const RESearchRange  	return matched;  } -Sci::Position Cxx11RegexFindText(Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *s, +Sci::Position Cxx11RegexFindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *s,  	bool caseSensitive, Sci::Position *length, RESearch &search) {  	const RESearchRange resr(doc, minPos, maxPos);  	try { diff --git a/src/Document.h b/src/Document.h index 387af74f0..48363d92e 100644 --- a/src/Document.h +++ b/src/Document.h @@ -240,11 +240,11 @@ public:  	struct CharacterExtracted {  		unsigned int character;  		unsigned int widthBytes; -		CharacterExtracted(unsigned int character_, unsigned int widthBytes_) : +		CharacterExtracted(unsigned int character_, unsigned int widthBytes_) noexcept :  			character(character_), widthBytes(widthBytes_) {  		}  		// For DBCS characters turn 2 bytes into an int -		static CharacterExtracted DBCS(unsigned char lead, unsigned char trail) { +		static CharacterExtracted DBCS(unsigned char lead, unsigned char trail) noexcept {  			return CharacterExtracted((lead << 8) | trail, 2);  		}  	}; @@ -266,7 +266,9 @@ public:  	Document(int options);  	// Deleted so Document objects can not be copied.  	Document(const Document &) = delete; +	Document(Document &&) = delete;  	void operator=(const Document &) = delete; +	Document &operator=(Document &&) = delete;  	~Document() override;  	int AddRef(); @@ -290,15 +292,15 @@ public:  	void SCI_METHOD SetErrorStatus(int status) override;  	Sci_Position SCI_METHOD LineFromPosition(Sci_Position pos) const override; -	Sci::Line SciLineFromPosition(Sci::Position pos) const;	// Avoids casting LineFromPosition +	Sci::Line SciLineFromPosition(Sci::Position pos) const noexcept;	// Avoids casting LineFromPosition  	Sci::Position ClampPositionIntoDocument(Sci::Position pos) const;  	bool ContainsLineEnd(const char *s, Sci::Position length) const { return cb.ContainsLineEnd(s, length); }  	bool IsCrLf(Sci::Position pos) const;  	int LenChar(Sci::Position pos); -	bool InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position &end) const; +	bool InGoodUTF8(Sci::Position pos, Sci::Position &start, Sci::Position &end) const noexcept;  	Sci::Position MovePositionOutsideChar(Sci::Position pos, Sci::Position moveDir, bool checkLineEnd=true) const; -	Sci::Position NextPosition(Sci::Position pos, int moveDir) const; -	bool NextCharacter(Sci::Position &pos, int moveDir) const;	// Returns true if pos changed +	Sci::Position NextPosition(Sci::Position pos, int moveDir) const noexcept; +	bool NextCharacter(Sci::Position &pos, int moveDir) const noexcept;	// Returns true if pos changed  	Document::CharacterExtracted CharacterAfter(Sci::Position position) const;  	Document::CharacterExtracted CharacterBefore(Sci::Position position) const;  	Sci_Position SCI_METHOD GetRelativePosition(Sci_Position positionStart, Sci_Position characterOffset) const override; @@ -306,6 +308,7 @@ public:  	int SCI_METHOD GetCharacterAndWidth(Sci_Position position, Sci_Position *pWidth) const override;  	int SCI_METHOD CodePage() const override;  	bool SCI_METHOD IsDBCSLeadByte(char ch) const override; +	bool IsDBCSLeadByteNoExcept(char ch) const noexcept;  	int SafeSegment(const char *text, int length, int lengthSegment) const;  	EncodingFamily CodePageFamily() const; @@ -359,7 +362,7 @@ public:  	void DelChar(Sci::Position pos);  	void DelCharBack(Sci::Position pos); -	char CharAt(Sci::Position position) const { return cb.CharAt(position); } +	char CharAt(Sci::Position position) const noexcept { return cb.CharAt(position); }  	void SCI_METHOD GetCharRange(char *buffer, Sci_Position position, Sci_Position lengthRetrieve) const override {  		cb.GetCharRange(buffer, position, lengthRetrieve);  	} @@ -397,7 +400,7 @@ public:  	Sci_Position SCI_METHOD Length() const override { return cb.Length(); }  	void Allocate(Sci::Position newSize) { cb.Allocate(newSize); } -	CharacterExtracted ExtractCharacter(Sci::Position position) const; +	CharacterExtracted ExtractCharacter(Sci::Position position) const noexcept;  	bool IsWordStartAt(Sci::Position pos) const;  	bool IsWordEndAt(Sci::Position pos) const; diff --git a/src/Partitioning.h b/src/Partitioning.h index d1887e325..9237df0fa 100644 --- a/src/Partitioning.h +++ b/src/Partitioning.h @@ -102,7 +102,7 @@ public:  	~Partitioning() {  	} -	T Partitions() const { +	T Partitions() const noexcept {  		return static_cast<T>(body->Length())-1;  	} @@ -154,7 +154,7 @@ public:  		body->Delete(partition);  	} -	T PositionFromPartition(T partition) const { +	T PositionFromPartition(T partition) const noexcept {  		PLATFORM_ASSERT(partition >= 0);  		PLATFORM_ASSERT(partition < body->Length());  		const ptrdiff_t lengthBody = body->Length(); @@ -168,7 +168,7 @@ public:  	}  	/// Return value in range [0 .. Partitions() - 1] even for arguments outside interval -	T PartitionFromPosition(T pos) const { +	T PartitionFromPosition(T pos) const noexcept {  		if (body->Length() <= 1)  			return 0;  		if (pos >= (PositionFromPartition(Partitions()))) diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 20a2ddda3..0af487a1d 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -497,7 +497,7 @@ TextSegment BreakFinder::Next() {  				charWidth = UTF8DrawBytes(reinterpret_cast<unsigned char *>(&ll->chars[nextBreak]),  					static_cast<int>(lineRange.end - nextBreak));  			else if (encodingFamily == efDBCS) -				charWidth = pdoc->IsDBCSLeadByte(ll->chars[nextBreak]) ? 2 : 1; +				charWidth = pdoc->IsDBCSLeadByteNoExcept(ll->chars[nextBreak]) ? 2 : 1;  			const Representation *repr = preprs->RepresentationFromCharacter(&ll->chars[nextBreak], charWidth);  			if (((nextBreak > 0) && (ll->styles[nextBreak] != ll->styles[nextBreak - 1])) ||  					repr || diff --git a/src/SplitVector.h b/src/SplitVector.h index 3fb595eef..40061c955 100644 --- a/src/SplitVector.h +++ b/src/SplitVector.h @@ -104,7 +104,7 @@ public:  	/// Retrieve the element at a particular position.  	/// Retrieving positions outside the range of the buffer returns empty or 0. -	const T& ValueAt(ptrdiff_t position) const { +	const T& ValueAt(ptrdiff_t position) const noexcept {  		if (position < part1Length) {  			if (position < 0) {  				return empty; @@ -144,7 +144,7 @@ public:  	/// Retrieve the element at a particular position.  	/// The position must be within bounds or an assertion is triggered. -	const T &operator[](ptrdiff_t position) const { +	const T &operator[](ptrdiff_t position) const noexcept {  		PLATFORM_ASSERT(position >= 0 && position < lengthBody);  		if (position < part1Length) {  			return body[position]; @@ -156,7 +156,7 @@ public:  	/// Retrieve reference to the element at a particular position.  	/// This, instead of the const variant, can be used to mutate in-place.  	/// The position must be within bounds or an assertion is triggered. -	T &operator[](ptrdiff_t position) { +	T &operator[](ptrdiff_t position) noexcept {  		PLATFORM_ASSERT(position >= 0 && position < lengthBody);  		if (position < part1Length) {  			return body[position]; @@ -166,7 +166,7 @@ public:  	}  	/// Retrieve the length of the buffer. -	ptrdiff_t Length() const { +	ptrdiff_t Length() const noexcept {  		return lengthBody;  	} diff --git a/src/UniConversion.cxx b/src/UniConversion.cxx index 18c1cd521..fb50b9277 100644 --- a/src/UniConversion.cxx +++ b/src/UniConversion.cxx @@ -218,7 +218,7 @@ size_t UTF32FromUTF8(const char *s, size_t len, unsigned int *tbuf, size_t tlen)  	return ui;  } -unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) { +unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) noexcept {  	if (val < SUPPLEMENTAL_PLANE_FIRST) {  		tbuf[0] = static_cast<wchar_t>(val);  		return 1; @@ -254,7 +254,7 @@ const unsigned char UTF8BytesOfLead[256] = {  // the non-characters *FFFE, *FFFF and FDD0 .. FDEF return 3 or 4 as they can be  // reasonably treated as code points in some circumstances. They will, however,  // not have associated glyphs. -int UTF8Classify(const unsigned char *us, int len) { +int UTF8Classify(const unsigned char *us, int len) noexcept {  	// For the rules: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8  	if (us[0] < 0x80) {  		// ASCII @@ -325,7 +325,7 @@ int UTF8Classify(const unsigned char *us, int len) {  	return UTF8MaskInvalid | 1;  } -int UTF8DrawBytes(const unsigned char *us, int len) { +int UTF8DrawBytes(const unsigned char *us, int len) noexcept {  	const int utf8StatusNext = UTF8Classify(us, len);  	return (utf8StatusNext & UTF8MaskInvalid) ? 1 : (utf8StatusNext & UTF8MaskWidth);  } diff --git a/src/UniConversion.h b/src/UniConversion.h index 98bcd0329..bece53f4d 100644 --- a/src/UniConversion.h +++ b/src/UniConversion.h @@ -20,12 +20,12 @@ void UTF8FromUTF32Character(int uch, char *putf);  size_t UTF16Length(const char *s, size_t len);  size_t UTF16FromUTF8(const char *s, size_t len, wchar_t *tbuf, size_t tlen);  size_t UTF32FromUTF8(const char *s, size_t len, unsigned int *tbuf, size_t tlen); -unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf); +unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf) noexcept;  std::string FixInvalidUTF8(const std::string &text);  extern const unsigned char UTF8BytesOfLead[256]; -inline int UnicodeFromUTF8(const unsigned char *us) { +inline int UnicodeFromUTF8(const unsigned char *us) noexcept {  	switch (UTF8BytesOfLead[us[0]]) {  	case 1:  		return us[0]; @@ -38,31 +38,31 @@ inline int UnicodeFromUTF8(const unsigned char *us) {  	}  } -inline bool UTF8IsTrailByte(unsigned char ch) { +inline bool UTF8IsTrailByte(unsigned char ch) noexcept {  	return (ch >= 0x80) && (ch < 0xc0);  } -inline bool UTF8IsAscii(int ch) { +inline bool UTF8IsAscii(int ch) noexcept {  	return ch < 0x80;  }  enum { UTF8MaskWidth=0x7, UTF8MaskInvalid=0x8 }; -int UTF8Classify(const unsigned char *us, int len); +int UTF8Classify(const unsigned char *us, int len) noexcept;  // Similar to UTF8Classify but returns a length of 1 for invalid bytes  // instead of setting the invalid flag -int UTF8DrawBytes(const unsigned char *us, int len); +int UTF8DrawBytes(const unsigned char *us, int len) noexcept;  // Line separator is U+2028 \xe2\x80\xa8  // Paragraph separator is U+2029 \xe2\x80\xa9  const int UTF8SeparatorLength = 3; -inline bool UTF8IsSeparator(const unsigned char *us) { +inline bool UTF8IsSeparator(const unsigned char *us) noexcept {  	return (us[0] == 0xe2) && (us[1] == 0x80) && ((us[2] == 0xa8) || (us[2] == 0xa9));  }  // NEL is U+0085 \xc2\x85  const int UTF8NELLength = 2; -inline bool UTF8IsNEL(const unsigned char *us) { +inline bool UTF8IsNEL(const unsigned char *us) noexcept {  	return (us[0] == 0xc2) && (us[1] == 0x85);  } @@ -72,11 +72,11 @@ enum { SURROGATE_TRAIL_FIRST = 0xDC00 };  enum { SURROGATE_TRAIL_LAST = 0xDFFF };  enum { SUPPLEMENTAL_PLANE_FIRST = 0x10000 }; -inline unsigned int UTF16CharLength(wchar_t uch) { +inline unsigned int UTF16CharLength(wchar_t uch) noexcept {  	return ((uch >= SURROGATE_LEAD_FIRST) && (uch <= SURROGATE_LEAD_LAST)) ? 2 : 1;  } -inline unsigned int UTF16LengthFromUTF8ByteCount(unsigned int byteCount) { +inline unsigned int UTF16LengthFromUTF8ByteCount(unsigned int byteCount) noexcept {  	return (byteCount < 4) ? 1 : 2;  } | 
