forked from malcolmgroves/FluentQuery
-
Notifications
You must be signed in to change notification settings - Fork 4
/
FluentQuery.Chars.pas
executable file
·691 lines (610 loc) · 22.1 KB
/
FluentQuery.Chars.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
{****************************************************}
{ }
{ FluentQuery }
{ }
{ Copyright (C) 2013 Malcolm Groves }
{ }
{ http://www.malcolmgroves.com }
{ }
{****************************************************}
{ }
{ This Source Code Form is subject to the terms of }
{ the Mozilla Public License, v. 2.0. If a copy of }
{ the MPL was not distributed with this file, You }
{ can obtain one at }
{ }
{ http://mozilla.org/MPL/2.0/ }
{ }
{****************************************************}
unit FluentQuery.Chars;
interface
uses
FluentQuery.Core.Types,
System.SysUtils,
FluentQuery.Core.EnumerationStrategies,
FluentQuery.Core.Enumerators,
System.Generics.Collections;
type
IUnboundCharQuery = interface;
IBoundCharQuery = interface(IBaseBoundQuery<Char>)
function GetEnumerator: IBoundCharQuery;
// Query Operations
function Equals(const Value : Char) : IBoundCharQuery;
function IsControl: IBoundCharQuery;
function IsDigit: IBoundCharQuery;
function IsHighSurrogate: IBoundCharQuery;
function IsInArray(const SomeChars: array of Char): IBoundCharQuery;
function IsLetter: IBoundCharQuery;
function IsLetterOrDigit: IBoundCharQuery;
function IsLower: IBoundCharQuery;
function IsLowSurrogate: IBoundCharQuery;
function IsNumber: IBoundCharQuery;
function IsPunctuation: IBoundCharQuery;
function IsSeparator: IBoundCharQuery;
function IsSurrogate: IBoundCharQuery;
function IsSymbol: IBoundCharQuery;
function IsUpper: IBoundCharQuery;
function IsWhiteSpace: IBoundCharQuery;
function IsNotWhiteSpace: IBoundCharQuery;
function Map(Transformer : TFunc<Char, Char>) : IBoundCharQuery;
function Matches(const Value : Char; IgnoreCase : Boolean = True) : IBoundCharQuery;
function NotEquals(const Value : Char) : IBoundCharQuery;
function NotMatches(const Value : Char; IgnoreCase : Boolean = True) : IBoundCharQuery;
function Skip(Count : Integer): IBoundCharQuery;
function SkipWhile(Predicate : TPredicate<Char>) : IBoundCharQuery; overload;
function SkipWhile(UnboundQuery : IUnboundCharQuery) : IBoundCharQuery; overload;
function Take(Count : Integer): IBoundCharQuery;
function TakeWhile(Predicate : TPredicate<Char>): IBoundCharQuery; overload;
function TakeWhile(UnboundQuery : IUnboundCharQuery): IBoundCharQuery; overload;
function Where(Predicate : TPredicate<Char>) : IBoundCharQuery;
function WhereNot(UnboundQuery : IUnboundCharQuery) : IBoundCharQuery; overload;
function WhereNot(Predicate : TPredicate<Char>) : IBoundCharQuery; overload;
// terminating operations
function AsString : String;
end;
IUnboundCharQuery = interface(IBaseUnboundQuery<Char>)
function GetEnumerator: IUnboundCharQuery;
function From(StringValue : String) : IBoundCharQuery; overload;
function From(Container : TEnumerable<Char>) : IBoundCharQuery; overload;
// Query Operations
function Equals(const Value : Char) : IUnboundCharQuery;
function IsControl: IUnboundCharQuery;
function IsDigit: IUnboundCharQuery;
function IsHighSurrogate: IUnboundCharQuery;
function IsInArray(const SomeChars: array of Char): IUnboundCharQuery;
function IsLetter: IUnboundCharQuery;
function IsLetterOrDigit: IUnboundCharQuery;
function IsLower: IUnboundCharQuery;
function IsLowSurrogate: IUnboundCharQuery;
function IsNumber: IUnboundCharQuery;
function IsPunctuation: IUnboundCharQuery;
function IsSeparator: IUnboundCharQuery;
function IsSurrogate: IUnboundCharQuery;
function IsSymbol: IUnboundCharQuery;
function IsUpper: IUnboundCharQuery;
function IsWhiteSpace: IUnboundCharQuery;
function IsNotWhiteSpace: IUnboundCharQuery;
function Map(Transformer : TFunc<Char, Char>) : IUnboundCharQuery;
function Matches(const Value : Char; IgnoreCase : Boolean = True) : IUnboundCharQuery;
function NotEquals(const Value : Char) : IUnboundCharQuery;
function NotMatches(const Value : Char; IgnoreCase : Boolean = True) : IUnboundCharQuery;
function Skip(Count : Integer): IUnboundCharQuery;
function SkipWhile(Predicate : TPredicate<Char>) : IUnboundCharQuery; overload;
function SkipWhile(UnboundQuery : IUnboundCharQuery) : IUnboundCharQuery; overload;
function Take(Count : Integer): IUnboundCharQuery;
function TakeWhile(Predicate : TPredicate<Char>): IUnboundCharQuery; overload;
function TakeWhile(UnboundQuery : IUnboundCharQuery): IUnboundCharQuery; overload;
function Where(Predicate : TPredicate<Char>) : IUnboundCharQuery;
function WhereNot(UnboundQuery : IUnboundCharQuery) : IUnboundCharQuery; overload;
function WhereNot(Predicate : TPredicate<Char>) : IUnboundCharQuery; overload;
end;
function CharQuery : IUnboundCharQuery;
implementation
uses System.Character, FluentQuery.Core.MethodFactories, FluentQuery.Core.Reduce;
type
TCharQuery = class(TBaseQuery<Char>,
IBoundCharQuery,
IUnboundCharQuery)
protected
type
TCharQueryImpl<T : IBaseQuery<Char>> = class
private
FQuery : TCharQuery;
public
constructor Create(Query : TCharQuery); virtual;
function GetEnumerator: T;
{$IFDEF DEBUG}
function GetOperationName : String;
function GetOperationPath : String;
property OperationName : string read GetOperationName;
property OperationPath : string read GetOperationPath;
{$ENDIF}
function From(StringValue : String) : IBoundCharQuery; overload;
function From(Collection : TEnumerable<Char>) : IBoundCharQuery; overload;
// Primitive Operations
function Map(Transformer : TFunc<Char, Char>) : T;
function SkipWhile(Predicate : TPredicate<Char>) : T; overload;
function TakeWhile(Predicate : TPredicate<Char>): T; overload;
function Where(Predicate : TPredicate<Char>) : T;
// Derivative Operations
function Equals(const Value : Char) : T; reintroduce;
function NotEquals(const Value : Char) : T;
function Skip(Count : Integer): T;
function SkipWhile(UnboundQuery : IUnboundCharQuery) : T; overload;
function Take(Count : Integer): T;
function TakeWhile(UnboundQuery : IUnboundCharQuery): T; overload;
function WhereNot(UnboundQuery : IUnboundCharQuery) : T; overload;
function WhereNot(Predicate : TPredicate<Char>) : T; overload;
function Matches(const Value : Char; IgnoreCase : Boolean = True) : T;
function NotMatches(const Value : Char; IgnoreCase : Boolean = True) : T;
function IsControl: T;
function IsDigit: T;
function IsHighSurrogate: T;
function IsInArray(const SomeChars: array of Char): T;
function IsLetter: T;
function IsLetterOrDigit: T;
function IsLower: T;
function IsLowSurrogate: T;
function IsNumber: T;
function IsPunctuation: T;
function IsSeparator: T;
function IsSurrogate: T;
function IsSymbol: T;
function IsUpper: T;
function IsWhiteSpace: T;
function IsNotWhiteSpace: T;
// Terminating Operations
function Predicate : TPredicate<Char>;
function AsString : String;
function First : Char;
function Count : Integer;
end;
protected
FBoundQuery : TCharQueryImpl<IBoundCharQuery>;
FUnboundQuery : TCharQueryImpl<IUnboundCharQuery>;
public
constructor Create(EnumerationStrategy : TEnumerationStrategy<Char>;
UpstreamQuery : IBaseQuery<Char> = nil;
SourceData : IMinimalEnumerator<Char> = nil); override;
destructor Destroy; override;
property BoundQuery : TCharQueryImpl<IBoundCharQuery>
read FBoundQuery implements IBoundCharQuery;
property UnboundQuery : TCharQueryImpl<IUnboundCharQuery>
read FUnboundQuery implements IUnboundCharQuery;
end;
TCharPredicateFactory = class(TMethodFactory<Char>)
public
class function Matches(const AChar : Char; IgnoreCase : Boolean) : TPredicate<Char>;
end;
function CharQuery : IUnboundCharQuery;
begin
Result := TCharQuery.Create(TEnumerationStrategy<Char>.Create);
{$IFDEF DEBUG}
Result.OperationName := 'CharQuery';
{$ENDIF}
end;
{ TCharQueryEnumerator }
function TCharQuery.TCharQueryImpl<T>.Count: Integer;
begin
Result := TReducer<Char,Integer>.Reduce(FQuery,
0,
function(Accumulator : Integer; NextValue : Char): Integer
begin
Result := Accumulator + 1;
end);
end;
constructor TCharQuery.TCharQueryImpl<T>.Create(
Query: TCharQuery);
begin
FQuery := Query;
end;
function TCharQuery.TCharQueryImpl<T>.Equals(
const Value: Char): T;
begin
Result := Matches(Value, False);
{$IFDEF DEBUG}
Result.OperationName := 'Equals';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.First: Char;
begin
if FQuery.MoveNext then
Result := FQuery.GetCurrent
else
raise EEmptyResultSetException.Create('Can''t call First on an empty Result Set');
end;
function TCharQuery.TCharQueryImpl<T>.From(
Collection: TEnumerable<Char>): IBoundCharQuery;
begin
Result := TCharQuery.Create(TEnumerationStrategy<Char>.Create,
IBaseQuery<Char>(FQuery),
TGenericEnumeratorAdapter<Char>.Create(Collection.GetEnumerator) as IMinimalEnumerator<Char>);
{$IFDEF DEBUG}
Result.OperationName := Format('From(%s)', [Collection.ToString]);
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.From(
StringValue: String): IBoundCharQuery;
begin
Result := TCharQuery.Create(TEnumerationStrategy<Char>.Create,
IBaseQuery<Char>(FQuery),
TStringEnumeratorAdapter.Create(StringValue));
{$IFDEF DEBUG}
Result.OperationName := Format('From(''%s'')', [StringValue]);
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.GetEnumerator: T;
begin
Result := FQuery;
end;
{$IFDEF DEBUG}
function TCharQuery.TCharQueryImpl<T>.GetOperationName: String;
begin
Result := FQuery.OperationName;
end;
function TCharQuery.TCharQueryImpl<T>.GetOperationPath: String;
begin
Result := FQuery.OperationPath;
end;
{$ENDIF}
function TCharQuery.TCharQueryImpl<T>.IsControl: T;
var
LIsControl : TPredicate<char>;
begin
LIsControl := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsControl;
end;
Result := Where(LIsControl);
{$IFDEF DEBUG}
Result.OperationName := 'IsControl';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsDigit: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsDigit;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsDigit';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsHighSurrogate: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsHighSurrogate;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsHighSurrogate';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsInArray(const SomeChars: array of Char): T;
var
LPredicate : TPredicate<char>;
LSomeChars : array of Char;
LIndex : Integer;
begin
SetLength(LSomeChars, Length(SomeChars));
for LIndex := Low(SomeChars) to High(SomeChars) do
LSomeChars[LIndex] := SomeChars[LIndex];
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsInArray(LSomeChars);
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsInArray(SomeChars)';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsLetter: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsLetter;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsLetter';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsLetterOrDigit: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsLetterOrDigit;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsLetterOrDigit';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsLower: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsLower;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsLower';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsLowSurrogate: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsLowSurrogate;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsLowSurrogate';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsNotWhiteSpace: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := not CurrentValue.IsWhiteSpace;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsNotWhitespace';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsNumber: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsNumber;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsNumber';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsPunctuation: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsPunctuation;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsPunctuation';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsSeparator: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsSeparator;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsSeparator';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsSurrogate: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsSurrogate;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsSurrogate';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsSymbol: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsSymbol;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsSymbol';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsUpper: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsUpper;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsUpper';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.IsWhiteSpace: T;
var
LPredicate : TPredicate<char>;
begin
LPredicate := function (CurrentValue : Char) : Boolean
begin
Result := CurrentValue.IsWhiteSpace;
end;
Result := Where(LPredicate);
{$IFDEF DEBUG}
Result.OperationName := 'IsWhitespace';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.Map(
Transformer: TFunc<Char, Char>): T;
begin
Result := TCharQuery.Create(TIsomorphicTransformEnumerationStrategy<Char>.Create(Transformer),
IBaseQuery<Char>(FQuery));
{$IFDEF DEBUG}
Result.OperationName := 'Map(Transformer)';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.Matches(const Value: Char;
IgnoreCase: Boolean): T;
begin
Result := Where(TCharPredicateFactory.Matches(Value, IgnoreCase));
{$IFDEF DEBUG}
Result.OperationName := Format('Matches(''%s'', %s', [Value, IgnoreCase.ToString]);
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.NotEquals(
const Value: Char): T;
begin
Result := NotMatches(Value, False);
{$IFDEF DEBUG}
Result.OperationName := Format('NotEquals(''%s'')', [Value]);
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.NotMatches(
const Value: Char; IgnoreCase: Boolean): T;
begin
Result := WhereNot(TCharPredicateFactory.Matches(Value, IgnoreCase));
{$IFDEF DEBUG}
Result.OperationName := Format('NotMatches(''%s'', %s', [Value, IgnoreCase.ToString]);
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.Predicate: TPredicate<Char>;
begin
Result := TCharPredicateFactory.QuerySingleValue(FQuery);
end;
function TCharQuery.TCharQueryImpl<T>.Skip(Count: Integer): T;
begin
Result := SkipWhile(TCharPredicateFactory.UpToNumberOfTimes(Count));
{$IFDEF DEBUG}
Result.OperationName := Format('Skip(%d)', [Count]);
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.SkipWhile(
UnboundQuery: IUnboundCharQuery): T;
begin
Result := SkipWhile(UnboundQuery.Predicate);
{$IFDEF DEBUG}
Result.OperationName := Format('SkipWhile', [UnboundQuery.OperationPath]);
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.SkipWhile(
Predicate: TPredicate<Char>): T;
begin
Result := TCharQuery.Create(TSkipWhileEnumerationStrategy<Char>.Create(Predicate),
IBaseQuery<Char>(FQuery));
{$IFDEF DEBUG}
Result.OperationName := 'SkipWhile(Predicate)';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.Take(Count: Integer): T;
begin
Result := TakeWhile(TCharPredicateFactory.UpToNumberOfTimes(Count));
{$IFDEF DEBUG}
Result.OperationName := Format('Take(%d)', [Count]);
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.TakeWhile(
UnboundQuery: IUnboundCharQuery): T;
begin
Result := TakeWhile(UnboundQuery.Predicate);
{$IFDEF DEBUG}
Result.OperationName := Format('TakeWhile', [UnboundQuery.OperationPath]);
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.TakeWhile(
Predicate: TPredicate<Char>): T;
begin
Result := TCharQuery.Create(TTakeWhileEnumerationStrategy<Char>.Create(Predicate),
IBaseQuery<Char>(FQuery));
{$IFDEF DEBUG}
Result.OperationName := 'TakeWhile(Predicate)';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.AsString: String;
begin
Result := TReducer<Char,String>.Reduce(FQuery,
'',
function(Accumulator : String; NextValue : Char): String
begin
Result := Accumulator + NextValue;
end);
end;
function TCharQuery.TCharQueryImpl<T>.Where(
Predicate: TPredicate<Char>): T;
begin
Result := TCharQuery.Create(TWhereEnumerationStrategy<Char>.Create(Predicate),
IBaseQuery<Char>(FQuery));
{$IFDEF DEBUG}
Result.OperationName := 'Where(Predicate)';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.WhereNot(
Predicate: TPredicate<Char>): T;
begin
Result := Where(TCharPredicateFactory.InvertPredicate(Predicate));
{$IFDEF DEBUG}
Result.OperationName := 'WhereNot(Predicate)';
{$ENDIF}
end;
function TCharQuery.TCharQueryImpl<T>.WhereNot(
UnboundQuery: IUnboundCharQuery): T;
begin
Result := WhereNot(UnboundQuery.Predicate);
{$IFDEF DEBUG}
Result.OperationName := Format('WhereNot(%s)', [UnboundQuery.OperationPath]);
{$ENDIF}
end;
{ TCharQueryEnumerator }
constructor TCharQuery.Create(
EnumerationStrategy: TEnumerationStrategy<Char>;
UpstreamQuery: IBaseQuery<Char>;
SourceData: IMinimalEnumerator<Char>);
begin
inherited Create(EnumerationStrategy, UpstreamQuery, SourceData);
FBoundQuery := TCharQueryImpl<IBoundCharQuery>.Create(self);
FUnboundQuery := TCharQueryImpl<IUnboundCharQuery>.Create(self);
end;
destructor TCharQuery.Destroy;
begin
FBoundQuery.Free;
FUnboundQuery.Free;
inherited;
end;
{ TCharPredicateFactory }
class function TCharPredicateFactory.Matches(const AChar: Char;
IgnoreCase: Boolean): TPredicate<Char>;
begin
Result := function (Value : Char) : Boolean
begin
if IgnoreCase then
Result := Value.ToUpper = AChar.ToUpper
else
Result := Value = AChar;
end;
end;
end.