Merge pull request #826 from kugel-/doxygen-fixes2
[geany-mirror.git] / scintilla / src / CharClassify.cxx
blob595b0da30424b4e88cf4e68c5aa7f009bf292b12
1 // Scintilla source code edit control
2 /** @file CharClassify.cxx
3 ** Character classifications used by Document and RESearch.
4 **/
5 // Copyright 2006 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 #include <stdlib.h>
9 #include <ctype.h>
11 #include <stdexcept>
13 #include "CharClassify.h"
15 #ifdef SCI_NAMESPACE
16 using namespace Scintilla;
17 #endif
19 CharClassify::CharClassify() {
20 SetDefaultCharClasses(true);
23 void CharClassify::SetDefaultCharClasses(bool includeWordClass) {
24 // Initialize all char classes to default values
25 for (int ch = 0; ch < 256; ch++) {
26 if (ch == '\r' || ch == '\n')
27 charClass[ch] = ccNewLine;
28 else if (ch < 0x20 || ch == ' ')
29 charClass[ch] = ccSpace;
30 else if (includeWordClass && (ch >= 0x80 || isalnum(ch) || ch == '_'))
31 charClass[ch] = ccWord;
32 else
33 charClass[ch] = ccPunctuation;
37 void CharClassify::SetCharClasses(const unsigned char *chars, cc newCharClass) {
38 // Apply the newCharClass to the specifed chars
39 if (chars) {
40 while (*chars) {
41 charClass[*chars] = static_cast<unsigned char>(newCharClass);
42 chars++;
47 int CharClassify::GetCharsOfClass(cc characterClass, unsigned char *buffer) {
48 // Get characters belonging to the given char class; return the number
49 // of characters (if the buffer is NULL, don't write to it).
50 int count = 0;
51 for (int ch = maxChar - 1; ch >= 0; --ch) {
52 if (charClass[ch] == characterClass) {
53 ++count;
54 if (buffer) {
55 *buffer = static_cast<unsigned char>(ch);
56 buffer++;
60 return count;