示例#1
0
        protected override string QuoteSnippetString(string value)
        {
            StringBuilder b = new StringBuilder(value.Length + 5);
            bool fInDoubleQuotes = true;
            Indentation indentation = new Indentation((IndentedTextWriter)base.Output, base.Indent + 1);
            b.Append("\"");
            for (int i = 0; i < value.Length; i++)
            {
                char ch = value[i];
                switch (ch)
                {
                    case '\t':
                        this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append("&Global.Microsoft.VisualBasic.ChrW(9)");
                        goto Label_0186;

                    case '\n':
                        this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append("&Global.Microsoft.VisualBasic.ChrW(10)");
                        goto Label_0186;

                    case '\r':
                        this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        if ((i >= (value.Length - 1)) || (value[i + 1] != '\n'))
                        {
                            break;
                        }
                        b.Append("&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)");
                        i++;
                        goto Label_0186;

                    case '"':
                    case '“':
                    case '”':
                    case 65282:
                        this.EnsureInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append(ch);
                        b.Append(ch);
                        goto Label_0186;

                    case '\0':
                        this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append("&Global.Microsoft.VisualBasic.ChrW(0)");
                        goto Label_0186;

                    case '\u2028':
                    case '\u2029':
                        this.EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        AppendEscapedChar(b, ch);
                        goto Label_0186;

                    default:
                        this.EnsureInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append(value[i]);
                        goto Label_0186;
                }
                b.Append("&Global.Microsoft.VisualBasic.ChrW(13)");
            Label_0186:
                if ((i > 0) && ((i % 80) == 0))
                {
                    if ((char.IsHighSurrogate(value[i]) && (i < (value.Length - 1))) && char.IsLowSurrogate(value[i + 1]))
                    {
                        b.Append(value[++i]);
                    }
                    if (fInDoubleQuotes)
                    {
                        b.Append("\"");
                    }
                    fInDoubleQuotes = true;
                    b.Append("& _ ");
                    b.Append(Environment.NewLine);
                    b.Append(indentation.IndentationString);
                    b.Append('"');
                }
            }
            if (fInDoubleQuotes)
            {
                b.Append("\"");
            }
            return b.ToString();
        }
        /// <devdoc>
        ///    <para>
        ///       Provides conversion to formatting with escape codes.
        ///    </para>
        /// </devdoc>
        protected override string QuoteSnippetString(string value) {
            StringBuilder b = new StringBuilder(value.Length+5);

            bool fInDoubleQuotes = true;
            Indentation indentObj = new Indentation((IndentedTextWriter)Output, Indent + 1);

            b.Append("\"");

            int i = 0;
            while(i < value.Length) {
                char ch = value[i];
                switch (ch) {
                    case '\"':
                    // These are the inward sloping quotes used by default in some cultures like CHS. 
                    // VBC.EXE does a mapping ANSI that results in it treating these as syntactically equivalent to a
                    // regular double quote.
                    case '\u201C': 
                    case '\u201D':
                    case '\uFF02':
                        EnsureInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append(ch);
                        b.Append(ch);
                        break;
                    case '\r':
                        EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        if (i < value.Length - 1 && value[i+1] == '\n') {
                            b.Append("&Global.Microsoft.VisualBasic.ChrW(13)&Global.Microsoft.VisualBasic.ChrW(10)");
                            i++;
                        }
                        else {
                            b.Append("&Global.Microsoft.VisualBasic.ChrW(13)");
                        }
                        break;
                    case '\t':
                        EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append("&Global.Microsoft.VisualBasic.ChrW(9)");
                        break;
                    case '\0':
                        EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append("&Global.Microsoft.VisualBasic.ChrW(0)");
                        break;
                    case '\n':
                        EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append("&Global.Microsoft.VisualBasic.ChrW(10)");
                        break;
                    case '\u2028':
                    case '\u2029':
                        EnsureNotInDoubleQuotes(ref fInDoubleQuotes, b);
                        AppendEscapedChar(b,ch);
                        break;
                    default:
                        EnsureInDoubleQuotes(ref fInDoubleQuotes, b);
                        b.Append(value[i]);
                        break;
                }

                if (i > 0 && i % MaxLineLength == 0) {
                    //
                    // If current character is a high surrogate and the following 
                    // character is a low surrogate, don't break them. 
                    // Otherwise when we write the string to a file, we might lose 
                    // the characters.
                    // 
                    if( Char.IsHighSurrogate(value[i])
                        && (i < value.Length -1) 
                        && Char.IsLowSurrogate(value[i+1])){ 
                        b.Append(value[++i]);    
                    }
                                        
                    if (fInDoubleQuotes)
                        b.Append("\"");
                    fInDoubleQuotes = true;

                    b.Append("& _ ");
                    b.Append(Environment.NewLine);                    
                    b.Append(indentObj.IndentationString);
                    b.Append('\"');
                }
                ++i;
            }

            if (fInDoubleQuotes)
                b.Append("\"");

            return b.ToString();
        }
        /// <devdoc>
        ///    <para>
        ///       Provides conversion to C-style formatting with escape codes.
        ///    </para>
        /// </devdoc>
        private string QuoteSnippetStringCStyle(string value) {
            StringBuilder b = new StringBuilder(value.Length+5);
            Indentation indentObj = new Indentation((IndentedTextWriter)Output, Indent + 1);

            b.Append("\"");

            int i = 0;
            while(i < value.Length) {
                switch (value[i]) {
                    case '\r':
                        b.Append("\\r");
                        break;
                    case '\t':
                        b.Append("\\t");
                        break;
                    case '\"':
                        b.Append("\\\"");
                        break;
                    case '\'':
                        b.Append("\\\'");
                        break;
                    case '\\':
                        b.Append("\\\\");
                        break;
                    case '\0':
                        b.Append("\\0");
                        break;
                    case '\n':
                        b.Append("\\n");
                        break;
                    case '\u2028':
                    case '\u2029':
                        AppendEscapedChar(b,value[i]);
                        break;

                    default:
                        b.Append(value[i]);
                        break;
                }
                
                if (i > 0 && i % MaxLineLength == 0) {
                    //
                    // If current character is a high surrogate and the following 
                    // character is a low surrogate, don't break them. 
                    // Otherwise when we write the string to a file, we might lose 
                    // the characters.
                    // 
                    if( Char.IsHighSurrogate(value[i])
                        && (i < value.Length -1) 
                        && Char.IsLowSurrogate(value[i+1])){ 
                        b.Append(value[++i]);    
                    }
                    
                    b.Append("\" +\r\n");
                    b.Append(indentObj.IndentationString);
                    b.Append('\"');
                }
                ++i;
            }

            b.Append("\"");

            return b.ToString();
        }
        private string QuoteSnippetStringCStyle(string value)
        {
            StringBuilder b = new StringBuilder(value.Length + 5);
            Indentation indentation = new Indentation((IndentedTextWriter) this.Output, this.Indent + 1);
            b.Append("\"");
            for (int i = 0; i < value.Length; i++)
            {
                switch (value[i])
                {
                    case '\u2028':
                    case '\u2029':
                        this.AppendEscapedChar(b, value[i]);
                        break;

                    case '\\':
                        b.Append(@"\\");
                        break;

                    case '\'':
                        b.Append(@"\'");
                        break;

                    case '\t':
                        b.Append(@"\t");
                        break;

                    case '\n':
                        b.Append(@"\n");
                        break;

                    case '\r':
                        b.Append(@"\r");
                        break;

                    case '"':
                        b.Append("\\\"");
                        break;

                    case '\0':
                        b.Append(@"\0");
                        break;

                    default:
                        b.Append(value[i]);
                        break;
                }
                if ((i > 0) && ((i % 80) == 0))
                {
                    if ((char.IsHighSurrogate(value[i]) && (i < (value.Length - 1))) && char.IsLowSurrogate(value[i + 1]))
                    {
                        b.Append(value[++i]);
                    }
                    b.Append("\" +");
                    b.Append(Environment.NewLine);
                    b.Append(indentation.IndentationString);
                    b.Append('"');
                }
            }
            b.Append("\"");
            return b.ToString();
        }