| 1 |
// Scintilla source code edit control |
| 2 |
/** @file StyleContext.cxx |
| 3 |
** Lexer infrastructure. |
| 4 |
**/ |
| 5 |
// Copyright 1998-2004 by Neil Hodgson <[email protected]> |
| 6 |
// This file is in the public domain. |
| 7 |
|
| 8 |
#include <cstdlib> |
| 9 |
#include <cstdint> |
| 10 |
#include <cassert> |
| 11 |
|
| 12 |
#include <string> |
| 13 |
#include <string_view> |
| 14 |
|
| 15 |
#include "ILexer.h" |
| 16 |
|
| 17 |
#include "LexAccessor.h" |
| 18 |
#include "Accessor.h" |
| 19 |
#include "StyleContext.h" |
| 20 |
#include "CharacterSet.h" |
| 21 |
|
| 22 |
using namespace Lexilla; |
| 23 |
|
| 24 |
StyleContext::StyleContext(Sci_PositionU startPos, Sci_PositionU length, |
| 25 |
int initStyle, LexAccessor &styler_, char chMask) : |
| 26 |
styler(styler_), |
| 27 |
multiByteAccess((styler.Encoding() == EncodingType::eightBit) ? nullptr : styler.MultiByteAccess()), |
| 28 |
lengthDocument(static_cast<Sci_PositionU>(styler.Length())), |
| 29 |
endPos(((startPos + length) < lengthDocument) ? (startPos + length) : (lengthDocument+1)), |
| 30 |
lineDocEnd(styler.GetLine(lengthDocument)), |
| 31 |
currentPosLastRelative(SIZE_MAX), |
| 32 |
currentPos(startPos), |
| 33 |
currentLine(styler.GetLine(startPos)), |
| 34 |
lineEnd(styler.LineEnd(currentLine)), |
| 35 |
lineStartNext(styler.LineStart(currentLine + 1)), |
| 36 |
atLineStart(static_cast<Sci_PositionU>(styler.LineStart(currentLine)) == startPos), |
| 37 |
// Mask off all bits which aren't in the chMask. |
| 38 |
state(initStyle &chMask) { |
| 39 |
|
| 40 |
styler.StartAt(startPos /*, chMask*/); |
| 41 |
styler.StartSegment(startPos); |
| 42 |
|
| 43 |
chPrev = GetRelativeCharacter(-1); |
| 44 |
|
| 45 |
// Variable width is now 0 so GetNextChar gets the char at currentPos into chNext/widthNext |
| 46 |
GetNextChar(); |
| 47 |
ch = chNext; |
| 48 |
width = widthNext; |
| 49 |
|
| 50 |
GetNextChar(); |
| 51 |
} |
| 52 |
|
| 53 |
bool StyleContext::MatchIgnoreCase(const char *s) { |
| 54 |
if (MakeLowerCase(ch) != static_cast<unsigned char>(*s)) |
| 55 |
return false; |
| 56 |
s++; |
| 57 |
if (MakeLowerCase(chNext) != static_cast<unsigned char>(*s)) |
| 58 |
return false; |
| 59 |
s++; |
| 60 |
for (int n = 2; *s; n++) { |
| 61 |
if (*s != |
| 62 |
MakeLowerCase(styler.SafeGetCharAt(currentPos + n, 0))) |
| 63 |
return false; |
| 64 |
s++; |
| 65 |
} |
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
void StyleContext::GetCurrent(char *s, Sci_PositionU len) const { |
| 70 |
styler.GetRange(styler.GetStartSegment(), currentPos, s, len); |
| 71 |
} |
| 72 |
|
| 73 |
void StyleContext::GetCurrentLowered(char *s, Sci_PositionU len) const { |
| 74 |
styler.GetRangeLowered(styler.GetStartSegment(), currentPos, s, len); |
| 75 |
} |
| 76 |
|
| 77 |
void StyleContext::GetCurrentString(std::string &string, Transform transform) const { |
| 78 |
const Sci_PositionU startPos = styler.GetStartSegment(); |
| 79 |
const Sci_PositionU len = currentPos - styler.GetStartSegment(); |
| 80 |
string.resize(len); |
| 81 |
if (transform == Transform::lower) { |
| 82 |
styler.GetRangeLowered(startPos, currentPos, string.data(), len + 1); |
| 83 |
} else { |
| 84 |
styler.GetRange(startPos, currentPos, string.data(), len + 1); |
| 85 |
} |
| 86 |
} |