Debian Codegraph @

scintilla/lexilla/lexlib/LexAccessor.cxx

raw
1 // Scintilla source code edit control
2 /** @file LexAccessor.cxx
3 ** Interfaces between Scintilla and lexers.
4 **/
5 // Copyright 1998-2010 by Neil Hodgson <[email protected]>
6 // The License.txt file describes the conditions under which this software may be distributed.
7 #include <cassert>
8 #include <cstring>
9
10 #include <string>
11 #include <algorithm>
12
13 #include "ILexer.h"
14
15 #include "LexAccessor.h"
16 #include "CharacterSet.h"
17
18 using namespace Lexilla;
19
20 namespace Lexilla {
21
22 bool LexAccessor::MatchIgnoreCase(Sci_Position pos, const char *s) {
23 assert(s);
24 for (; *s; s++, pos++) {
25 if (*s != MakeLowerCase(SafeGetCharAt(pos))) {
26 return false;
27 }
28 }
29 return true;
30 }
31
32 void LexAccessor::GetRange(Sci_PositionU startPos_, Sci_PositionU endPos_, char *s, Sci_PositionU len) const {
33 assert(s);
34 assert(startPos_ <= endPos_ && len != 0);
35 memset(s, '\0', len);
36 endPos_ = std::min(endPos_, startPos_ + len - 1);
37 endPos_ = std::min(endPos_, static_cast<Sci_PositionU>(lenDoc));
38 len = endPos_ - startPos_;
39 if (startPos_ >= static_cast<Sci_PositionU>(startPos) && endPos_ <= static_cast<Sci_PositionU>(endPos)) {
40 const char * const p = buf + (startPos_ - startPos);
41 memcpy(s, p, len);
42 } else {
43 pAccess->GetCharRange(s, startPos_, len);
44 }
45 }
46
47 void LexAccessor::GetRangeLowered(Sci_PositionU startPos_, Sci_PositionU endPos_, char *s, Sci_PositionU len) const {
48 assert(s);
49 GetRange(startPos_, endPos_, s, len);
50 while (*s) {
51 if (*s >= 'A' && *s <= 'Z') {
52 *s += 'a' - 'A';
53 }
54 ++s;
55 }
56 }
57
58 std::string LexAccessor::GetRange(Sci_PositionU startPos_, Sci_PositionU endPos_) const {
59 assert(startPos_ < endPos_);
60 endPos_ = std::min(endPos_, static_cast<Sci_PositionU>(lenDoc));
61 const Sci_PositionU len = endPos_ - startPos_;
62 std::string s(len, '\0');
63 GetRange(startPos_, endPos_, s.data(), len + 1);
64 return s;
65 }
66
67 std::string LexAccessor::GetRangeLowered(Sci_PositionU startPos_, Sci_PositionU endPos_) const {
68 assert(startPos_ < endPos_);
69 endPos_ = std::min(endPos_, static_cast<Sci_PositionU>(lenDoc));
70 const Sci_PositionU len = endPos_ - startPos_;
71 std::string s(len, '\0');
72 GetRangeLowered(startPos_, endPos_, s.data(), len + 1);
73 return s;
74 }
75
76 }