static int IndexOfHtmlEncodeChar(ICharArray value, int startIndex, int endIndex) { for (int i = startIndex; i < endIndex; i++) { switch (value[i]) { case '\'': case '"': case '&': case '<': case '>': return(i); default: if (value[i] >= 160 && value[i] < 256) { return(i); } if (char.IsSurrogate(value[i])) { return(i); } break; } } return(endIndex); }
static int IndexOfHtmlEncodeAttributeChar(ICharArray value, int startIndex, int endIndex, char quote) { for (int i = startIndex; i < endIndex; i++) { char c = value[i]; switch (c) { case '\t': case '\r': case '\n': case '\f': break; case '&': case '<': case '>': return(i); default: if (c == quote || c < 32 || c >= 127) { return(i); } break; } } return(endIndex); }
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 int IndexOfHtmlEncodeAttributeChar (ICharArray value, int startIndex, int endIndex, char quote) { for (int i = startIndex; i < endIndex; i++) { switch (value[i]) { case '&': case '<': case '>': return i; default: if (value[i] == quote) return i; break; } } return endIndex; }
static int IndexOfHtmlEncodeChar (ICharArray value, int startIndex, int endIndex) { for (int i = startIndex; i < endIndex; i++) { char c = value[i]; switch (c) { case '\t': case '\r': case '\n': case '\f': break; case '\'': case '"': case '&': case '<': case '>': return i; default: if (c < 32 || c >= 127) return i; break; } } return endIndex; }
static int IndexOfHtmlEncodeAttributeChar (ICharArray value, int startIndex, int endIndex, char quote) { for (int i = startIndex; i < endIndex; i++) { char c = value[i]; switch (c) { case '\t': case '\r': case '\n': case '\f': break; case '&': case '<': case '>': return i; default: if (c == quote || c < 32 || c >= 127) return i; break; } } return endIndex; }
static int IndexOfHtmlEncodeAttributeChar(ICharArray value, int startIndex, int endIndex, char quote) { for (int i = startIndex; i < endIndex; i++) { switch (value[i]) { case '&': case '<': case '>': return(i); default: if (value[i] == quote) { return(i); } break; } } return(endIndex); }
/* ** Name: readUCS2 ** ** Description: ** Reads UCS2 characters from the current input message ** into a ICharArray. The array limit is ignored. Any ** characters which exceed the array limit are read and ** discarded. It is the callers responsibility to ** ensure adaquate limit and capacity. ** ** Input: ** length Number of characters. ** ** Output: ** array Filled with characters from message. ** ** Returns: ** int Number of characters actually read. ** ** History: ** 22-Sep-03 (gordy) ** Created. */ public int readUCS2( ICharArray array, int length ) { for( int count = length; count > 0; count-- ) array.put( (char)readShort() ); return( length ); }
private void CompareCharArrays(ICharArray expected, ICharArray actual) { Assert.That(actual, Is.Not.Null); Assert.That(expected.Dimensions, Is.EqualTo(actual.Dimensions)); Assert.That(expected.String, Is.EqualTo(actual.String)); }
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 int IndexOfHtmlEncodeChar(ICharArray value, int startIndex, int endIndex) { for (int i = startIndex; i < endIndex; i++) { switch (value[i]) { case '\'': case '"': case '&': case '<': case '>': return i; default: if (value[i] >= 160 && value[i] < 256) return i; if (char.IsSurrogate(value[i])) return i; break; } } return endIndex; }
/* ** Name: writeUCS2 ** ** Description: ** Append a character sub-array to current output message. ** If buffer overflow would occur, the message (and array) ** is split. ** ** Input: ** value The character array with sub-array to be appended. ** ** Output: ** None. ** ** Returns: ** void ** ** History: ** 1-Dec-03 (gordy) ** Created. */ public void writeUCS2(ICharArray array) { int end = array.valuelength(); for (int position = 0; position < end; position++) write((short)array.get(position)); return; }
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; } } }