32
32
* The second part of the file contains inline function definitions that
33
33
* are designed to be modified depending on the defined macros at the
34
34
* point where they are included. This is meant to be included multiple
35
* times so the same code can be used for NSString, NSGString, and
35
* times so the same code can be used for NSString, and subclasses.
39
38
#ifndef __GSeq_h_GNUSTEP_BASE_INCLUDE
73
72
GSeqStruct SEQ = { BUF, LEN, LEN * MAXDEC, 0 }
76
* A function to normalize a unicode character sequence.
75
* A function to normalize a unicode character sequence ... produces a
76
* sequence containing composed characters in a well defined order and
77
* with a nul terminator as well as a character count.
78
79
static inline void GSeq_normalize(GSeq seq)
80
81
unsigned count = seq->count;
81
unichar *source = seq->chars;
85
unichar *source = seq->chars;
85
86
unichar target[count*MAXDEC+1];
90
unichar *spoint = source;
91
unichar *tpoint = target;
93
source[count] = (unichar)(0);
97
unichar *dpoint = uni_is_decomp(*spoint);
90
* Pre-scan ... anything with a code under 0x00C0 is not a decomposable
91
* character, so we don't need to expand it.
92
* If there are no decomposable characters or composed sequences, the
93
* sequence is already normalised and we don't need to make any changes.
97
if (source[base] >= 0x00C0)
103
source[count] = (unichar)(0);
108
* Now expand decomposable characters into the long format.
109
* Use the 'base' value to avoid re-checking characters which have
110
* already been expanded.
114
unichar *spoint = &source[base];
115
unichar *tpoint = &target[base];
116
unsigned newbase = 0;
120
unichar *dpoint = uni_is_decomp(*spoint);
130
*tpoint++ = *dpoint++;
134
newbase = (spoint - source) + 1;
140
count = tpoint - target;
141
memcpy(&source[base], &target[base], 2*(count - base));
142
source[count] = (unichar)(0);
107
*tpoint++ = *dpoint++;
114
count = tpoint - target;
115
memcpy(source, target, 2*count);
155
* Now standardise ordering of all composed character sequences.
125
unichar *first = seq->chars;
126
unichar *second = first + 1;
130
for (i = 1; i < count; i++)
132
if (uni_cop(*second))
163
unichar *first = seq->chars;
164
unichar *second = first + 1;
168
for (i = 1; i < count; i++)
134
if (uni_cop(*first) > uni_cop(*second))
136
unichar tmp = *first;
142
else if (uni_cop(*first) == uni_cop(*second))
144
if (*first > *second)
146
unichar tmp = *first;
170
if (uni_cop(*second))
172
if (uni_cop(*first) > uni_cop(*second))
174
unichar tmp = *first;
180
else if (uni_cop(*first) == uni_cop(*second))
182
if (*first > *second)
184
unichar tmp = *first;
251
290
* Set up macros for dealing with 'self' on the basis of GSQ_S
253
292
#if GSEQ_S == GSEQ_US
254
#define GSEQ_ST ivars
293
#define GSEQ_ST GSStr
255
294
#define GSEQ_SLEN s->_count
256
295
#define GSEQ_SGETC(I) s->_contents.u[I]
257
296
#define GSEQ_SGETR(B,R) memcpy(B, &s->_contents.u[R.location], 2*(R).length)
258
297
#define GSEQ_SRANGE(I) (*srImp)((id)s, ranSel, I)
260
299
#if GSEQ_S == GSEQ_CS
261
#define GSEQ_ST ivars
300
#define GSEQ_ST GSStr
262
301
#define GSEQ_SLEN s->_count
263
302
#define GSEQ_SGETC(I) (unichar)s->_contents.c[I]
264
303
#define GSEQ_SGETR(B,R) ( { \
283
322
* Set up macros for dealing with 'other' string on the basis of GSQ_O
285
324
#if GSEQ_O == GSEQ_US
286
#define GSEQ_OT ivars
325
#define GSEQ_OT GSStr
287
326
#define GSEQ_OLEN o->_count
288
327
#define GSEQ_OGETC(I) o->_contents.u[I]
289
328
#define GSEQ_OGETR(B,R) memcpy(B, &o->_contents.u[R.location], 2*(R).length)
290
329
#define GSEQ_ORANGE(I) (*orImp)((id)o, ranSel, I)
292
331
#if GSEQ_O == GSEQ_CS
293
#define GSEQ_OT ivars
332
#define GSEQ_OT GSStr
294
333
#define GSEQ_OLEN o->_count
295
334
#define GSEQ_OGETC(I) (unichar)o->_contents.c[I]
296
335
#define GSEQ_OGETR(B,R) ( { \
372
411
#if GSEQ_S == GSEQ_NS
373
sgImp = (void (*)())[(id)s methodForSelector: gcrSel];
412
sgImp = (void (*)(NSString*,SEL,unichar*,NSRange))
413
[(id)s methodForSelector: gcrSel];
374
414
GSEQ_SGETR(sBuf, aRange);
376
416
#if GSEQ_S == GSEQ_CS
382
422
#if GSEQ_O == GSEQ_NS
383
ogImp = (void (*)())[(id)o methodForSelector: gcrSel];
423
ogImp = (void (*)(NSString*,SEL,unichar*,NSRange))
424
[(id)o methodForSelector: gcrSel];
384
425
GSEQ_OGETR(oBuf, NSMakeRange(0, oLen));
386
427
#if GSEQ_O == GSEQ_CS
448
489
#if GSEQ_S == GSEQ_NS || GSEQ_S == GSEQ_US
449
srImp = (NSRange (*)())[(id)s methodForSelector: ranSel];
490
srImp = (NSRange (*)(NSString*, SEL, unsigned))
491
[(id)s methodForSelector: ranSel];
451
493
#if GSEQ_O == GSEQ_NS || GSEQ_O == GSEQ_US
452
orImp = (NSRange (*)())[(id)o methodForSelector: ranSel];
494
orImp = (NSRange (*)(NSString*, SEL, unsigned))
495
[(id)o methodForSelector: ranSel];
454
497
#if GSEQ_S == GSEQ_NS
455
sgImp = (void (*)())[(id)s methodForSelector: gcrSel];
498
sgImp = (void (*)(NSString*, SEL, unichar*, NSRange))
499
[(id)s methodForSelector: gcrSel];
457
501
#if GSEQ_O == GSEQ_NS
458
ogImp = (void (*)())[(id)o methodForSelector: gcrSel];
502
ogImp = (void (*)(NSString*, SEL, unichar*, NSRange))
503
[(id)o methodForSelector: gcrSel];
462
506
while (sCount < end)
464
508
if (oCount >= oLength)
556
600
* Cache method implementations for getting characters and ranges
558
602
#if GSEQ_S == GSEQ_NS
559
scImp = (unichar (*)())[(id)s methodForSelector: caiSel];
560
sgImp = (void (*)())[(id)s methodForSelector: gcrSel];
603
scImp = (unichar (*)(NSString*,SEL,unsigned))
604
[(id)s methodForSelector: caiSel];
605
sgImp = (void (*)(NSString*,SEL,unichar*,NSRange))
606
[(id)s methodForSelector: gcrSel];
562
608
#if GSEQ_O == GSEQ_NS
563
ocImp = (unichar (*)())[(id)o methodForSelector: caiSel];
564
ogImp = (void (*)())[(id)o methodForSelector: gcrSel];
609
ocImp = (unichar (*)(NSString*,SEL,unsigned))
610
[(id)o methodForSelector: caiSel];
611
ogImp = (void (*)(NSString*,SEL,unichar*,NSRange))
612
[(id)o methodForSelector: gcrSel];
566
614
#if GSEQ_S == GSEQ_NS || GSEQ_S == GSEQ_US
567
srImp = (NSRange (*)())[(id)s methodForSelector: ranSel];
615
srImp = (NSRange (*)(NSString*,SEL,unsigned))
616
[(id)s methodForSelector: ranSel];
569
618
#if GSEQ_O == GSEQ_NS || GSEQ_O == GSEQ_US
570
orImp = (NSRange (*)())[(id)o methodForSelector: ranSel];
619
orImp = (NSRange (*)(NSString*,SEL,unsigned))
620
[(id)o methodForSelector: ranSel];