Beispiel #1
0
        public static StringBuilder ExtractComment(this StringBuilder @this, int startIndex, out int endIndex)
        {
            if (@this.Length > startIndex + 1)
            {
                var ch1 = @this[startIndex];
                var ch2 = @this[startIndex + 1];

                if (ch1 == '/' && ch2 == '/')
                {
                    // Single line comment

                    return(@this.ExtractCommentSingleLine(startIndex, out endIndex));
                }

                if (ch1 == '/' && ch2 == '*')
                {
                    /*
                     * Multi-line comment
                     */

                    return(@this.ExtractCommentMultiLine(startIndex, out endIndex));
                }
            }

            endIndex = -1;
            return(null);
        }
Beispiel #2
0
        public static StringBuilder ExtractTriviaToken(this StringBuilder @this, int startIndex, out int endIndex)
        {
            var sb  = new StringBuilder();
            var pos = startIndex;

            var isSpace = false;

            while (pos < @this.Length)
            {
                var ch = @this[pos];
                pos++;

                if (ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t')
                {
                    isSpace = true;
                    sb.Append(ch);
                }
                else if (ch == '/' && !isSpace)
                {
                    if (pos < @this.Length)
                    {
                        ch = @this[pos];
                        if (ch == '/')
                        {
                            return(@this.ExtractCommentSingleLine(startIndex, out endIndex));
                        }
                        if (ch == '*')
                        {
                            return(@this.ExtractCommentMultiLine(startIndex, out endIndex));
                        }

                        // otherwise is probably the divide operator
                        pos--;
                        break;
                    }
                }
                else
                {
                    pos -= 2;
                    break;
                }
            }

            if (isSpace)
            {
                endIndex = pos;
                return(sb);
            }

            endIndex = -1;
            return(null);
        }
 public static StringBuilder ExtractCommentSingleLine(this StringBuilder @this)
 {
     return(@this.ExtractCommentSingleLine(0));
 }
        public static StringBuilder ExtractCommentSingleLine(this StringBuilder @this, int startIndex)
        {
            int endIndex;

            return(@this.ExtractCommentSingleLine(startIndex, out endIndex));
        }
 public static StringBuilder ExtractCommentSingleLine(this StringBuilder @this, out int endIndex)
 {
     return(@this.ExtractCommentSingleLine(0, out endIndex));
 }