Ticket #7423: terminal-utf8-spaces-v2.patch
File terminal-utf8-spaces-v2.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 } else if (ByteCount() == 3) { 83 // most multibyte space chars are all in one range (0x2000-0x200B) 84 if (bytes[0] == 0xe8 && bytes[1] == 0x80) 85 return (bytes[2] >= 0x80 && bytes[2] <= 0x8f); 86 87 // U+FEFF (zero-width non-breaking space) is not 88 if (bytes[0] == 0xef && bytes[1] == 0xbb) 89 return (bytes[2] == 0xbf); 90 91 return false; 92 } else { 93 return false; 94 } 68 95 } 69 96 97 70 98 UTF8Char ToLower() const 71 99 { 72 100 // TODO: Support multi-byte chars! … … 76 104 return UTF8Char((char)tolower(bytes[0])); 77 105 } 78 106 107 79 108 bool operator==(const UTF8Char& other) const 80 109 { 81 110 int32 byteCount = ByteCount(); … … 91 120 return equals; 92 121 } 93 122 123 94 124 bool operator!=(const UTF8Char& other) const 95 125 { 96 126 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