notepad-plus-plus/lexilla/lexlib/StyleContext.cxx
Christian Grasser 213e9135ba Update to scintilla 5.5.3 & Lexilla 5.4.1
Release 5.5.3 (https://www.scintilla.org/scintilla553.zip)

    Released 19 October 2024.
    On Win32 change direction of horizontal mouse wheel and touchpad scrolling to match other applications. Bug #2449.

Release 5.4.1 (https://www.scintilla.org/lexilla541.zip)

    Released 19 October 2024.
    Lexer added for Dart "dart". Pull request #265, Pull request #275.
    Lexer added for troff / nroff "troff". Pull request #264.
    Lexer added for Zig "zig". Pull request #267.
    C++: Fix crash for empty documentation comment keyword where '<' occurs at line end.
    F#: Include EOLs in the style range of SCE_FSHARP_COMMENTLINE. Stabilizes EOL detection when folding line comment groups. Issue #276.
    F#: Fix per-line folding in F# documents. Issue #277.
    HTML: Improve SGML/DTD lexing. Don't terminate SGML when > inside quoted string. Lex both [ and ] as SCE_H_SGML_DEFAULT. Nested sections handled instead of switching to SCE_H_SGML_ERROR. Issue #272.
    JavaScript: New SCE_HJ_TEMPLATELITERAL and SCE_HJA_TEMPLATELITERAL styles for template literals when lexer is hypertext, or xml. Issue #280.
    PHP: Fix failure to recognize PHP start "<?php' at end of document. Caused by not capping retrieval range at document end causing no text to be retrieved. Issue #269.
    Smalltalk: Fix scaled decimal numbers without decimal separator. Pull request #274.

Fix #15228, fix #15368, fix #15650, close #15717
2024-10-20 17:33:07 +02:00

105 lines
3.0 KiB
C++

// Scintilla source code edit control
/** @file StyleContext.cxx
** Lexer infrastructure.
**/
// Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
// This file is in the public domain.
#include <cstdlib>
#include <cstdint>
#include <cassert>
#include <string>
#include <string_view>
#include "ILexer.h"
#include "LexAccessor.h"
#include "Accessor.h"
#include "StyleContext.h"
#include "CharacterSet.h"
using namespace Lexilla;
StyleContext::StyleContext(Sci_PositionU startPos, Sci_PositionU length,
int initStyle, LexAccessor &styler_, char chMask) :
styler(styler_),
multiByteAccess((styler.Encoding() == EncodingType::eightBit) ? nullptr : styler.MultiByteAccess()),
lengthDocument(static_cast<Sci_PositionU>(styler.Length())),
endPos(((startPos + length) < lengthDocument) ? (startPos + length) : (lengthDocument+1)),
lineDocEnd(styler.GetLine(lengthDocument)),
currentPosLastRelative(SIZE_MAX),
currentPos(startPos),
currentLine(styler.GetLine(startPos)),
lineEnd(styler.LineEnd(currentLine)),
lineStartNext(styler.LineStart(currentLine + 1)),
atLineStart(static_cast<Sci_PositionU>(styler.LineStart(currentLine)) == startPos),
// Mask off all bits which aren't in the chMask.
state(initStyle &chMask) {
styler.StartAt(startPos /*, chMask*/);
styler.StartSegment(startPos);
chPrev = GetRelativeCharacter(-1);
// Variable width is now 0 so GetNextChar gets the char at currentPos into chNext/widthNext
GetNextChar();
ch = chNext;
width = widthNext;
GetNextChar();
}
bool StyleContext::MatchIgnoreCase(const char *s) {
if (MakeLowerCase(ch) != static_cast<unsigned char>(*s))
return false;
s++;
if (MakeLowerCase(chNext) != static_cast<unsigned char>(*s))
return false;
s++;
for (int n = 2; *s; n++) {
if (*s !=
MakeLowerCase(styler.SafeGetCharAt(currentPos + n, 0)))
return false;
s++;
}
return true;
}
bool StyleContext::MatchIgnoreCase2(const char *s) {
if (MakeLowerCase(ch) != MakeLowerCase(static_cast<unsigned char>(*s)))
return false;
s++;
if (!*s)
return true;
if (MakeLowerCase(chNext) != MakeLowerCase(static_cast<unsigned char>(*s)))
return false;
s++;
for (int n = 2; *s; n++) {
if (MakeLowerCase(static_cast<unsigned char>(*s)) !=
MakeLowerCase(static_cast<unsigned char>(styler.SafeGetCharAt(currentPos + n))))
return false;
s++;
}
return true;
}
void StyleContext::GetCurrent(char *s, Sci_PositionU len) const {
styler.GetRange(styler.GetStartSegment(), currentPos, s, len);
}
void StyleContext::GetCurrentLowered(char *s, Sci_PositionU len) const {
styler.GetRangeLowered(styler.GetStartSegment(), currentPos, s, len);
}
void StyleContext::GetCurrentString(std::string &string, Transform transform) const {
const Sci_PositionU startPos = styler.GetStartSegment();
const Sci_PositionU len = currentPos - styler.GetStartSegment();
string.resize(len);
if (transform == Transform::lower) {
styler.GetRangeLowered(startPos, currentPos, string.data(), len + 1);
} else {
styler.GetRange(startPos, currentPos, string.data(), len + 1);
}
}