diff options
| author | nyamatongwe <unknown> | 2003-04-18 10:19:52 +0000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2003-04-18 10:19:52 +0000 | 
| commit | 3b031e3e5ec28064ce2bb4e67e0d9e48a40ee594 (patch) | |
| tree | be79d641bf1864cfc90539159dff2769ab5541d3 /src/Document.cxx | |
| parent | 9a1ee8d945b1aeeb1dab0d7e7d0710194a5cad5b (diff) | |
| download | scintilla-mirror-3b031e3e5ec28064ce2bb4e67e0d9e48a40ee594.tar.gz | |
New methods for finding the next or previous position taking multi byte
characters into account.
Diffstat (limited to 'src/Document.cxx')
| -rw-r--r-- | src/Document.cxx | 39 | 
1 files changed, 15 insertions, 24 deletions
| diff --git a/src/Document.cxx b/src/Document.cxx index 255c9ee11..98fc6b330 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -265,7 +265,7 @@ int Document::LenChar(int pos) {  		return 1;  	}  } - +#include <assert.h>  // Normalise a position so that it is not halfway through a two byte character.  // This can occur in two situations -  // When lines are terminated with \r\n pairs which should be treated as one character. @@ -273,17 +273,11 @@ int Document::LenChar(int pos) {  // If moving, move the position in the indicated direction.  int Document::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) {  	//Platform::DebugPrintf("NoCRLF %d %d\n", pos, moveDir); -	// If out of range, just return value - should be fixed up after -	if (pos < 0) -		return pos; -	if (pos > Length()) -		return pos; - -	// Position 0 and Length() can not be between any two characters -	if (pos == 0) -		return pos; -	if (pos == Length()) -		return pos; +	// If out of range, just return minimum/maximum value. +	if (pos <= 0) +		return 0; +	if (pos >= Length()) +		return Length();  	// assert pos > 0 && pos < Length()  	if (checkLineEnd && IsCrLf(pos - 1)) { @@ -309,29 +303,26 @@ int Document::MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd) {  		} else {  			// Anchor DBCS calculations at start of line because start of line can  			// not be a DBCS trail byte. -			int startLine = pos; - -			while (startLine > 0 && cb.CharAt(startLine) != '\r' && cb.CharAt(startLine) != '\n') -				startLine--; -			while (startLine < pos) { +			int posCheck = LineStart(LineFromPosition(pos)); +			while (posCheck < pos) {  				char mbstr[maxBytesInDBCSCharacter+1];  				int i;  				for(i=0;i<Platform::DBCSCharMaxLength();i++) { -					mbstr[i] = cb.CharAt(startLine+i); +					mbstr[i] = cb.CharAt(posCheck+i);  				}  				mbstr[i] = '\0';  				int mbsize = Platform::DBCSCharLength(dbcsCodePage, mbstr); -				if (startLine + mbsize == pos) { +				if (posCheck + mbsize == pos) {  					return pos; -				} else if (startLine + mbsize > pos) { +				} else if (posCheck + mbsize > pos) {  					if (moveDir > 0) { -						return startLine + mbsize; +						return posCheck + mbsize;  					} else { -						return startLine; +						return posCheck;  					}  				} -				startLine += mbsize; +				posCheck += mbsize;  			}  		}  	} @@ -938,7 +929,7 @@ long Document::FindText(int minPos, int maxPos, const char *s,  					endOfLine = startPos;  				}  			} -			 +  			DocumentIndexer di(this, endOfLine);  			int success = pre->Execute(di, startOfLine, endOfLine);  			if (success) { | 
