private void WriteHtmlUri(string value) {
Debug.Assert(value != null);
Debug.Assert(this.isHtmlOutput);
int length = value.Length;
int i = 0;
while(i < length) {
char ch = value[i];
i ++;
switch (ch) {
case '&':
if(i != length && value[i] == '{') { // &{ hasn't to be encoded in HTML output.
Write(ch);
}
else {
Write(s_EnAmpersand);
}
break;
case '"':
Write(s_EnQuote);
break;
case '\n':
Write(s_EnNewLine);
break;
case '\r':
Write(s_EnReturn);
break;
default:
if(127 < ch) {
if (this.utf8Encoding == null) {
this.utf8Encoding = Encoding.UTF8;
this.byteBuffer = new byte[utf8Encoding.GetMaxByteCount(1)];
}
int bytes = this.utf8Encoding.GetBytes(value, i - 1, 1, this.byteBuffer, 0);
for(int j = 0; j < bytes; j ++) {
Write("%");
Write(((uint)this.byteBuffer[j]).ToString("X2", CultureInfo.InvariantCulture));
}
}
else {
Write(ch);
}
break;
}
}
}