Antlr3.Tool.Grammar.GetUnescapedStringFromGrammarStringLiteral C# (CSharp) Method

GetUnescapedStringFromGrammarStringLiteral() public static method

public static GetUnescapedStringFromGrammarStringLiteral ( string literal ) : System.Text.StringBuilder
literal string
return System.Text.StringBuilder
        public static StringBuilder GetUnescapedStringFromGrammarStringLiteral( string literal )
        {
            //[email protected]("escape: ["+literal+"]");
            StringBuilder buf = new StringBuilder();
            int last = literal.Length - 1; // skip quotes on outside
            for ( int i = 1; i < last; i++ )
            {
                char c = literal[i];
                if ( c == '\\' )
                {
                    i++;
                    c = literal[i];
                    if ( char.ToUpperInvariant( c ) == 'U' )
                    {
                        // \u0000
                        i++;
                        string unicodeChars = literal.Substring( i, 4 );
                        // parse the unicode 16 bit hex value
                        //int val = Integer.parseInt( unicodeChars, 16 );
                        int val = int.Parse( unicodeChars, System.Globalization.NumberStyles.AllowHexSpecifier );
                        i += 4 - 1; // loop will inc by 1; only jump 3 then
                        buf.Append( (char)val );
                    }
                    else if ( char.IsDigit( c ) )
                    {
                        ErrorManager.Error( ErrorManager.MSG_SYNTAX_ERROR,
                                           "invalid char literal: " + literal );
                        buf.Append( "\\" + (char)c );
                    }
                    else
                    {
                        buf.Append( (char)AntlrLiteralEscapedCharValue[c] ); // normal \x escape
                    }
                }
                else
                {
                    buf.Append( c ); // simple char x
                }
            }
            //[email protected]("string: ["+buf.toString()+"]");
            return buf;
        }
Grammar