Пример #1
0
        public void TestGetUnicodeCodeFromChar()
        {
            char[] c1 = UnicodeUtil.GetUnicodeHexCodeFromChar('0');
            System.Diagnostics.Debug.WriteLine("c1 = " + String.Join(",", c1));
            // Assert.AreEqual("\\u0030".toCharArray(), c1);

            char[] c2 = UnicodeUtil.GetUnicodeHexCodeFromChar('a');
            System.Diagnostics.Debug.WriteLine("c2 = " + String.Join(",", c2));
            // Assert.AreEqual("".toCharArray(), c2);
        }
Пример #2
0
        private void _appendEscapedString(TextWriter writer, string primStr)
        {
            int escapeForwardSlash = builderPolicy.EscapeForwardSlash;

            if (!string.ReferenceEquals(primStr, null) && primStr.Length > 0)
            {
                char[] primChars = primStr.ToCharArray();
                char   prevEc    = (char)0;
                foreach (char ec in primChars)
                {
                    if (Symbols.IsEscapedChar(ec))
                    {
                        if (prevEc == '<' && ec == '/')
                        {
                            if (escapeForwardSlash >= 0)
                            {
                                writer.Write("\\/");
                            }
                            else
                            {
                                writer.Write("/");
                            }
                            // } else if(prevEc == '\\' && ec == '\\') {
                            //     // Already escaped... ????
                            //     // Skip ???
                        }
                        else
                        {
                            string str = Symbols.GetEscapedCharString(ec, escapeForwardSlash > 0 ? true : false);
                            if (!string.ReferenceEquals(str, null))
                            {
                                writer.Write(str);
                            }
                            else
                            {
                                // ???
                                writer.Write(ec);
                            }
                        }
                    }
                    else if (CharUtil.IsISOControl(ec))
                    {
                        char[] uc = UnicodeUtil.GetUnicodeHexCodeFromChar(ec);
                        writer.Write(uc);
                    }
                    else
                    {
                        writer.Write(ec);
                    }
                    prevEc = ec;
                }
            }
        }
Пример #3
0
        private string _escapeString(string primStr)
        {
            StringBuilder sb = new StringBuilder();

            if (!string.ReferenceEquals(primStr, null) && primStr.Length > 0)
            {
                char[] primChars = primStr.ToCharArray();
                char   prevEc    = (char)0;
                foreach (char ec in primChars)
                {
                    if (Symbols.IsEscapedChar(ec))
                    {
                        if (prevEc == '<' && ec == '/')
                        {
                            sb.Append("\\/");
                        }
                        else
                        {
                            string str = Symbols.GetEscapedCharString(ec, false);
                            if (!string.ReferenceEquals(str, null))
                            {
                                sb.Append(str);
                            }
                            else
                            {
                                // ???
                                sb.Append(ec);
                            }
                        }
                    }
                    else if (CharUtil.IsISOControl(ec))
                    {
                        char[] uc = UnicodeUtil.GetUnicodeHexCodeFromChar(ec);
                        sb.Append(uc);
                    }
                    else
                    {
                        sb.Append(ec);
                    }
                    prevEc = ec;
                }
            }
            return(sb.ToString());
        }
Пример #4
0
 // private static readonly int escapeForwardSlash = -1;
 private async void _AppendEscapedString(TextWriter writer, string primStr)
 {
     if (primStr != null && primStr.Length > 0)
     {
         char[] primChars = primStr.ToCharArray();
         // char prevEc = 0;
         foreach (char ec in primChars)
         {
             if (Symbols.IsEscapedChar(ec))
             {
                 // if(prevEc == '<' && ec == '/') {
                 //     // if(escapeForwardSlash >= 0) {
                 //     //     await writer.WriteAsync("\\/");
                 //     // } else {
                 //         await writer.WriteAsync("/");
                 //     // }
                 // } else {
                 // string str = Symbols.GetEscapedCharString(ec, escapeForwardSlash > 0 ? true : false);
                 string str = Symbols.GetEscapedCharString(ec, false);
                 if (str != null)
                 {
                     await writer.WriteAsync(str);
                 }
                 else
                 {
                     // ???
                     await writer.WriteAsync(ec);
                 }
                 // }
             }
             else if (CharUtil.IsISOControl(ec))
             {
                 char[] uc = UnicodeUtil.GetUnicodeHexCodeFromChar(ec);
                 await writer.WriteAsync(uc);
             }
             else
             {
                 await writer.WriteAsync(ec);
             }
             // prevEc = ec;
         }
     }
 }