static void HtmlAttributeEncode (TextWriter output, ICharArray value, int startIndex, int count, char quote = '"') { int endIndex = startIndex + count; int index; index = IndexOfHtmlEncodeAttributeChar (value, startIndex, endIndex, quote); output.Write (quote); if (index == endIndex) { value.Write (output, startIndex, count); output.Write (quote); return; } if (index > startIndex) value.Write (output, startIndex, index - startIndex); while (index < endIndex) { char c = value[index++]; int unichar; switch (c) { case '\t': case '\r': case '\n': case '\f': output.Write (c); break; case '\'': output.Write (c == quote ? "'" : "'"); break; case '"': output.Write (c == quote ? """ : "\""); break; case '&': output.Write ("&"); break; case '<': output.Write ("<"); break; case '>': output.Write (">"); break; default: if (c < 32 || (c >= 127 && c < 160)) { // illegal control character break; } if (c > 255 && char.IsSurrogate (c)) { if (index + 1 < endIndex && char.IsSurrogatePair (c, value[index])) { unichar = char.ConvertToUtf32 (c, value[index]); index++; } else { unichar = c; } } else if (c >= 160) { // 160-255 and non-surrogates unichar = c; } else { // SPACE and other printable (safe) ASCII output.Write (c); break; } output.Write (string.Format (CultureInfo.InvariantCulture, "&#{0};", unichar)); break; } } output.Write (quote); }
static void HtmlEncodeAttribute(TextWriter output, ICharArray value, int startIndex, int count, char quote = '"') { int endIndex = startIndex + count; int index; index = IndexOfHtmlEncodeAttributeChar(value, startIndex, endIndex, quote); output.Write(quote); if (index == endIndex) { value.Write(output, startIndex, count); output.Write(quote); return; } if (index > startIndex) value.Write(output, startIndex, index - startIndex); while (index < endIndex) { char c = value[index++]; int unichar, nextIndex; switch (c) { case '\t': case '\r': case '\n': case '\f': output.Write(c); break; case '\'': output.Write(c == quote ? "'" : "'"); break; case '"': output.Write(c == quote ? """ : "\""); break; case '&': output.Write("&"); break; case '<': output.Write("<"); break; case '>': output.Write(">"); break; default: if (c < 32 || (c >= 127 && c < 160)) { // illegal control character break; } if (c > 255 && char.IsSurrogate(c)) { if (index + 1 < endIndex && char.IsSurrogatePair(c, value[index])) { unichar = char.ConvertToUtf32(c, value[index]); index++; } else { unichar = c; } } else if (c >= 160) { // 160-255 and non-surrogates unichar = c; } else { // SPACE and other printable (safe) ASCII output.Write(c); break; } output.Write(string.Format(CultureInfo.InvariantCulture, "&#{0};", unichar)); break; } if (index >= endIndex) break; if ((nextIndex = IndexOfHtmlEncodeAttributeChar(value, index, endIndex, quote)) > index) { value.Write(output, index, nextIndex - index); index = nextIndex; } } output.Write(quote); }
static void HtmlEncode (TextWriter output, ICharArray data, int startIndex, int count) { int endIndex = startIndex + count; int index; index = IndexOfHtmlEncodeChar (data, startIndex, endIndex); if (index > startIndex) data.Write (output, startIndex, index - startIndex); while (index < endIndex) { char c = data[index++]; int unichar; switch (c) { case '\t': case '\r': case '\n': case '\f': output.Write (c); break; case '\'': output.Write ("'"); break; case '"': output.Write ("""); break; case '&': output.Write ("&"); break; case '<': output.Write ("<"); break; case '>': output.Write (">"); break; default: if (c < 32 || (c >= 127 && c < 160)) { // illegal control character break; } if (c > 255 && char.IsSurrogate (c)) { if (index + 1 < endIndex && char.IsSurrogatePair (c, data[index])) { unichar = char.ConvertToUtf32 (c, data[index]); index++; } else { unichar = c; } } else if (c >= 160) { // 160-255 and non-surrogates unichar = c; } else { // SPACE and other printable (safe) ASCII output.Write (c); break; } output.Write (string.Format (CultureInfo.InvariantCulture, "&#{0};", unichar)); break; } } }
static void HtmlEncode(TextWriter output, ICharArray data, int startIndex, int count) { int endIndex = startIndex + count; int index; index = IndexOfHtmlEncodeChar(data, startIndex, endIndex); if (index > startIndex) { data.Write(output, startIndex, index - startIndex); } while (index < endIndex) { char c = data[index++]; int unichar, nextIndex; switch (c) { case '\t': case '\r': case '\n': case '\f': output.Write(c); break; case '\'': output.Write("'"); break; case '"': output.Write("""); break; case '&': output.Write("&"); break; case '<': output.Write("<"); break; case '>': output.Write(">"); break; default: if (c < 32 || (c >= 127 && c < 160)) { // illegal control character break; } if (c > 255 && char.IsSurrogate(c)) { if (index + 1 < endIndex && char.IsSurrogatePair(c, data[index])) { unichar = char.ConvertToUtf32(c, data[index]); index++; } else { unichar = c; } } else if (c >= 160) { // 160-255 and non-surrogates unichar = c; } else { // SPACE and other printable (safe) ASCII output.Write(c); break; } output.Write(string.Format(CultureInfo.InvariantCulture, "&#{0};", unichar)); break; } if (index >= endIndex) { break; } if ((nextIndex = IndexOfHtmlEncodeChar(data, index, endIndex)) > index) { data.Write(output, index, nextIndex - index); index = nextIndex; } } }
static void HtmlEncodeAttribute(TextWriter output, ICharArray value, int startIndex, int count, char quote = '"') { int endIndex = startIndex + count; int index; index = IndexOfHtmlEncodeAttributeChar(value, startIndex, endIndex, quote); output.Write(quote); if (index == endIndex) { value.Write(output, startIndex, count); output.Write(quote); return; } if (index > startIndex) { value.Write(output, startIndex, index - startIndex); } while (index < endIndex) { char c = value[index++]; int nextIndex; switch (c) { case '\'': if (c == quote) { output.Write("'"); } else { output.Write(c); } break; case '"': if (c == quote) { output.Write("""); } else { output.Write(c); } break; case '&': output.Write("&"); break; case '<': output.Write("<"); break; case '>': output.Write(">"); break; default: output.Write(c); break; } if (index >= endIndex) { break; } if ((nextIndex = IndexOfHtmlEncodeAttributeChar(value, index, endIndex, quote)) > index) { value.Write(output, index, nextIndex - index); index = nextIndex; } } output.Write(quote); }
static void HtmlEncode(TextWriter output, ICharArray data, int startIndex, int count) { int endIndex = startIndex + count; int index; index = IndexOfHtmlEncodeChar(data, startIndex, endIndex); if (index > startIndex) { data.Write(output, startIndex, index - startIndex); } while (index < endIndex) { char c = data[index++]; int unichar, nextIndex; switch (c) { case '\'': output.Write("'"); break; case '"': output.Write("""); break; case '&': output.Write("&"); break; case '<': output.Write("<"); break; case '>': output.Write(">"); break; default: if (c >= 160 && c < 256) { unichar = c; } else if (char.IsSurrogate(c)) { if (index + 1 < endIndex && char.IsSurrogatePair(c, data[index])) { unichar = char.ConvertToUtf32(c, data[index]); index++; } else { unichar = c; } } else { output.Write(c); break; } output.Write(string.Format(CultureInfo.InvariantCulture, "&#{0};", unichar)); break; } if (index >= endIndex) { break; } if ((nextIndex = IndexOfHtmlEncodeChar(data, index, endIndex)) > index) { data.Write(output, index, nextIndex - index); index = nextIndex; } } }