MongoDBDriver/Util/JsonUtils.cs
/// <summary>
/// Escapes any characters that are special to javascript.
/// </summary>
Escapes any characters that are special to javascript.
Escapes any characters that are special to javascript .
public static string Escape(string text){
            StringBuilder sb = new StringBuilder();
            foreach(char c in text){
                switch(c){
                    case '\b':
                        sb.Append(@"\b");
                        break;
                    case '\f':
                        sb.Append(@"\f");
                        break;
                    case '\n':
                        sb.Append(@"\n");
                        break;
                    case '\r':
                        sb.Append(@"\r");
                        break;
                    case '\t':
                        sb.Append(@"\t");
                        break;
                    case '\v':
                        sb.Append(@"\v");
                        break;
                    case '\'':
                        sb.Append(@"\'");
                        break;
                    case '"':
                        sb.Append("\\\"");
                        break;
                    case '\\':
                        sb.Append(@"\\");
                        break;
                    default:
                        if(c <= '\u001f'){
                            sb.Append("\\u");
                            sb.Append(((int)c).ToString("x4"));
                        }else{
                            sb.Append(c);
                        }
                        break;
                }
            }
            return sb.ToString();
        }
public static string Escape ( string text ) { StringBuilder sb = new StringBuilder ( ) ; foreach ( char c in text ) { switch ( c ) { case ' \b ' : sb . Append ( @"\b" ) ; break ; case ' \f ' : sb . Append ( @"\f" ) ; break ; case ' \n ' : sb . Append ( @"\n" ) ; break ; case ' \r ' : sb . Append ( @"\r" ) ; break ; case ' \t ' : sb . Append ( @"\t" ) ; break ; case ' \v ' : sb . Append ( @"\v" ) ; break ; case ' \' ' : sb . Append ( @"\'" ) ; break ; case ' ' : sb . Append ( " \\ \" " ) ; break ; case ' \\ ' : sb . Append ( @"\\" ) ; break ; default : if ( c <= ' \u001f ' ) { sb . Append ( " \\ " ) ; sb . Append ( ( ( int ) c ) . ToString ( " " ) ) ; } else { sb . Append ( c ) ; } break ; } } return sb . ToString ( ) ; }
Escapes any characters that are special to javascript.
Escapes any characters that are special to javascript .
text
string