diff options
| author | nyamatongwe <devnull@localhost> | 2003-01-13 10:25:28 +0000 | 
|---|---|---|
| committer | nyamatongwe <devnull@localhost> | 2003-01-13 10:25:28 +0000 | 
| commit | 1d47b64abfffba1bfeb30826d10b6034108306fb (patch) | |
| tree | 87a7d825cd0c2bb78b8d6c65daa72d4b2b407585 | |
| parent | 8b71956cc93116ade7795bee066c9b4d3c3e224c (diff) | |
| download | scintilla-mirror-1d47b64abfffba1bfeb30826d10b6034108306fb.tar.gz | |
Simplified and corrected code.
IsDBCS no longer present as now must deal with 3 byte DBCS so use LenChar
and DBCSCharLength.
| -rw-r--r-- | src/Document.cxx | 68 | ||||
| -rw-r--r-- | src/Document.h | 13 | 
2 files changed, 23 insertions, 58 deletions
| diff --git a/src/Document.cxx b/src/Document.cxx index 7a5ce2fa8..2844bf20e 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -220,39 +220,10 @@ bool Document::IsCrLf(int pos) {  static const int maxBytesInDBCSCharacter=5; -bool Document::IsDBCS(int pos) { -	if (dbcsCodePage) { -		if (SC_CP_UTF8 == dbcsCodePage) { -			unsigned char ch = static_cast<unsigned char>(cb.CharAt(pos)); -			return ch >= 0x80; -		} else { -			// Anchor DBCS calculations at start of line because start of line can -			// not be a DBCS trail byte. -			int startLine = pos; -			char mbstr[maxBytesInDBCSCharacter+1]; -			while (startLine > 0 && cb.CharAt(startLine) != '\r' && cb.CharAt(startLine) != '\n') -				startLine--; -			while (startLine <= pos) { -				int i; -				for (i=0; i<Platform::DBCSCharMaxLength(); i++) { -					mbstr[i] = cb.CharAt(startLine+i); -				} -				mbstr[i] = '\0'; -				int mbsize = Platform::DBCSCharLength(dbcsCodePage, mbstr); -				if (mbsize >= 1) { -					startLine += mbsize; -					if (startLine >= pos) -						return true; -				} -				startLine++; -			} -		} -	} -	return false; -} -  int Document::LenChar(int pos) { -	if (IsCrLf(pos)) { +	if (pos < 0) { +		return 1; +	} else if (IsCrLf(pos)) {  		return 2;  	} else if (SC_CP_UTF8 == dbcsCodePage) {  		unsigned char ch = static_cast<unsigned char>(cb.CharAt(pos)); @@ -326,7 +297,7 @@ int Document::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) {  			while (startLine > 0 && cb.CharAt(startLine) != '\r' && cb.CharAt(startLine) != '\n')  				startLine--; -			for (;startLine <= pos;) { +			while (startLine < pos) {  				char mbstr[maxBytesInDBCSCharacter+1];  				int i;  				for(i=0;i<Platform::DBCSCharMaxLength();i++) { @@ -335,19 +306,16 @@ int Document::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) {  				mbstr[i] = '\0';  				int mbsize = Platform::DBCSCharLength(dbcsCodePage, mbstr); -				if (mbsize >= 1) { -					if (startLine + mbsize == pos) { -						return pos; -					} else if (startLine + mbsize > pos) { -						if (moveDir > 0) -							return startLine + mbsize; -						else -							return startLine; +				if (startLine + mbsize == pos) { +					return pos; +				} else if (startLine + mbsize > pos) { +					if (moveDir > 0) { +						return startLine + mbsize; +					} else { +						return startLine;  					} -					startLine += mbsize; -					continue;  				} -				startLine++; +				startLine += mbsize;  			}  		}  	} @@ -565,11 +533,9 @@ void Document::DelCharBack(int pos) {  		return;  	} else if (IsCrLf(pos - 2)) {  		DeleteChars(pos - 2, 2); -	} else if (SC_CP_UTF8 == dbcsCodePage) { +	} else if (dbcsCodePage) {  		int startChar = MovePositionOutsideChar(pos - 1, -1, false);  		DeleteChars(startChar, pos - startChar); -	} else if (IsDBCS(pos - 1)) { -		DeleteChars(pos - 2, 2);  	} else {  		DeleteChars(pos - 1, 1);  	} @@ -1064,11 +1030,11 @@ int Document::LinesTotal() {  void Document::ChangeCase(Range r, bool makeUpperCase) {  	for (int pos = r.start; pos < r.end; pos++) { -		char ch = CharAt(pos); -		if (dbcsCodePage && IsDBCS(pos)) { -			pos += LenChar(pos); +		int len = LenChar(pos); +		if (dbcsCodePage && (len > 1)) { +			pos += len;  		} else { -			if (makeUpperCase) { +			char ch = CharAt(pos);
			if (makeUpperCase) {  				if (islower(ch)) {  					ChangeChar(pos, static_cast<char>(MakeUpperCase(ch)));  				} diff --git a/src/Document.h b/src/Document.h index 82931207c..d5059f7bc 100644 --- a/src/Document.h +++ b/src/Document.h @@ -26,10 +26,10 @@ public:  	Position start;  	Position end; -	Range(Position pos=0) :  +	Range(Position pos=0) :  		start(pos), end(pos) {  	}; -	Range(Position start_, Position end_) :  +	Range(Position start_, Position end_) :  		start(start_), end(end_) {  	}; @@ -60,7 +60,7 @@ public:  	}  	bool Overlaps(Range other) const { -		return  +		return  		Contains(other.start) ||  		Contains(other.end) ||  		other.Contains(start) || @@ -88,7 +88,7 @@ public:  		}  	}; -private:	 +private:  	int refCount;  	CellBuffer cb;  	enum charClassification { ccSpace, ccNewLine, ccWord, ccPunctuation }; @@ -191,7 +191,7 @@ public:  	int ExtendWordSelect(int pos, int delta, bool onlyWordCharacters=false);  	int NextWordStart(int pos, int delta);  	int Length() { return cb.Length(); } -	long FindText(int minPos, int maxPos, const char *s,  +	long FindText(int minPos, int maxPos, const char *s,  		bool caseSensitive, bool word, bool wordStart, bool regExp, int *length);  	long FindText(int iMessage, unsigned long wParam, long lParam);  	const char *SubstituteByPosition(const char *text, int *length); @@ -222,7 +222,6 @@ public:  	int WordPartRight(int pos);  private: -	bool IsDBCS(int pos);  	charClassification WordCharClass(unsigned char ch);  	bool IsWordStartAt(int pos);  	bool IsWordEndAt(int pos); @@ -252,7 +251,7 @@ public:  	int foldLevelNow;  	int foldLevelPrev; -	DocModification(int modificationType_, int position_=0, int length_=0,  +	DocModification(int modificationType_, int position_=0, int length_=0,  		int linesAdded_=0, const char *text_=0) :  		modificationType(modificationType_),  		position(position_), | 
