System.Globalization.Tests.Unicode_Win7_IdnaTest.EscapedToLiteralString C# (CSharp) Method

EscapedToLiteralString() private static method

This will convert strings with escaped sequences to literal characters. The input string is expected to have escaped sequences in the form of '\uXXXX'. Example: "a\u0020b" will be converted to 'a b'.
private static EscapedToLiteralString ( string escaped, int lineNumber ) : string
escaped string
lineNumber int
return string
        private static string EscapedToLiteralString(string escaped, int lineNumber)
        {
            var sb = new StringBuilder();

            for (int i = 0; i < escaped.Length; i++)
            {
                if (i + 1 < escaped.Length && escaped[i] == '\\' && escaped[i + 1] == 'u')
                {
                    // Verify that the escaped sequence is not malformed
                    Assert.True(i + 5 < escaped.Length, $"There was a problem converting to literal string on Line {lineNumber}");

                    var codepoint = Convert.ToInt32(escaped.Substring(i + 2, 4), 16);
                    sb.Append((char)codepoint);
                    i += 5;
                }
                else
                {
                    sb.Append(escaped[i]);
                }
            }

            return sb.ToString().Trim();
        }
    }