1 /* 2 * Copyright 2008-2013, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "TerminalCharClassifier.h" 7 8 #include <ctype.h> 9 10 #include <algorithm> 11 12 13 // #pragma mark - TerminalCharClassifier 14 15 16 TerminalCharClassifier::~TerminalCharClassifier() 17 { 18 } 19 20 21 // #pragma mark - DefaultCharClassifier 22 23 24 DefaultCharClassifier::DefaultCharClassifier(const char* additionalWordChars) 25 { 26 const char* p = additionalWordChars; 27 while (p != NULL && *p != '\0') { 28 int count = UTF8Char::ByteCount(*p); 29 if (count <= 0 || count > 4) 30 break; 31 fAdditionalWordChars.push_back(UTF8Char(p, count)); 32 p += count; 33 } 34 } 35 36 37 int 38 DefaultCharClassifier::Classify(const UTF8Char& character) 39 { 40 if (character.IsSpace()) 41 return CHAR_TYPE_SPACE; 42 43 if (character.IsAlNum()) 44 return CHAR_TYPE_WORD_CHAR; 45 46 if (std::find(fAdditionalWordChars.begin(), fAdditionalWordChars.end(), 47 character) != fAdditionalWordChars.end()) { 48 return CHAR_TYPE_WORD_CHAR; 49 } 50 51 return CHAR_TYPE_WORD_DELIMITER; 52 } 53