vfs: check userland buffers before reading them.
[haiku.git] / src / apps / terminal / TerminalCharClassifier.cpp
blob86a3c9c6063982d5bf4df902d2653d2de32e2d28
1 /*
2 * Copyright 2008-2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "TerminalCharClassifier.h"
8 #include <ctype.h>
10 #include <algorithm>
13 // #pragma mark - TerminalCharClassifier
16 TerminalCharClassifier::~TerminalCharClassifier()
21 // #pragma mark - DefaultCharClassifier
24 DefaultCharClassifier::DefaultCharClassifier(const char* additionalWordChars)
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;
37 int
38 DefaultCharClassifier::Classify(const UTF8Char& character)
40 if (character.IsSpace())
41 return CHAR_TYPE_SPACE;
43 if (character.IsAlNum())
44 return CHAR_TYPE_WORD_CHAR;
46 if (std::find(fAdditionalWordChars.begin(), fAdditionalWordChars.end(),
47 character) != fAdditionalWordChars.end()) {
48 return CHAR_TYPE_WORD_CHAR;
51 return CHAR_TYPE_WORD_DELIMITER;