@@ -10,7 +10,7 @@ namespace System.Text.Encodings.Web
10
10
/// <summary>
11
11
/// Represents a filter which allows only certain Unicode code points through.
12
12
/// </summary>
13
- public sealed class CodePointFilter : ICodePointFilter
13
+ public class CodePointFilter
14
14
{
15
15
private AllowedCharactersBitmap _allowedCharactersBitmap ;
16
16
@@ -23,20 +23,12 @@ public CodePointFilter()
23
23
}
24
24
25
25
/// <summary>
26
- /// Instantiates the filter by cloning the allow list of another <see cref="ICodePointFilter "/>.
26
+ /// Instantiates the filter by cloning the allow list of another <see cref="CodePointFilter "/>.
27
27
/// </summary>
28
- public CodePointFilter ( ICodePointFilter other )
28
+ public CodePointFilter ( CodePointFilter other )
29
29
{
30
- CodePointFilter otherAsCodePointFilter = other as CodePointFilter ;
31
- if ( otherAsCodePointFilter != null )
32
- {
33
- _allowedCharactersBitmap = otherAsCodePointFilter . GetAllowedCharacters ( ) ;
34
- }
35
- else
36
- {
37
- _allowedCharactersBitmap = AllowedCharactersBitmap . CreateNew ( ) ;
38
- AllowFilter ( other ) ;
39
- }
30
+ _allowedCharactersBitmap = AllowedCharactersBitmap . CreateNew ( ) ;
31
+ AllowFilter ( other ) ;
40
32
}
41
33
42
34
/// <summary>
@@ -56,22 +48,15 @@ public CodePointFilter(params UnicodeRange[] allowedRanges)
56
48
/// <summary>
57
49
/// Allows the character specified by <paramref name="character"/> through the filter.
58
50
/// </summary>
59
- /// <returns>
60
- /// The 'this' instance.
61
- /// </returns>
62
- public CodePointFilter AllowCharacter ( char character )
51
+ public virtual void AllowCharacter ( char character )
63
52
{
64
53
_allowedCharactersBitmap . AllowCharacter ( character ) ;
65
- return this ;
66
54
}
67
55
68
56
/// <summary>
69
57
/// Allows all characters specified by <paramref name="characters"/> through the filter.
70
58
/// </summary>
71
- /// <returns>
72
- /// The 'this' instance.
73
- /// </returns>
74
- public CodePointFilter AllowCharacters ( params char [ ] characters )
59
+ public virtual void AllowCharacters ( params char [ ] characters )
75
60
{
76
61
if ( characters == null )
77
62
{
@@ -82,37 +67,12 @@ public CodePointFilter AllowCharacters(params char[] characters)
82
67
{
83
68
_allowedCharactersBitmap . AllowCharacter ( characters [ i ] ) ;
84
69
}
85
-
86
- return this ;
87
- }
88
-
89
- /// <summary>
90
- /// Allows all characters in the string <paramref name="characters"/> through the filter.
91
- /// </summary>
92
- /// <returns>
93
- /// The 'this' instance.
94
- /// </returns>
95
- public CodePointFilter AllowCharacters ( string characters )
96
- {
97
- if ( characters == null )
98
- {
99
- throw new ArgumentNullException ( "characters" ) ;
100
- }
101
-
102
- for ( int i = 0 ; i < characters . Length ; i ++ )
103
- {
104
- _allowedCharactersBitmap . AllowCharacter ( characters [ i ] ) ;
105
- }
106
- return this ;
107
70
}
108
71
109
72
/// <summary>
110
73
/// Allows all characters specified by <paramref name="filter"/> through the filter.
111
74
/// </summary>
112
- /// <returns>
113
- /// The 'this' instance.
114
- /// </returns>
115
- public CodePointFilter AllowFilter ( ICodePointFilter filter )
75
+ public virtual void AllowFilter ( CodePointFilter filter )
116
76
{
117
77
if ( filter == null )
118
78
{
@@ -128,16 +88,12 @@ public CodePointFilter AllowFilter(ICodePointFilter filter)
128
88
_allowedCharactersBitmap . AllowCharacter ( codePointAsChar ) ;
129
89
}
130
90
}
131
- return this ;
132
91
}
133
92
134
93
/// <summary>
135
94
/// Allows all characters specified by <paramref name="range"/> through the filter.
136
95
/// </summary>
137
- /// <returns>
138
- /// The 'this' instance.
139
- /// </returns>
140
- public CodePointFilter AllowRange ( UnicodeRange range )
96
+ public virtual void AllowRange ( UnicodeRange range )
141
97
{
142
98
if ( range == null )
143
99
{
@@ -150,16 +106,12 @@ public CodePointFilter AllowRange(UnicodeRange range)
150
106
{
151
107
_allowedCharactersBitmap . AllowCharacter ( ( char ) ( firstCodePoint + i ) ) ;
152
108
}
153
- return this ;
154
109
}
155
110
156
111
/// <summary>
157
112
/// Allows all characters specified by <paramref name="ranges"/> through the filter.
158
113
/// </summary>
159
- /// <returns>
160
- /// The 'this' instance.
161
- /// </returns>
162
- public CodePointFilter AllowRanges ( params UnicodeRange [ ] ranges )
114
+ public virtual void AllowRanges ( params UnicodeRange [ ] ranges )
163
115
{
164
116
if ( ranges == null )
165
117
{
@@ -170,62 +122,28 @@ public CodePointFilter AllowRanges(params UnicodeRange[] ranges)
170
122
{
171
123
AllowRange ( ranges [ i ] ) ;
172
124
}
173
-
174
- return this ;
175
125
}
176
126
177
127
/// <summary>
178
128
/// Resets this filter by disallowing all characters.
179
129
/// </summary>
180
- /// <returns>
181
- /// The 'this' instance.
182
- /// </returns>
183
- public CodePointFilter Clear ( )
130
+ public virtual void Clear ( )
184
131
{
185
132
_allowedCharactersBitmap . Clear ( ) ;
186
- return this ;
187
133
}
188
134
189
135
/// <summary>
190
136
/// Disallows the character <paramref name="character"/> through the filter.
191
137
/// </summary>
192
- /// <returns>
193
- /// The 'this' instance.
194
- /// </returns>
195
- public CodePointFilter ForbidCharacter ( char character )
138
+ public virtual void ForbidCharacter ( char character )
196
139
{
197
140
_allowedCharactersBitmap . ForbidCharacter ( character ) ;
198
- return this ;
199
141
}
200
142
201
143
/// <summary>
202
144
/// Disallows all characters specified by <paramref name="characters"/> through the filter.
203
145
/// </summary>
204
- /// <returns>
205
- /// The 'this' instance.
206
- /// </returns>
207
- public CodePointFilter ForbidCharacters ( params char [ ] characters )
208
- {
209
- if ( characters == null )
210
- {
211
- throw new ArgumentNullException ( "characters" ) ;
212
- }
213
-
214
- for ( int i = 0 ; i < characters . Length ; i ++ )
215
- {
216
- _allowedCharactersBitmap . ForbidCharacter ( characters [ i ] ) ;
217
- }
218
-
219
- return this ;
220
- }
221
-
222
- /// <summary>
223
- /// Disallows all characters in the string <paramref name="characters"/> through the filter.
224
- /// </summary>
225
- /// <returns>
226
- /// The 'this' instance.
227
- /// </returns>
228
- public CodePointFilter ForbidCharacters ( string characters )
146
+ public virtual void ForbidCharacters ( params char [ ] characters )
229
147
{
230
148
if ( characters == null )
231
149
{
@@ -236,16 +154,12 @@ public CodePointFilter ForbidCharacters(string characters)
236
154
{
237
155
_allowedCharactersBitmap . ForbidCharacter ( characters [ i ] ) ;
238
156
}
239
- return this ;
240
157
}
241
158
242
159
/// <summary>
243
160
/// Disallows all characters specified by <paramref name="range"/> through the filter.
244
161
/// </summary>
245
- /// <returns>
246
- /// The 'this' instance.
247
- /// </returns>
248
- public CodePointFilter ForbidRange ( UnicodeRange range )
162
+ public virtual void ForbidRange ( UnicodeRange range )
249
163
{
250
164
if ( range == null )
251
165
{
@@ -258,16 +172,12 @@ public CodePointFilter ForbidRange(UnicodeRange range)
258
172
{
259
173
_allowedCharactersBitmap . ForbidCharacter ( ( char ) ( firstCodePoint + i ) ) ;
260
174
}
261
- return this ;
262
175
}
263
176
264
177
/// <summary>
265
178
/// Disallows all characters specified by <paramref name="ranges"/> through the filter.
266
179
/// </summary>
267
- /// <returns>
268
- /// The 'this' instance.
269
- /// </returns>
270
- public CodePointFilter ForbidRanges ( params UnicodeRange [ ] ranges )
180
+ public virtual void ForbidRanges ( params UnicodeRange [ ] ranges )
271
181
{
272
182
if ( ranges == null )
273
183
{
@@ -278,8 +188,6 @@ public CodePointFilter ForbidRanges(params UnicodeRange[] ranges)
278
188
{
279
189
ForbidRange ( ranges [ i ] ) ;
280
190
}
281
-
282
- return this ;
283
191
}
284
192
285
193
/// <summary>
@@ -294,7 +202,7 @@ internal AllowedCharactersBitmap GetAllowedCharacters()
294
202
/// <summary>
295
203
/// Gets an enumeration of all allowed code points.
296
204
/// </summary>
297
- public IEnumerable < int > GetAllowedCodePoints ( )
205
+ public virtual IEnumerable < int > GetAllowedCodePoints ( )
298
206
{
299
207
for ( int i = 0 ; i < 0x10000 ; i ++ )
300
208
{
@@ -308,15 +216,15 @@ public IEnumerable<int> GetAllowedCodePoints()
308
216
/// <summary>
309
217
/// Returns a value stating whether the character <paramref name="character"/> is allowed through the filter.
310
218
/// </summary>
311
- public bool IsCharacterAllowed ( char character )
219
+ public virtual bool IsCharacterAllowed ( char character )
312
220
{
313
221
return _allowedCharactersBitmap . IsCharacterAllowed ( character ) ;
314
222
}
315
223
316
224
/// <summary>
317
225
/// Wraps the provided filter as a CodePointFilter, avoiding the clone if possible.
318
226
/// </summary>
319
- internal static CodePointFilter Wrap ( ICodePointFilter filter )
227
+ internal static CodePointFilter Wrap ( CodePointFilter filter )
320
228
{
321
229
return ( filter as CodePointFilter ) ?? new CodePointFilter ( filter ) ;
322
230
}
0 commit comments