~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/sdk/wxscintilla/src/scintilla/src/CharClassify.cxx

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
7
 
 
8
#include <stdlib.h>
 
9
#include <ctype.h>
 
10
 
 
11
#include "CharClassify.h"
 
12
 
 
13
#ifdef SCI_NAMESPACE
 
14
using namespace Scintilla;
 
15
#endif
 
16
 
 
17
CharClassify::CharClassify() {
 
18
        SetDefaultCharClasses(true);
 
19
}
 
20
 
 
21
void CharClassify::SetDefaultCharClasses(bool includeWordClass) {
 
22
        // Initialize all char classes to default values
 
23
        for (int ch = 0; ch < 256; ch++) {
 
24
                if (ch == '\r' || ch == '\n')
 
25
                        charClass[ch] = ccNewLine;
 
26
                else if (ch < 0x20 || ch == ' ')
 
27
                        charClass[ch] = ccSpace;
 
28
                else if (includeWordClass && (ch >= 0x80 || isalnum(ch) || ch == '_'))
 
29
                        charClass[ch] = ccWord;
 
30
                else
 
31
                        charClass[ch] = ccPunctuation;
 
32
        }
 
33
}
 
34
 
 
35
void CharClassify::SetCharClasses(const unsigned char *chars, cc newCharClass) {
 
36
        // Apply the newCharClass to the specifed chars
 
37
        if (chars) {
 
38
                while (*chars) {
 
39
                        charClass[*chars] = static_cast<unsigned char>(newCharClass);
 
40
                        chars++;
 
41
                }
 
42
        }
 
43
}
 
44
 
 
45
int CharClassify::GetCharsOfClass(cc characterClass, unsigned char *buffer) {
 
46
        // Get characters belonging to the given char class; return the number
 
47
        // of characters (if the buffer is NULL, don't write to it).
 
48
        int count = 0;
 
49
        for (int ch = maxChar - 1; ch >= 0; --ch) {
 
50
                if (charClass[ch] == characterClass) {
 
51
                        ++count;
 
52
                        if (buffer) {
 
53
                                *buffer = static_cast<unsigned char>(ch);
 
54
                                buffer++;
 
55
                        }
 
56
                }
 
57
        }
 
58
        return count;
 
59
}