Ejemplo n.º 1
0
 public static unsafe int FindFirstCharacterToEncode(this HtmlEncoder htmlEncoder, string s, int start)
 {
     fixed(char *t = s)
     {
         return(htmlEncoder.FindFirstCharacterToEncode(t + start, s.Length - start));
     }
 }
Ejemplo n.º 2
0
        public async Task Write(string s)
        {
            var position = 0;

            while (position < s.Length)
            {
                var safeChunkLength = _htmlEncoder.FindFirstCharacterToEncode(s, position);
                if (safeChunkLength == -1)  // no encoding chars in the input, write the whole string without encoding
                {
                    safeChunkLength = s.Length - position;
                }

                await WriteRawImpl(s, position, safeChunkLength).ConfigureAwait(false);

                position += safeChunkLength;

                if (position < s.Length)
                {
                    // we're now looking at an HTML-encoding character
                    position = await WriteEncodingChars(s, position).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 3
0
        public void Write(string s)
        {
            fixed(char *str = s)
            {
                var start = str;
                var end   = str + s.Length;

                while (start < end)
                {
                    var len             = (int)(end - start);
                    var safeChunkLength = _htmlEncoder.FindFirstCharacterToEncode(start, len);
                    if (safeChunkLength == -1)  // no encoding chars in the input, write the whole string without encoding
                    {
                        safeChunkLength = len;
                    }

                    WriteRawImpl(ref start, start + safeChunkLength);

                    // we're now looking at an HTML-encoding character
                    WriteEncodingChars(ref start, end);
                }
            }
        }