/// <summary> /// Event is called by the tokenizer when a content-encoding meta tag is found. We should just always return true. /// </summary> /// /// <param name="sender"> /// The tokenizer /// </param> /// <param name="e"> /// Encoding detected event information. /// </param> private void tokenizer_EncodingDeclared(object sender, EncodingDetectedEventArgs e) { Encoding encoding; bool accept = false; try { encoding = Encoding.GetEncoding(e.Encoding); } catch { // when an invalid encoding is detected just ignore. encoding = null; } if (encoding!=null && !encoding.Equals(charSetEncoding)) { accept = true; charSetEncoding = encoding; reEncode = true; } e.AcceptEncoding = accept; }
// ]NOCPP] public bool InternalEncodingDeclaration(string internalCharset) { bool accept = false; if (EncodingDeclared != null) { foreach (var inv in EncodingDeclared.GetInvocationList()) { var args = new EncodingDetectedEventArgs(internalCharset); inv.DynamicInvoke(this, args); if (args.AcceptEncoding) accept = true; } } return accept; }
/// <summary> /// Event is called by the tokenizer when a content-encoding meta tag is found. We should just always return true. /// </summary> /// /// <param name="sender"> /// The tokenizer /// </param> /// <param name="e"> /// Encoding detected event information. /// </param> private void tokenizer_EncodingDeclared(object sender, EncodingDetectedEventArgs e) { // if we can't actually reset the document because more than the buffer has been read already, just ignore it if (activeStream.CanRead && activeStream.Position > preprocessorBlockSize) { e.AcceptEncoding = false; return; } bool accept = false; Encoding encoding; try { encoding = Encoding.GetEncoding(e.Encoding); } catch { // when an invalid encoding is detected just ignore. encoding = null; } if (encoding!=null && !encoding.Equals(charSetEncoding)) { accept = true; charSetEncoding = encoding; reEncode = true; } e.AcceptEncoding = accept; }
/// <summary> /// Event is called by the tokenizer when a content-encoding meta tag is found. We should just always return true. /// </summary> /// /// <param name="sender"> /// The tokenizer /// </param> /// <param name="e"> /// Encoding detected event information. /// </param> private void tokenizer_EncodingDeclared(object sender, EncodingDetectedEventArgs e) { Encoding encoding; try { encoding = Encoding.GetEncoding(e.Encoding); } catch { // when an invalid encoding is detected just ignore. return; } bool accept = false; // only accept new encodings from meta if there has been no encoding identified already if (encoding != null && ActiveEncoding==null) { accept = true; ActiveEncoding = encoding; // when CanRead & CanSeek then it means we can and should restart the stream. If outside of 1K // then it's illegal, don't actually restart, just change encoding midstream. if (!AlreadyReEncoded && ActiveStreamOffset < preprocessorBlockBytes) { ReEncode = ReEncodeAction.ReEncode; accept = true; } else { ReEncode = ReEncodeAction.ChangeEncoding; accept = false; } } e.AcceptEncoding = accept; }
/// <summary> /// Event is called by the tokenizer when a content-encoding meta tag is found. We should just always return true. /// </summary> /// /// <param name="sender"> /// The tokenizer /// </param> /// <param name="e"> /// Encoding detected event information. /// </param> private void tokenizer_EncodingDeclared(object sender, EncodingDetectedEventArgs e) { Encoding encoding; try { encoding = Encoding.GetEncoding(e.Encoding); } catch { // when an invalid encoding is detected just ignore. return; } // if we can't actually reset the document because more than the buffer has been read already, just ignore it //if (activeStream.CanRead && activeStream.Position > preprocessorBlockSize) //{ // e.AcceptEncoding = false; // return; //} bool accept = false; if (encoding != null && !encoding.Equals(ActiveEncoding)) { accept = true; ActiveEncoding = encoding; // when CanRead & CanSeek then it means we can and should restart the stream. If outside of 1K // then it's illegal, don't actually restart, just change encoding midstream. if (!AlreadyReEncoded && ActiveStreamOffset < preprocessorBlockSize) { ReEncode = ReEncodeAction.ReEncode; accept = true; } else { ReEncode = ReEncodeAction.ChangeEncoding; accept = false; } } e.AcceptEncoding = accept; }