System.Diagnostics.Tests.FileVersionInfoTest.GetUnicodeString C# (CSharp) Method

GetUnicodeString() static private method

static private GetUnicodeString ( String str ) : string
str String
return string
        static string GetUnicodeString(String str)
        {
            if (str == null)
                return "<null>";

            StringBuilder buffer = new StringBuilder();
            buffer.Append("\"");
            for (int i = 0; i < str.Length; i++)
            {
                char ch = str[i];
                if (ch == '\r')
                {
                    buffer.Append("\\r");
                }
                else if (ch == '\n')
                {
                    buffer.Append("\\n");
                }
                else if (ch == '\\')
                {
                    buffer.Append("\\");
                }
                else if (ch == '\"')
                {
                    buffer.Append("\\\"");
                }
                else if (ch == '\'')
                {
                    buffer.Append("\\\'");
                }
                else if (ch < 0x20 || ch >= 0x7f)
                {
                    buffer.Append("\\u");
                    buffer.Append(((int)ch).ToString("x4"));
                }
                else
                {
                    buffer.Append(ch);
                }
            }
            buffer.Append("\"");
            return (buffer.ToString());
        }