| 1 | // Scintilla source code edit control |
| 2 | /** @file DBCS.cxx |
| 3 | ** Functions to handle DBCS double byte encodings like Shift-JIS. |
| 4 | **/ |
| 5 | // Copyright 2017 by Neil Hodgson <neilh@scintilla.org> |
| 6 | // The License.txt file describes the conditions under which this software may be distributed. |
| 7 | |
| 8 | #include "DBCS.h" |
| 9 | |
| 10 | using namespace Scintilla::Internal; |
| 11 | |
| 12 | namespace Scintilla::Internal { |
| 13 | |
| 14 | bool DBCSIsLeadByte(int codePage, char ch) noexcept { |
| 15 | // Byte ranges found in Wikipedia articles with relevant search strings in each case |
| 16 | const unsigned char uch = ch; |
| 17 | switch (codePage) { |
| 18 | case 932: |
| 19 | // Shift_jis |
| 20 | return ((uch >= 0x81) && (uch <= 0x9F)) || |
| 21 | ((uch >= 0xE0) && (uch <= 0xFC)); |
| 22 | // Lead bytes F0 to FC may be a Microsoft addition. |
| 23 | case 936: |
| 24 | // GBK |
| 25 | return (uch >= 0x81) && (uch <= 0xFE); |
| 26 | case 949: |
| 27 | // Korean Wansung KS C-5601-1987 |
| 28 | return (uch >= 0x81) && (uch <= 0xFE); |
| 29 | case 950: |
| 30 | // Big5 |
| 31 | return (uch >= 0x81) && (uch <= 0xFE); |
| 32 | case 1361: |
| 33 | // Korean Johab KS C-5601-1992 |
| 34 | return |
| 35 | ((uch >= 0x84) && (uch <= 0xD3)) || |
| 36 | ((uch >= 0xD8) && (uch <= 0xDE)) || |
| 37 | ((uch >= 0xE0) && (uch <= 0xF9)); |
| 38 | } |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | bool IsDBCSValidSingleByte(int codePage, int ch) noexcept { |
| 43 | switch (codePage) { |
| 44 | case 932: |
| 45 | return ch == 0x80 |
| 46 | || (ch >= 0xA0 && ch <= 0xDF) |
| 47 | || (ch >= 0xFD); |
| 48 | |
| 49 | default: |
| 50 | return false; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | } |
| 55 | |