当前位置: 首页>>代码示例>>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;未经允许,请勿转载。