~ubuntu-branches/ubuntu/utopic/geany/utopic

« back to all changes in this revision

Viewing changes to scintilla/CharClassify.cxx

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-12-10 07:43:26 UTC
  • mfrom: (3.3.7 sid)
  • Revision ID: package-import@ubuntu.com-20111210074326-s8yqbew5i20h33tf
Tags: 0.21-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  - debian/patches/20_use_evince_viewer.patch:
     + use evince as viewer for pdf and dvi files
  - debian/patches/20_use_x_terminal_emulator.patch:
     + use x-terminal-emulator as terminal
  - debian/control
     + Add breaks on geany-plugins-common << 0.20
* Also fixes bugs:
  - Filter for MATLAB/Octave files filters everythign (LP: 885505)

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
 
// Shut up annoying Visual C++ warnings:
14
 
#ifdef _MSC_VER
15
 
#pragma warning(disable: 4514)
16
 
#endif
17
 
 
18
 
CharClassify::CharClassify() {
19
 
        SetDefaultCharClasses(true);
20
 
}
21
 
 
22
 
void CharClassify::SetDefaultCharClasses(bool includeWordClass) {
23
 
        // Initialize all char classes to default values
24
 
        for (int ch = 0; ch < 256; ch++) {
25
 
                if (ch == '\r' || ch == '\n')
26
 
                        charClass[ch] = ccNewLine;
27
 
                else if (ch < 0x20 || ch == ' ')
28
 
                        charClass[ch] = ccSpace;
29
 
                else if (includeWordClass && (ch >= 0x80 || isalnum(ch) || ch == '_'))
30
 
                        charClass[ch] = ccWord;
31
 
                else
32
 
                        charClass[ch] = ccPunctuation;
33
 
        }
34
 
}
35
 
 
36
 
void CharClassify::SetCharClasses(const unsigned char *chars, cc newCharClass) {
37
 
        // Apply the newCharClass to the specifed chars
38
 
        if (chars) {
39
 
                while (*chars) {
40
 
                        charClass[*chars] = static_cast<unsigned char>(newCharClass);
41
 
                        chars++;
42
 
                }
43
 
        }
44
 
}
45
 
 
46
 
int CompareCaseInsensitive(const char *a, const char *b) {
47
 
        while (*a && *b) {
48
 
                if (*a != *b) {
49
 
                        char upperA = MakeUpperCase(*a);
50
 
                        char upperB = MakeUpperCase(*b);
51
 
                        if (upperA != upperB)
52
 
                                return upperA - upperB;
53
 
                }
54
 
                a++;
55
 
                b++;
56
 
        }
57
 
        // Either *a or *b is nul
58
 
        return *a - *b;
59
 
}
60
 
 
61
 
int CompareNCaseInsensitive(const char *a, const char *b, size_t len) {
62
 
        while (*a && *b && len) {
63
 
                if (*a != *b) {
64
 
                        char upperA = MakeUpperCase(*a);
65
 
                        char upperB = MakeUpperCase(*b);
66
 
                        if (upperA != upperB)
67
 
                                return upperA - upperB;
68
 
                }
69
 
                a++;
70
 
                b++;
71
 
                len--;
72
 
        }
73
 
        if (len == 0)
74
 
                return 0;
75
 
        else
76
 
                // Either *a or *b is nul
77
 
                return *a - *b;
78
 
}