当前位置: 首页>>代码示例>>C#>>正文


C# Scintilla.SetStyling方法代码示例

本文整理汇总了C#中ScintillaNET.Scintilla.SetStyling方法的典型用法代码示例。如果您正苦于以下问题:C# Scintilla.SetStyling方法的具体用法?C# Scintilla.SetStyling怎么用?C# Scintilla.SetStyling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScintillaNET.Scintilla的用法示例。


在下文中一共展示了Scintilla.SetStyling方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Style

        public void Style(Scintilla scintilla, int startPos, int endPos)
        {
            // 改行コードをWindowsフォーマット(CR+LF)またはUnixフォーマット(LF)から
            // Macフォーマット(CR)にしたときに発生する例外(IndexOutOfRangeException)を回避
            startPos = startPos < 0 ? 0 : startPos;
            endPos = endPos > scintilla.TextLength ? scintilla.TextLength : endPos;

            int lineNumber = scintilla.LineFromPosition(startPos);
            startPos = scintilla.Lines[lineNumber].Position;

            char chBeforePrev = '\0';
            char chPrev = '\0';
            char ch = '\0';
            char chNext = '\0';
            char chAfterNext = '\0';
            int length = 0;
            ParseState state = ParseState.None;

            switch (scintilla.GetStyleAt(startPos - 1)) {
                case HspLexer.StylePreprocessor:
                    state = ParseState.AfterPreprocessor;
                    break;
                case HspLexer.StyleString:
                    state = ParseState.String;
                    break;
                case HspLexer.StyleComment:
                    state = ParseState.Comment;
                    break;
            }

            scintilla.StartStyling(startPos);

            int currentPos = startPos;
            int currentLine = lineNumber;
            int currentLineStartPos = startPos;
            int currentLineEndPos = scintilla.Lines[lineNumber].EndPosition;

            while (currentPos < endPos) {
                chBeforePrev = (char)scintilla.GetCharAt(currentPos - 2);
                chPrev = (char)scintilla.GetCharAt(currentPos - 1);
                ch = (char)scintilla.GetCharAt(currentPos);
                chNext = (char)scintilla.GetCharAt(currentPos + 1);
                chAfterNext = (char)scintilla.GetCharAt(currentPos + 2);

            Process:
                switch (state) {
                    case ParseState.None:
                        if (ch == '\"') {
                            // 文字列
                            scintilla.SetStyling(1, HspLexer.StyleStringLine);
                            state = ParseState.StringLine;
                        } else if (ch == '{' && chNext == '\"') {
                            // 複数行文字列
                            scintilla.SetStyling(2, HspLexer.StyleString);
                            state = ParseState.String;
                            ++currentPos;
                        } else if (ch == '\'') {
                            // 文字
                            scintilla.SetStyling(1, HspLexer.StyleCharacter);
                            state = ParseState.Character;
                        } else if (ch == ';') {
                            // 単一行コメント
                            scintilla.SetStyling(1, HspLexer.StyleCommentLine);
                            state = ParseState.CommentLine;
                        } else if (ch == '/' && chNext == '/') {
                            // 単一行コメント
                            scintilla.SetStyling(2, HspLexer.StyleCommentLine);
                            state = ParseState.CommentLine;
                            ++currentPos;
                        } else if (ch == '/' && chNext == '*') {
                            // 複数行コメント
                            scintilla.SetStyling(2, HspLexer.StyleComment);
                            state = ParseState.Comment;
                            ++currentPos;
                        } else if (ch == '*' && (Char.IsLetter(chNext) || chNext == '_') &&
                            String.IsNullOrWhiteSpace(scintilla.GetTextRange(
                                currentLineStartPos, currentPos - currentLineStartPos))) {
                            // ラベル
                            scintilla.SetStyling(2, HspLexer.StyleLabel);
                            state = ParseState.Label;
                            ++currentPos;
                        } else if (ch == '#' && length == 0 &&
                            String.IsNullOrWhiteSpace(scintilla.GetTextRange(
                                currentLineStartPos, currentPos - currentLineStartPos))) {
                            // プリプロセッサ
                            state = ParseState.Preprocessor;
                            goto Process;
                        } else if ((Char.IsLetter(ch) || ch == '_') && length == 0) {
                            // 識別子
                            state = ParseState.Identifier;
                            goto Process;
                        } else if (ch == ':') {
                            // 行区切り
                            currentLineStartPos = currentPos + 1;
                            scintilla.SetStyling(1, HspLexer.StyleDefault);
                        } else if (ch == '\0') {
                            // NULL文字の場合はすぐreturn
                            return;
                        } else {
                            scintilla.SetStyling(1, HspLexer.StyleDefault);
//.........这里部分代码省略.........
开发者ID:drksugi,项目名称:HspEditorPlus,代码行数:101,代码来源:HspLexer.cs

示例2: StyleText

        public void StyleText(Scintilla scintilla, int startPos, int endPos)
        {
            if(scintilla.GetCharAt(0) != '=') //Not Expression
                return;

            // Back up to the line start
            var line = scintilla.LineFromPosition(startPos);
            startPos = scintilla.Lines[line].Position;

            var length = 0;
            char stringStartChar = '"';
            var state = LexerState.Unknown;
            var EOF = false;

            // Start styling
            scintilla.StartStyling(startPos);
            while (startPos < endPos)
            {
                var c = (char)scintilla.GetCharAt(startPos);
                //lastSymbol = startPos == endPos - 1;

            REPROCESS:
                switch (state)
                {
                    case LexerState.Unknown:
                        if (c == '"' || c == '\'')
                        {
                            // Start of "string"
                            stringStartChar = c;
                            scintilla.SetStyling(1, (int)Style.String);
                            state = LexerState.String;
                        }
                        else if (c == '{')
                        {
                            state = LexerState.Braces;
                            goto REPROCESS;
                        }
                        else if (Char.IsDigit(c))
                        {
                            state = LexerState.Number;
                            goto REPROCESS;
                        }
                        else if (Char.IsLetter(c))
                        {
                            state = LexerState.Identifier;
                            goto REPROCESS;
                        }
                        else if (operators.Any(x => x[0] == c))
                        {
                            state = LexerState.Operator;
                            goto REPROCESS;
                        }
                        else
                        {
                            // Everything else
                            scintilla.SetStyling(1, (int)Style.Default);
                        }
                        break;

                    case LexerState.String:
                        if (c == stringStartChar)
                        {
                            length++;
                            scintilla.SetStyling(length, (int)Style.String);
                            length = 0;
                            state = LexerState.Unknown;
                        }
                        else
                        {
                            length++;
                        }
                        break;

                    case LexerState.Braces:
                        if (c == '}')
                        {
                            length++;
                            var style = Style.Identifier;
                            var identifier = scintilla.GetTextRange(startPos - length + 2, length - 2);
                            if (identifier.Length == 0)
                            {
                                style = Style.Error;
                            }
                            else if (identifier[0] == '!')
                            {
                                if (userInfo.Contains(identifier.Substring(1)))
                                    style = Style.UserInfo;
                                else
                                    style = Style.Error;
                            }
                            else if (identifier[0] == '@')
                            {
                                if (globals.Contains(identifier.Substring(1)))
                                    style = Style.Globals;
                                else
                                    style = Style.Error;
                            }
                            else if (identifier[0] == '?' && parameters != null)
                            {
                                if (parameters.Contains(identifier.Substring(1)))
//.........这里部分代码省略.........
开发者ID:majorsilence,项目名称:My-FyiReporting,代码行数:101,代码来源:RdlScriptLexer.cs


注:本文中的ScintillaNET.Scintilla.SetStyling方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。