當前位置: 首頁>>代碼示例>>C#>>正文


C# Block.Indent方法代碼示例

本文整理匯總了C#中Block.Indent方法的典型用法代碼示例。如果您正苦於以下問題:C# Block.Indent方法的具體用法?C# Block.Indent怎麽用?C# Block.Indent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Block的用法示例。


在下文中一共展示了Block.Indent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Step

        public void Step(IDocumentAccessor doc, IndentationSettings set)
        {
            string line = doc.Text;
            if (set.LeaveEmptyLines && line.Length == 0) return; // leave empty lines empty
            line = line.TrimStart();

            StringBuilder indent = new StringBuilder();
            if (line.Length == 0) {
                // Special treatment for empty lines:
                if (blockComment || (inString && verbatim))
                    return;
                indent.Append(block.InnerIndent);
                indent.Append(Repeat(set.IndentString, block.OneLineBlock));
                if (block.Continuation)
                    indent.Append(set.IndentString);
                if (doc.Text != indent.ToString())
                    doc.Text = indent.ToString();
                return;
            }

            if (TrimEnd(doc))
                line = doc.Text.TrimStart();

            Block oldBlock = block;
            bool startInComment = blockComment;
            bool startInString = (inString && verbatim);

            #region Parse char by char
            lineComment = false;
            inChar = false;
            escape = false;
            if (!verbatim) inString = false;

            lastRealChar = '\n';

            char lastchar = ' ';
            char c = ' ';
            char nextchar = line[0];
            for (int i = 0; i < line.Length; i++) {
                if (lineComment) break; // cancel parsing current line

                lastchar = c;
                c = nextchar;
                if (i + 1 < line.Length)
                    nextchar = line[i + 1];
                else
                    nextchar = '\n';

                if (escape) {
                    escape = false;
                    continue;
                }

                #region Check for comment/string chars
                switch (c) {
                    case '/':
                        if (blockComment && lastchar == '*')
                            blockComment = false;
                        if (!inString && !inChar) {
                            if (!blockComment && nextchar == '/')
                                lineComment = true;
                            if (!lineComment && nextchar == '*')
                                blockComment = true;
                        }
                        break;
                    case '#':
                        if (!(inChar || blockComment || inString))
                            lineComment = true;
                        break;
                    case '"':
                        if (!(inChar || lineComment || blockComment)) {
                            inString = !inString;
                            if (!inString && verbatim) {
                                if (nextchar == '"') {
                                    escape = true; // skip escaped quote
                                    inString = true;
                                } else {
                                    verbatim = false;
                                }
                            } else if (inString && lastchar == '@') {
                                verbatim = true;
                            }
                        }
                        break;
                    case '\'':
                        if (!(inString || lineComment || blockComment)) {
                            inChar = !inChar;
                        }
                        break;
                    case '\\':
                        if ((inString && !verbatim) || inChar)
                            escape = true; // skip next character
                        break;
                }
                #endregion

                if (lineComment || blockComment || inString || inChar) {
                    if (wordBuilder.Length > 0)
                        block.LastWord = wordBuilder.ToString();
                    wordBuilder.Length = 0;
//.........這裏部分代碼省略.........
開發者ID:Amichai,項目名稱:PhysicsPad,代碼行數:101,代碼來源:IndentationReformatter.cs

示例2: Step

        private void Step(IDocumentAccessor doc, IndentationSettings settings)
        {
            string line = doc.Text;
            if (settings.LeaveEmptyLines && line.Length == 0)
            {
                // Leave empty lines empty.
                _lineCommentStart = 0;
                return;
            }

            line = line.TrimStart();
            if (line.Length == 0)
            {
                _lineCommentStart = 0;
                if (_inBlockComment || _inVerbatimString)
                {
                    // Examples:
                    //
                    //  /* comment
                    //                      <-- HERE
                    //     comment
                    //  */
                    //
                    //  string s = @"text
                    //                      <-- HERE
                    //  text";
                    return;
                }

                _indent.Clear();
                _indent.Append(_block.InnerIndent);
                _indent.Append(Repeat(settings.IndentString, _block.OneLineBlock));
                if (_block.Continuation)
                {
                    // Example:
                    //
                    //   method(
                    //                      <-- HERE
                    //
                    _indent.Append(settings.IndentString);
                }

                // Apply indentation to current line.
                if (doc.Text.Length != _indent.Length) // Check length first to avoid unnecessary ToString().
                {
                    string text = _indent.ToString();
                    // ReSharper disable once RedundantCheckBeforeAssignment
                    if (doc.Text != text)
                        doc.Text = text;
                }

                return;
            }

            if (TrimEnd(doc))
                line = doc.Text.TrimStart();

            // oldBlock is the block at the start of the line.
            // _block is the block at the current character.
            Block oldBlock = _block;

            bool startInComment = _inBlockComment;
            bool startInString = _inVerbatimString;
            bool inLineComment = false;
            int lastLineCommentStart = _lineCommentStart;
            _lineCommentStart = 0;
            bool inString = _inVerbatimString;
            bool inChar = false;
            bool isEscapeChar = false;

            char lastRealChar = '\n'; // The last non-comment character.

            #region ----- Parse line character by character. -----

            char previousChar;
            char currentChar = ' ';
            char nextChar = line[0];
            for (int i = 0; i < line.Length; i++)
            {
                if (inLineComment)
                {
                    // Cancel parsing current line.
                    break;
                }

                previousChar = currentChar;
                currentChar = nextChar;
                if (i + 1 < line.Length)
                    nextChar = line[i + 1];
                else
                    nextChar = '\n';

                // Skip escape characters.
                if (isEscapeChar)
                {
                    // Example:
                    //
                    //   char c = '\t';
                    //              ^
                    //             HERE
//.........這裏部分代碼省略.........
開發者ID:Zolniu,項目名稱:DigitalRune,代碼行數:101,代碼來源:CSharpIndentationReformatter.cs


注:本文中的Block.Indent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。