diff options
| -rw-r--r-- | src/DBCS.cxx | 12 | ||||
| -rw-r--r-- | src/DBCS.h | 1 | ||||
| -rw-r--r-- | src/Editor.cxx | 21 | 
3 files changed, 20 insertions, 14 deletions
diff --git a/src/DBCS.cxx b/src/DBCS.cxx index 0af6fc6eb..e3ae3d75f 100644 --- a/src/DBCS.cxx +++ b/src/DBCS.cxx @@ -39,4 +39,16 @@ bool DBCSIsLeadByte(int codePage, char ch) noexcept {  	return false;  } +bool IsDBCSValidSingleByte(int codePage, int ch) noexcept { +	switch (codePage) { +	case 932: +		return ch == 0x80 +			|| (ch >= 0xA0 && ch <= 0xDF) +			|| (ch >= 0xFD); + +	default: +		return false; +	} +} +  } diff --git a/src/DBCS.h b/src/DBCS.h index c8edad057..ceeb75929 100644 --- a/src/DBCS.h +++ b/src/DBCS.h @@ -19,6 +19,7 @@ constexpr bool IsDBCSCodePage(int codePage) noexcept {  }  bool DBCSIsLeadByte(int codePage, char ch) noexcept; +bool IsDBCSValidSingleByte(int codePage, int ch) noexcept;  } diff --git a/src/Editor.cxx b/src/Editor.cxx index d01eb0cdf..5a0c153da 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -55,6 +55,7 @@  #include "CaseFolder.h"  #include "Document.h"  #include "UniConversion.h" +#include "DBCS.h"  #include "Selection.h"  #include "PositionCache.h"  #include "EditModel.h" @@ -226,9 +227,10 @@ void Editor::SetRepresentations() {  	}  	reprs.SetRepresentation("\x7f", "DEL"); +	const int dbcsCodePage = pdoc->dbcsCodePage;  	// C1 control set  	// As well as Unicode mode, ISO-8859-1 should use these -	if (IsUnicodeMode()) { +	if (CpUtf8 == dbcsCodePage) {  		const char *const repsC1[] = {  			"PAD", "HOP", "BPH", "NBH", "IND", "NEL", "SSA", "ESA",  			"HTS", "HTJ", "VTS", "PLD", "PLU", "RI", "SS2", "SS3", @@ -243,20 +245,11 @@ void Editor::SetRepresentations() {  		reprs.SetRepresentation("\xe2\x80\xa9", "PS");  	} -	// UTF-8 invalid bytes -	if (IsUnicodeMode()) { -		for (int k=0x80; k < 0x100; k++) { -			const char hiByte[2] = {  static_cast<char>(k), 0 }; -			char hexits[4]; -			Hexits(hexits, k); -			reprs.SetRepresentation(hiByte, hexits); -		} -	} else if (pdoc->dbcsCodePage) { -		// DBCS invalid single lead bytes +	// Invalid as single bytes in multi-byte encodings +	if (dbcsCodePage) {  		for (int k = 0x80; k < 0x100; k++) { -			const char ch = static_cast<char>(k); -			if (pdoc->IsDBCSLeadByteNoExcept(ch)  || pdoc->IsDBCSLeadByteInvalid(ch)) { -				const char hiByte[2] = { ch, 0 }; +			if ((CpUtf8 == dbcsCodePage) || !IsDBCSValidSingleByte(dbcsCodePage, k)) { +				const char hiByte[2] = { static_cast<char>(k), 0 };  				char hexits[4];  				Hexits(hexits, k);  				reprs.SetRepresentation(hiByte, hexits);  | 
