-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathGSeq.h
1166 lines (1043 loc) · 27 KB
/
GSeq.h
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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Implementation of composite character sequence functions for GNUSTEP
Copyright (C) 1999 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Date: May 1999
Based on code by: Stevo Crvenkovski <stevo@btinternet.com>
Date: March 1997
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
*/
/*
* Warning - this contains hairy code - handle with care.
* The first part of this file contains variable and constant definitions
* plus inline function definitions for handling sequences of unicode
* characters. It is bracketed in preprocessor conditionals so that it
* is only ever included once.
* The second part of the file contains inline function definitions that
* are designed to be modified depending on the defined macros at the
* point where they are included. This is meant to be included multiple
* times so the same code can be used for NSString, and subclasses.
*/
#ifndef __GSeq_h_GNUSTEP_GSEQ_BASE_INCLUDE
#define __GSeq_h_GNUSTEP_GSEQ_BASE_INCLUDE
/*
* Some standard selectors for frequently used methods. Set in NSString
* +initialize or the GSString.m setup() function.
*/
static SEL caiSel = NULL;
static SEL gcrSel = NULL;
static SEL ranSel = NULL;
/*
* The maximum decompostion level for composite unicode characters.
*/
#define MAXDEC 18
/*
* The structure definition for handling a unicode character sequence
* for a single character.
*/
typedef struct {
unichar *chars;
NSUInteger count;
NSUInteger capacity;
BOOL normalized;
} GSeqStruct;
typedef GSeqStruct *GSeq;
/*
* A macro to define a GSeqStruct variable capable of holding a
* unicode character sequence of the specified length.
*/
#define GSEQ_MAKE(BUF, SEQ, LEN) \
unichar BUF[LEN * MAXDEC + 1]; \
GSeqStruct SEQ = { BUF, LEN, LEN * MAXDEC, 0 }
/*
* A function to normalize a unicode character sequence ... produces a
* sequence containing composed characters in a well defined order and
* with a nul terminator as well as a character count.
*/
static inline void GSeq_normalize(GSeq seq)
{
NSUInteger count = seq->count;
if (count)
{
unichar *source = seq->chars;
unichar target[count*MAXDEC+1];
NSUInteger base = 0;
/*
* Pre-scan ... anything with a code under 0x00C0 is not a decomposable
* character, so we don't need to expand it.
* If there are no decomposable characters or composed sequences, the
* sequence is already normalised and we don't need to make any changes.
*/
while (base < count)
{
if (source[base] >= 0x00C0)
{
break;
}
base++;
}
source[count] = (unichar)(0);
if (base < count)
{
/*
* Now expand decomposable characters into the long format.
* Use the 'base' value to avoid re-checking characters which have
* already been expanded.
*/
while (base < count)
{
unichar *spoint = &source[base];
unichar *tpoint = &target[base];
NSUInteger newbase = 0;
do
{
unichar *dpoint = uni_is_decomp(*spoint);
if (!dpoint)
{
*tpoint++ = *spoint;
}
else
{
while (*dpoint)
{
*tpoint++ = *dpoint++;
}
if (newbase <= 0)
{
newbase = (spoint - source) + 1;
}
}
}
while (*spoint++);
count = tpoint - target;
memcpy(&source[base], &target[base], 2*(count - base));
source[count] = (unichar)(0);
if (newbase > 0)
{
base = newbase;
}
else
{
base = count;
}
}
seq->count = count;
/*
* Now standardise ordering of all composed character sequences.
*/
if (count > 1)
{
BOOL notdone = YES;
while (notdone)
{
unichar *first = seq->chars;
unichar *second = first + 1;
NSUInteger i;
notdone = NO;
for (i = 1; i < count; i++)
{
if (GSPrivateUniCop(*second))
{
if (GSPrivateUniCop(*first)
> GSPrivateUniCop(*second))
{
unichar tmp = *first;
*first = *second;
*second = tmp;
notdone = YES;
}
else if (GSPrivateUniCop(*first)
== GSPrivateUniCop(*second))
{
if (*first > *second)
{
unichar tmp = *first;
*first = *second;
*second = tmp;
notdone = YES;
}
else if (*first == *second)
{
unichar *end = seq->chars + count;
while (*first == *second && second < end)
{
second++;
count--;
}
first++;
while (second < end)
{
*first++ = *second++;
}
notdone = YES;
break;
}
}
}
first++;
second++;
}
}
seq->count = count;
}
}
seq->normalized = YES;
}
}
/*
* A function to compare two unicode character sequences normalizing if
* required.
*/
static inline NSComparisonResult GSeq_compare(GSeq s0, GSeq s1)
{
NSUInteger i;
NSUInteger end;
NSUInteger len0;
NSUInteger len1;
unichar *c0 = s0->chars;
unichar *c1 = s1->chars;
len0 = s0->count;
len1 = s1->count;
if (len0 == len1)
{
for (i = 0; i < len1; i++)
{
if (c0[i] != c1[i])
{
break;
}
}
if (i == len0)
{
return NSOrderedSame;
}
}
if (s0->normalized == NO)
GSeq_normalize(s0);
if (s1->normalized == NO)
GSeq_normalize(s1);
len0 = s0->count;
len1 = s1->count;
if (len0 < len1)
end = len0;
else
end = len1;
for (i = 0; i < end; i++)
{
if (c0[i] < c1[i])
return NSOrderedAscending;
if (c0[i] > c1[i])
return NSOrderedDescending;
}
if (len0 < len1)
return NSOrderedAscending;
if (len0 > len1)
return NSOrderedDescending;
return NSOrderedSame;
}
static inline void GSeq_lowercase(GSeq seq)
{
unichar *s = seq->chars;
NSUInteger len = seq->count;
NSUInteger i;
for (i = 0; i < len; i++)
s[i] = uni_tolower(s[i]);
}
static inline void GSeq_uppercase(GSeq seq)
{
unichar *s = seq->chars;
NSUInteger len = seq->count;
NSUInteger i;
for (i = 0; i < len; i++)
s[i] = uni_toupper(s[i]);
}
/*
* Specify NSString, GSUString or GSCString
*/
#define GSEQ_NS 0
#define GSEQ_US 1
#define GSEQ_CS 2
/*
* Definitions for bitmask of search options. These MUST match the
* enumeration in NSString.h
*/
#define GSEQ_FCLS 3
#define GSEQ_BCLS 7
#define GSEQ_FLS 2
#define GSEQ_BLS 6
#define GSEQ_FCS 1
#define GSEQ_BCS 5
#define GSEQ_FS 0
#define GSEQ_BS 4
#define GSEQ_FCLAS 11
#define GSEQ_BCLAS 15
#define GSEQ_FLAS 10
#define GSEQ_BLAS 14
#define GSEQ_FCAS 9
#define GSEQ_BCAS 13
#define GESQ_FAS 8
#define GSEQ_BAS 12
#endif /* __GSeq_h_GNUSTEP_GSEQ_BASE_INCLUDE */
/*
* Set up macros for dealing with 'self' on the basis of GSQ_S
*/
#if GSEQ_S == GSEQ_US
#define GSEQ_ST GSStr
#define GSEQ_SLEN s->_count
#define GSEQ_SGETC(I) s->_contents.u[I]
#define GSEQ_SGETR(B,R) memcpy(B, &s->_contents.u[R.location], 2*(R).length)
#define GSEQ_SRANGE(I) (*srImp)((id)s, ranSel, I)
#else
#if GSEQ_S == GSEQ_CS
#define GSEQ_ST GSStr
#define GSEQ_SLEN s->_count
#define GSEQ_SGETC(I) (unichar)s->_contents.c[I]
#define GSEQ_SGETR(B,R) ( { \
NSUInteger _lcount = 0; \
while (_lcount < (R).length) \
{ \
(B)[_lcount] = (unichar)s->_contents.c[(R).location + _lcount]; \
_lcount++; \
} \
} )
#define GSEQ_SRANGE(I) (NSRange){I,1}
#else
#define GSEQ_ST NSString*
#define GSEQ_SLEN [s length]
#define GSEQ_SGETC(I) (*scImp)(s, caiSel, I)
#define GSEQ_SGETR(B,R) (*sgImp)(s, gcrSel, B, R)
#define GSEQ_SRANGE(I) (*srImp)(s, ranSel, I)
#endif
#endif
/*
* Set up macros for dealing with 'other' string on the basis of GSQ_O
*/
#if GSEQ_O == GSEQ_US
#define GSEQ_OT GSStr
#define GSEQ_OLEN o->_count
#define GSEQ_OGETC(I) o->_contents.u[I]
#define GSEQ_OGETR(B,R) memcpy(B, &o->_contents.u[R.location], 2*(R).length)
#define GSEQ_ORANGE(I) (*orImp)((id)o, ranSel, I)
#else
#if GSEQ_O == GSEQ_CS
#define GSEQ_OT GSStr
#define GSEQ_OLEN o->_count
#define GSEQ_OGETC(I) (unichar)o->_contents.c[I]
#define GSEQ_OGETR(B,R) ( { \
NSUInteger _lcount = 0; \
while (_lcount < (R).length) \
{ \
(B)[_lcount] = (unichar)o->_contents.c[(R).location + _lcount]; \
_lcount++; \
} \
} )
#define GSEQ_ORANGE(I) (NSRange){I,1}
#else
#define GSEQ_OT NSString*
#define GSEQ_OLEN [o length]
#define GSEQ_OGETC(I) (*ocImp)(o, caiSel, I)
#define GSEQ_OGETR(B,R) (*ogImp)(o, gcrSel, B, R)
#define GSEQ_ORANGE(I) (*orImp)(o, ranSel, I)
#endif
#endif
/*
* If a string comparison function is required, implement it.
*/
#ifdef GSEQ_STRCOMP
static NSComparisonResult
GSEQ_STRCOMP(NSString *ss, NSString *os, NSUInteger mask, NSRange aRange)
{
GSEQ_ST s = (GSEQ_ST)ss;
GSEQ_OT o = (GSEQ_OT)os;
NSUInteger oLength; /* Length of other. */
#if 0
/* Range should be checked in calling code */
if (aRange.location > GSEQ_SLEN)
[NSException raise: NSRangeException format: @"Invalid location."];
if (aRange.length > (GSEQ_SLEN - aRange.location))
[NSException raise: NSRangeException format: @"Invalid location+length."];
#endif
oLength = GSEQ_OLEN;
if (aRange.length == 0)
{
if (oLength == 0)
{
return NSOrderedSame;
}
return NSOrderedAscending;
}
else if (oLength == 0)
{
return NSOrderedDescending;
}
if (mask & NSLiteralSearch)
{
NSUInteger i;
NSUInteger sLen = aRange.length;
NSUInteger oLen = oLength;
NSUInteger end;
#if GSEQ_S == GSEQ_NS
void (*sgImp)(NSString*, SEL, unichar*, NSRange);
unichar sBuf[sLen];
#else
#if GSEQ_S == GSEQ_US
unichar *sBuf;
#else
unsigned char *sBuf;
#endif
#endif
#if GSEQ_O == GSEQ_NS
void (*ogImp)(NSString*, SEL, unichar*, NSRange);
unichar oBuf[oLen];
#else
#if GSEQ_O == GSEQ_US
unichar *oBuf;
#else
unsigned char *oBuf;
#endif
#endif
#if GSEQ_S == GSEQ_NS
sgImp = (void (*)(NSString*,SEL,unichar*,NSRange))
[(id)s methodForSelector: gcrSel];
GSEQ_SGETR(sBuf, aRange);
#else
#if GSEQ_S == GSEQ_CS
sBuf = &s->_contents.c[aRange.location];
#else
sBuf = &s->_contents.u[aRange.location];
#endif
#endif
#if GSEQ_O == GSEQ_NS
ogImp = (void (*)(NSString*,SEL,unichar*,NSRange))
[(id)o methodForSelector: gcrSel];
GSEQ_OGETR(oBuf, NSMakeRange(0, oLen));
#else
#if GSEQ_O == GSEQ_CS
oBuf = o->_contents.c;
#else
oBuf = o->_contents.u;
#endif
#endif
if (oLen < sLen)
end = oLen;
else
end = sLen;
if (mask & NSCaseInsensitiveSearch)
{
#if GSEQ_O == GSEQ_CS || GSEQ_S == GSEQ_CS
if (GSPrivateDefaultCStringEncoding() == NSISOLatin1StringEncoding)
{
/* Using latin1 internally, rather than native encoding,
* so we can't use native tolower() function.
*/
for (i = 0; i < end; i++)
{
unichar c1 = uni_tolower((unichar)sBuf[i]);
unichar c2 = uni_tolower((unichar)oBuf[i]);
if (c1 < c2)
return NSOrderedAscending;
if (c1 > c2)
return NSOrderedDescending;
}
}
else
{
/* We are not using latin1 encoding internally, so we trust
* that the internal encoding matches the native encoding
* and the native tolower() function will work.
*/
for (i = 0; i < end; i++)
{
#if GSEQ_S == GSEQ_CS
unichar c1 = tolower(sBuf[i]);
#else
unichar c1 = uni_tolower((unichar)sBuf[i]);
#endif
#if GSEQ_O == GSEQ_CS
unichar c2 = tolower(oBuf[i]);
#else
unichar c2 = uni_tolower((unichar)oBuf[i]);
#endif
if (c1 < c2)
return NSOrderedAscending;
if (c1 > c2)
return NSOrderedDescending;
}
}
#else
for (i = 0; i < end; i++)
{
unichar c1 = uni_tolower((unichar)sBuf[i]);
unichar c2 = uni_tolower((unichar)oBuf[i]);
if (c1 < c2)
return NSOrderedAscending;
if (c1 > c2)
return NSOrderedDescending;
}
#endif
}
else
{
for (i = 0; i < end; i++)
{
#if GSEQ_O == GSEQ_CS && GSEQ_S == GSEQ_CS
if (sBuf[i] < oBuf[i])
return NSOrderedAscending;
if (sBuf[i] > oBuf[i])
return NSOrderedDescending;
#else
if ((unichar)sBuf[i] < (unichar)oBuf[i])
return NSOrderedAscending;
if ((unichar)sBuf[i] > (unichar)oBuf[i])
return NSOrderedDescending;
#endif
}
}
if (sLen > oLen)
return NSOrderedDescending;
else if (sLen < oLen)
return NSOrderedAscending;
else
return NSOrderedSame;
}
else
{
NSUInteger start = aRange.location;
NSUInteger end = start + aRange.length;
NSUInteger sLength = GSEQ_SLEN;
NSUInteger sCount = start;
NSUInteger oCount = 0;
NSComparisonResult result;
#if GSEQ_S == GSEQ_NS || GSEQ_S == GSEQ_US
NSRange (*srImp)(NSString*, SEL, NSUInteger);
#endif
#if GSEQ_O == GSEQ_NS || GSEQ_O == GSEQ_US
NSRange (*orImp)(NSString*, SEL, NSUInteger);
#endif
#if GSEQ_S == GSEQ_NS
void (*sgImp)(NSString*, SEL, unichar*, NSRange);
#endif
#if GSEQ_O == GSEQ_NS
void (*ogImp)(NSString*, SEL, unichar*, NSRange);
#endif
#if GSEQ_S == GSEQ_NS || GSEQ_S == GSEQ_US
srImp = (NSRange (*)(NSString*, SEL, NSUInteger))
[(id)s methodForSelector: ranSel];
#endif
#if GSEQ_O == GSEQ_NS || GSEQ_O == GSEQ_US
orImp = (NSRange (*)(NSString*, SEL, NSUInteger))
[(id)o methodForSelector: ranSel];
#endif
#if GSEQ_S == GSEQ_NS
sgImp = (void (*)(NSString*, SEL, unichar*, NSRange))
[(id)s methodForSelector: gcrSel];
#endif
#if GSEQ_O == GSEQ_NS
ogImp = (void (*)(NSString*, SEL, unichar*, NSRange))
[(id)o methodForSelector: gcrSel];
#endif
while (sCount < end)
{
if (oCount >= oLength)
{
return NSOrderedDescending;
}
else if (sCount >= sLength)
{
return NSOrderedAscending;
}
else
{
NSRange sRange = GSEQ_SRANGE(sCount);
NSRange oRange = GSEQ_ORANGE(oCount);
GSEQ_MAKE(sBuf, sSeq, sRange.length);
GSEQ_MAKE(oBuf, oSeq, oRange.length);
GSEQ_SGETR(sBuf, sRange);
GSEQ_OGETR(oBuf, oRange);
result = GSeq_compare(&sSeq, &oSeq);
if (result != NSOrderedSame)
{
if (mask & NSCaseInsensitiveSearch)
{
GSeq_lowercase(&oSeq);
GSeq_lowercase(&sSeq);
result = GSeq_compare(&sSeq, &oSeq);
if (result != NSOrderedSame)
{
return result;
}
}
else
{
return result;
}
}
sCount += sRange.length;
oCount += oRange.length;
}
}
if (oCount < oLength)
return NSOrderedAscending;
return NSOrderedSame;
}
}
#undef GSEQ_STRCOMP
#endif
/*
* If a string search function is required, implement it.
*/
#ifdef GSEQ_STRRANGE
static NSRange
GSEQ_STRRANGE(NSString *ss, NSString *os, NSUInteger mask, NSRange aRange)
{
GSEQ_ST s = (GSEQ_ST)ss;
GSEQ_OT o = (GSEQ_OT)os;
NSUInteger rangeEnd = NSMaxRange(aRange);
NSUInteger myIndex;
NSUInteger myEndIndex;
NSUInteger strLength;
#if GSEQ_S == GSEQ_NS
unichar (*scImp)(NSString*, SEL, NSUInteger);
void (*sgImp)(NSString*, SEL, unichar*, NSRange);
#endif
#if GSEQ_O == GSEQ_NS
unichar (*ocImp)(NSString*, SEL, NSUInteger);
void (*ogImp)(NSString*, SEL, unichar*, NSRange);
#endif
#if GSEQ_S == GSEQ_NS || GSEQ_S == GSEQ_US
NSRange (*srImp)(NSString*, SEL, NSUInteger);
#endif
#if GSEQ_O == GSEQ_NS || GSEQ_O == GSEQ_US
NSRange (*orImp)(NSString*, SEL, NSUInteger);
#endif
#if 0
/* Check that the search range is reasonable */
NSUInteger myLength = GSEQ_SLEN;
/* Range should be checked in calling code */
if (aRange.location > myLength)
[NSException raise: NSRangeException format: @"Invalid location."];
if (aRange.length > (myLength - aRange.location))
[NSException raise: NSRangeException format: @"Invalid location+length."];
#endif
/* Ensure the string can be found */
strLength = GSEQ_OLEN;
if (strLength > aRange.length || strLength == 0)
return (NSRange){NSNotFound, 0};
/*
* Cache method implementations for getting characters and ranges
*/
#if GSEQ_S == GSEQ_NS
scImp = (unichar (*)(NSString*,SEL,NSUInteger))
[(id)s methodForSelector: caiSel];
sgImp = (void (*)(NSString*,SEL,unichar*,NSRange))
[(id)s methodForSelector: gcrSel];
#endif
#if GSEQ_O == GSEQ_NS
ocImp = (unichar (*)(NSString*,SEL,NSUInteger))
[(id)o methodForSelector: caiSel];
ogImp = (void (*)(NSString*,SEL,unichar*,NSRange))
[(id)o methodForSelector: gcrSel];
#endif
#if GSEQ_S == GSEQ_NS || GSEQ_S == GSEQ_US
srImp = (NSRange (*)(NSString*,SEL,NSUInteger))
[(id)s methodForSelector: ranSel];
#endif
#if GSEQ_O == GSEQ_NS || GSEQ_O == GSEQ_US
orImp = (NSRange (*)(NSString*,SEL,NSUInteger))
[(id)o methodForSelector: ranSel];
#endif
switch (mask)
{
case GSEQ_FCLS:
case GSEQ_FCLAS:
{
unichar strFirstCharacter = GSEQ_OGETC(0);
myIndex = aRange.location;
myEndIndex = rangeEnd - strLength;
if (mask & NSAnchoredSearch)
myEndIndex = myIndex;
for (;;)
{
NSUInteger i = 1;
unichar myCharacter = GSEQ_SGETC(myIndex);
unichar strCharacter = strFirstCharacter;
for (;;)
{
if ((myCharacter != strCharacter) &&
((uni_tolower(myCharacter) != uni_tolower(strCharacter))))
break;
if (i == strLength)
return (NSRange){myIndex, strLength};
if (myIndex + i >= rangeEnd)
break;
myCharacter = GSEQ_SGETC(myIndex + i);
strCharacter = GSEQ_OGETC(i);
i++;
}
if (myIndex == myEndIndex)
break;
myIndex++;
}
return (NSRange){NSNotFound, 0};
}
case GSEQ_BCLS:
case GSEQ_BCLAS:
{
unichar strFirstCharacter = GSEQ_OGETC(0);
myIndex = rangeEnd - strLength;
myEndIndex = aRange.location;
if (mask & NSAnchoredSearch)
myEndIndex = myIndex;
for (;;)
{
NSUInteger i = 1;
unichar myCharacter = GSEQ_SGETC(myIndex);
unichar strCharacter = strFirstCharacter;
for (;;)
{
if ((myCharacter != strCharacter) &&
((uni_tolower(myCharacter) != uni_tolower(strCharacter))))
break;
if (i == strLength)
return (NSRange){myIndex, strLength};
if (myIndex + i >= rangeEnd)
break;
myCharacter = GSEQ_SGETC(myIndex + i);
strCharacter = GSEQ_OGETC(i);
i++;
}
if (myIndex-- == myEndIndex)
break;
}
return (NSRange){NSNotFound, 0};
}
case GSEQ_FLS:
case GSEQ_FLAS:
{
unichar strFirstCharacter = GSEQ_OGETC(0);
myIndex = aRange.location;
myEndIndex = rangeEnd - strLength;
if (mask & NSAnchoredSearch)
myEndIndex = myIndex;
for (;;)
{
NSUInteger i = 1;
unichar myCharacter = GSEQ_SGETC(myIndex);
unichar strCharacter = strFirstCharacter;
for (;;)
{
if (myCharacter != strCharacter)
break;
if (i == strLength)
return (NSRange){myIndex, strLength};
if (myIndex + i >= rangeEnd)
break;
myCharacter = GSEQ_SGETC(myIndex + i);
strCharacter = GSEQ_OGETC(i);
i++;
}
if (myIndex++ == myEndIndex)
break;
}
return (NSRange){NSNotFound, 0};
}
case GSEQ_BLS:
case GSEQ_BLAS:
{
unichar strFirstCharacter = GSEQ_OGETC(0);
myIndex = rangeEnd - strLength;
myEndIndex = aRange.location;
if (mask & NSAnchoredSearch)
myEndIndex = myIndex;
for (;;)
{
NSUInteger i = 1;
unichar myCharacter = GSEQ_SGETC(myIndex);
unichar strCharacter = strFirstCharacter;
for (;;)
{
if (myCharacter != strCharacter)
break;
if (i == strLength)
return (NSRange){myIndex, strLength};
if (myIndex + i >= rangeEnd)
break;
myCharacter = GSEQ_SGETC(myIndex + i);
strCharacter = GSEQ_OGETC(i);
i++;
}
if (myIndex-- == myEndIndex)
break;
}
return (NSRange){NSNotFound, 0};
}
case GSEQ_FCS:
case GSEQ_FCAS:
{
NSUInteger strBaseLength = [(NSString*)o _baseLength];
NSRange iRange;
myIndex = aRange.location;
myEndIndex = rangeEnd - strBaseLength;
if (mask & NSAnchoredSearch)
myEndIndex = myIndex;
iRange = GSEQ_ORANGE(0);
if (iRange.length)
{
GSEQ_MAKE(iBuf, iSeq, iRange.length);
GSEQ_OGETR(iBuf, iRange);
GSeq_lowercase(&iSeq);
for (;;)
{
NSRange sRange = GSEQ_SRANGE(myIndex);
GSEQ_MAKE(sBuf, sSeq, sRange.length);
GSEQ_SGETR(sBuf, sRange);
GSeq_lowercase(&sSeq);
if (GSeq_compare(&iSeq, &sSeq) == NSOrderedSame)
{
NSUInteger myCount = sRange.length;
NSUInteger strCount = iRange.length;
if (strCount >= strLength)
{
return (NSRange){myIndex, myCount};
}
while (myIndex + myCount < rangeEnd)
{
NSRange r0 = GSEQ_SRANGE(myIndex + myCount);
GSEQ_MAKE(b0, s0, r0.length);
NSRange r1 = GSEQ_ORANGE(strCount);
GSEQ_MAKE(b1, s1, r1.length);
GSEQ_SGETR(b0, r0);
GSEQ_OGETR(b1, r1);
if (GSeq_compare(&s0, &s1) != NSOrderedSame)
{
GSeq_lowercase(&s0);
GSeq_lowercase(&s1);
if (GSeq_compare(&s0, &s1) != NSOrderedSame)
{
break;
}
}
myCount += r0.length;
strCount += r1.length;
if (strCount >= strLength)
{
return (NSRange){myIndex, myCount};
}
}
}
myIndex += sRange.length;
if (myIndex > myEndIndex)
break;
}
}
return (NSRange){NSNotFound, 0};
}
case GSEQ_BCS:
case GSEQ_BCAS:
{
NSUInteger strBaseLength = [(NSString*)o _baseLength];
NSRange iRange;
myIndex = rangeEnd - strBaseLength;
myEndIndex = aRange.location;
if (mask & NSAnchoredSearch)
myEndIndex = myIndex;
iRange = GSEQ_ORANGE(0);
if (iRange.length)
{
GSEQ_MAKE(iBuf, iSeq, iRange.length);
GSEQ_OGETR(iBuf, iRange);
GSeq_lowercase(&iSeq);
for (;;)
{
NSRange sRange = GSEQ_SRANGE(myIndex);
GSEQ_MAKE(sBuf, sSeq, sRange.length);
GSEQ_SGETR(sBuf, sRange);
GSeq_lowercase(&sSeq);
if (GSeq_compare(&iSeq, &sSeq) == NSOrderedSame)
{
NSUInteger myCount = sRange.length;
NSUInteger strCount = iRange.length;
if (strCount >= strLength)
{
return (NSRange){myIndex, myCount};
}
while (myIndex + myCount < rangeEnd)
{
NSRange r0 = GSEQ_SRANGE(myIndex + myCount);
GSEQ_MAKE(b0, s0, r0.length);
NSRange r1 = GSEQ_ORANGE(strCount);
GSEQ_MAKE(b1, s1, r1.length);
GSEQ_SGETR(b0, r0);
GSEQ_OGETR(b1, r1);
if (GSeq_compare(&s0, &s1) != NSOrderedSame)
{
GSeq_lowercase(&s0);
GSeq_lowercase(&s1);
if (GSeq_compare(&s0, &s1) != NSOrderedSame)
{
break;
}
}
myCount += r0.length;
strCount += r1.length;
if (strCount >= strLength)
{
return (NSRange){myIndex, myCount};
}
}
}
if (myIndex-- <= myEndIndex)
break;
while (uni_isnonsp(GSEQ_SGETC(myIndex))
&& (myIndex > 0))