/// <summary> /// Instantiates an encoder using a custom code point filter. Any character not in the /// set returned by <paramref name="filter"/>'s <see cref="ICodePointFilter.GetAllowedCodePoints"/> /// method will be escaped. /// </summary> public HtmlEncoder(ICodePointFilter filter) : this(new HtmlUnicodeEncoder(CodePointFilter.Wrap(filter))) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } }
/// <summary> /// Instantiates an encoder using a custom code point filter. Any character not in the /// set returned by <paramref name="filter"/>'s <see cref="ICodePointFilter.GetAllowedCodePoints"/> /// method will be escaped. /// </summary> public JavaScriptStringEncoder(ICodePointFilter filter) : this(new JavaScriptStringUnicodeEncoder(CodePointFilter.Wrap(filter))) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } }
/// <summary> /// Instantiates the filter by cloning the allow list of another <see cref="ICodePointFilter"/>. /// </summary> public CodePointFilter(ICodePointFilter other) { CodePointFilter otherAsCodePointFilter = other as CodePointFilter; if (otherAsCodePointFilter != null) { _allowedCharactersBitmap = otherAsCodePointFilter.GetAllowedCharacters(); } else { _allowedCharactersBitmap = AllowedCharactersBitmap.CreateNew(); AllowFilter(other); } }
/// <summary> /// Allows all characters specified by <paramref name="filter"/> through the filter. /// </summary> /// <returns> /// The 'this' instance. /// </returns> public CodePointFilter AllowFilter([NotNull] ICodePointFilter filter) { foreach (var allowedCodePoint in filter.GetAllowedCodePoints()) { // If the code point can't be represented as a BMP character, skip it. char codePointAsChar = (char)allowedCodePoint; if (allowedCodePoint == codePointAsChar) { _allowedCharsBitmap.AllowCharacter(codePointAsChar); } } return(this); }
/// <summary> /// Allows all characters specified by <paramref name="filter"/> through the filter. /// </summary> /// <returns> /// The 'this' instance. /// </returns> public CodePointFilter AllowFilter(ICodePointFilter filter) { if (filter == null) { throw new ArgumentNullException("filter"); } foreach (var allowedCodePoint in filter.GetAllowedCodePoints()) { // If the code point can't be represented as a BMP character, skip it. char codePointAsChar = (char)allowedCodePoint; if (allowedCodePoint == codePointAsChar) { _allowedCharactersBitmap.AllowCharacter(codePointAsChar); } } return(this); }
/// <summary> /// Instantiates the filter by cloning the allow list of another <see cref="ICodePointFilter"/>. /// </summary> public CodePointFilter(ICodePointFilter other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } CodePointFilter otherAsCodePointFilter = other as CodePointFilter; if (otherAsCodePointFilter != null) { _allowedCharsBitmap = otherAsCodePointFilter.GetAllowedCharsBitmap(); } else { _allowedCharsBitmap = AllowedCharsBitmap.CreateNew(); AllowFilter(other); } }
/// <summary> /// Instantiates an encoder using a custom code point filter. Any character not in the /// set returned by <paramref name="filter"/>'s <see cref="ICodePointFilter.GetAllowedCodePoints"/> /// method will be escaped. /// </summary> public HtmlEncoderOld(ICodePointFilter filter) : this(new HtmlUnicodeEncoder(CodePointFilter.Wrap(filter))) { }
/// <summary> /// Instantiates an encoder using a custom code point filter. Any character not in the /// set returned by <paramref name="filter"/>'s <see cref="ICodePointFilter.GetAllowedCodePoints"/> /// method will be escaped. /// </summary> public JavaScriptStringEncoderOld(ICodePointFilter filter) : this(new JavaScriptStringUnicodeEncoder(CodePointFilter.Wrap(filter))) { }
/// <summary> /// Wraps the provided filter as a CodePointFilter, avoiding the clone if possible. /// </summary> internal static CodePointFilter Wrap(ICodePointFilter filter) { return (filter as CodePointFilter) ?? new CodePointFilter(filter); }
/// <summary> /// Allows all characters specified by <paramref name="filter"/> through the filter. /// </summary> /// <returns> /// The 'this' instance. /// </returns> public CodePointFilter AllowFilter(ICodePointFilter filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } foreach (var allowedCodePoint in filter.GetAllowedCodePoints()) { // If the code point can't be represented as a BMP character, skip it. char codePointAsChar = (char)allowedCodePoint; if (allowedCodePoint == codePointAsChar) { _allowedCharsBitmap.AllowCharacter(codePointAsChar); } } return this; }
/// <summary> /// Wraps the provided filter as a CodePointFilter, avoiding the clone if possible. /// </summary> internal static CodePointFilter Wrap(ICodePointFilter filter) { return((filter as CodePointFilter) ?? new CodePointFilter(filter)); }
/// <summary> /// Instantiates an encoder using a custom code point filter. Any character not in the /// set returned by <paramref name="filter"/>'s <see cref="ICodePointFilter.GetAllowedCodePoints"/> /// method will be escaped. /// </summary> public UrlEncoder([NotNull] ICodePointFilter filter) : this(new UrlUnicodeEncoder(CodePointFilter.Wrap(filter))) { }