public void SimpleReader()
 {
     using (var s = new StringReader("<foo>\n</foo>"))
         using (var encoder = new XmlTextEncoder(s)) {
             Assert.AreEqual("&lt;foo&gt;\n&lt;/foo&gt;", encoder.ReadToEnd());
         }
 }
 public void ErrorOnIllegalChars()
 {
     using (var s = new StringReader("\x000B"))
         using (var encoder = new XmlTextEncoder(s, filterIllegalChars: false)) {
             Assert.Throws(typeof(ArgumentException), () => encoder.ReadToEnd());
         }
 }
示例#3
0
        private void ProcessXText(XText xtext, StringBuilder sb, bool performReplacements)
        {
            //.NET likes to just drop out some of the formatting, specially the &quot; which becomes normal old double quotes.
            var correctedText = XmlTextEncoder.Encode(xtext.Value);
            var newvalue      = performReplacements ? Replace(correctedText) : correctedText;

            sb.Append(newvalue);
        }
        public void Scalability()
        {
            const int count = 1 << 16;

            Assert.AreEqual(
                "&amp;".Length * count,
                XmlTextEncoder.Encode(String.Empty.PadRight(count, '&')).Length);
        }
        public void IllegalChars()
        {
            var s = "foo";

            Assert.AreEqual(
                s,
                XmlTextEncoder.Encode(String.Format("\u0000\u0001\u000b{0}\u000e\u007f\u0086\uFFFE", s)));
        }
 public void EntityStrings()
 {
     Assert.AreEqual("&lt;foo /&gt;", XmlTextEncoder.Encode("<foo />"));
     Assert.AreEqual(
         "&lt;foo bar=&quot;baz&quot;&gt;&lt;/foo&gt;",
         XmlTextEncoder.Encode("<foo bar=\"baz\"></foo>"));
     Assert.AreEqual("&apos;&amp;&apos;", XmlTextEncoder.Encode("'&'"));
 }
        public void SimpleStrings()
        {
            Assert.AreEqual(String.Empty, XmlTextEncoder.Encode(String.Empty));

            var s = "foo\nbar";

            Assert.AreEqual(s, XmlTextEncoder.Encode(s));
        }
示例#8
0
        public string Parse(string input)
        {
            string trimmedInput = TrimBlankLines(input);

            trimmedInput = TrimUnessecaryIndents(trimmedInput);

            //TODO: remove all the leading whitespace.

            var encoded = XmlTextEncoder.Encode(trimmedInput);
            var sb      = new StringBuilder();

            sb.AppendLine("<div class=\"csharpcode\">");
            sb.AppendLine(encoded);
            sb.Append("</div>");
            return(sb.ToString());
        }
 internal XmlTextWriterBase64Encoder(XmlTextEncoder xmlTextEncoder)
 {
     this.xmlTextEncoder = xmlTextEncoder;
 }
示例#10
0
 private void Init()
 {
     buffer  = new StringBuilder();
     encoder = new XmlTextEncoder(new StringWriter(buffer), Encoding.Unicode);
 }
示例#11
0
 private static string Escape(char ch)
 {
     return(XmlTextEncoder.Encode(new string(ch, 1)));
 }
示例#12
0
 private void Init()
 {
     buffer  = new StringBuilder();
     encoder = new XmlTextEncoder(new StringWriter(buffer, CultureInfo.InvariantCulture));
 }
 public void IllegalSurrogates()
 {
     Assert.AreEqual(String.Empty, XmlTextEncoder.Encode("\xD834"));
     Assert.AreEqual(String.Empty, XmlTextEncoder.Encode("\xDD1E"));
     Assert.AreEqual("foobar", XmlTextEncoder.Encode("foo\xDD1E\xD834bar"));
 }
        public void LegalSurrogates()
        {
            var s = "foo\xD834\xDD1Ebar";

            Assert.AreEqual(s, XmlTextEncoder.Encode(s));
        }