Ticket #7423: terminal-utf8-spaces.patch
File terminal-utf8-spaces.patch, 2.4 KB (added by , 13 years ago) |
---|
-
src/apps/terminal/UTF8Char.h
12 12 struct UTF8Char { 13 13 char bytes[4]; 14 14 15 15 16 UTF8Char() 16 17 { 17 18 } 19 18 20 19 21 UTF8Char(char c) 20 22 { 21 23 bytes[0] = c; 22 24 } 25 26 27 UTF8Char(const char* c) 28 { 29 SetTo(c, ByteCount(*c)); 30 } 31 23 32 24 33 UTF8Char(const char* c, int32 count) 25 34 { 26 35 SetTo(c, count); 27 36 } 28 37 38 29 39 void SetTo(const char* c, int32 count) 30 40 { 31 41 bytes[0] = c[0]; … … 39 49 } 40 50 } 41 51 52 42 53 static int32 ByteCount(char firstChar) 43 54 { 44 55 // Note, this does not recognize invalid chars … … 50 61 return c < 0xf0 ? 3 : 4; 51 62 } 52 63 64 53 65 int32 ByteCount() const 54 66 { 55 67 return ByteCount(bytes[0]); 56 68 } 57 69 70 58 71 bool IsFullWidth() const 59 72 { 60 73 // TODO: Implement! 61 74 return false; 62 75 } 63 76 77 64 78 bool IsSpace() const 65 79 { 66 // TODO: Support multi-byte chars! 67 return ByteCount() == 1 ? isspace(bytes[0]) : false; 80 if (ByteCount() == 1) { 81 return isspace(bytes[0]); 82 } 83 else if (ByteCount() == 3) { 84 // most multibyte space chars are all in one range (0x2000-0x200B) 85 if (bytes[0] == 0xe8 && bytes[1] == 0x80) 86 return (bytes[2] >= 0x80 && bytes[2] <= 0x8f); 87 88 // U+FEFF (zero-width non-breaking space) is not 89 if (bytes[0] == 0xef && bytes[1] == 0xbb) 90 return (bytes[2] == 0xbf); 91 92 return false; 93 } 94 else { 95 return false; 96 } 68 97 } 69 98 99 70 100 UTF8Char ToLower() const 71 101 { 72 102 // TODO: Support multi-byte chars! … … 76 106 return UTF8Char((char)tolower(bytes[0])); 77 107 } 78 108 109 79 110 bool operator==(const UTF8Char& other) const 80 111 { 81 112 int32 byteCount = ByteCount(); … … 91 122 return equals; 92 123 } 93 124 125 94 126 bool operator!=(const UTF8Char& other) const 95 127 { 96 128 return !(*this == other); -
src/apps/terminal/TermView.cpp
405 405 406 406 virtual int Classify(const char* character) 407 407 { 408 // TODO: Deal correctly with non-ASCII chars. 409 char c = *character; 410 if (UTF8Char::ByteCount(c) > 1) 411 return CHAR_TYPE_WORD_CHAR; 412 413 if (isspace(c)) 408 UTF8Char u8c(character); 409 410 if (u8c.IsSpace()) 414 411 return CHAR_TYPE_SPACE; 412 413 char c = *character; 415 414 if (isalnum(c) || strchr(fSpecialWordChars, c) != NULL) 416 415 return CHAR_TYPE_WORD_CHAR; 417 416