@@ -54,16 +54,16 @@ struct tre_node
54
54
unsigned char type ;
55
55
union
56
56
{
57
- unsigned char ch ; // character
58
- unsigned char * cc ; // character class buffer
57
+ char ch ; // character
58
+ char * cc ; // character class buffer
59
59
unsigned short mn [2 ]; // {m,n} quantifier
60
- };
60
+ } u ;
61
61
};
62
62
63
63
struct tre_comp
64
64
{
65
65
tre_node nodes [TRE_MAX_NODES ];
66
- unsigned char buffer [TRE_MAX_BUFLEN ];
66
+ char buffer [TRE_MAX_BUFLEN ];
67
67
};
68
68
69
69
// Compile regex string pattern as tre_comp struct tregex
@@ -190,10 +190,10 @@ TRE_DEF int tre_ncompile(const char *pattern, unsigned plen, tre_comp *tregex)
190
190
return tre_err ("NULL/empty string or tre_comp" );
191
191
192
192
tre_node * tnode = tregex -> nodes ;
193
- unsigned char * buf = tregex -> buffer ;
193
+ char * buf = tregex -> buffer ;
194
194
unsigned buflen = sizeof tregex -> buffer ;
195
- unsigned char quable = 0 ; // is the last node quantifiable
196
- unsigned char temp ;
195
+ char quable = 0 ; // is the last node quantifiable
196
+ char temp ;
197
197
198
198
unsigned idx = 0 ;
199
199
@@ -243,7 +243,7 @@ TRE_DEF int tre_ncompile(const char *pattern, unsigned plen, tre_comp *tregex)
243
243
case 'S' : tnode [j ].type = TRE_NSPACE ; break ;
244
244
245
245
// Not in [dDwWsS]
246
- default : tnode [j ].type = TRE_CHAR ; tnode [j ].ch = pattern [i ]; break ;
246
+ default : tnode [j ].type = TRE_CHAR ; tnode [j ].u . ch = pattern [i ]; break ;
247
247
}
248
248
} break ;
249
249
@@ -254,7 +254,7 @@ TRE_DEF int tre_ncompile(const char *pattern, unsigned plen, tre_comp *tregex)
254
254
255
255
// Look-ahead to determine if negated
256
256
tnode [j ].type = (pattern [i + 1 ] == '^' ) ? (i ++ , TRE_NCLASS ) : TRE_CLASS ;
257
- tnode [j ].cc = buf + idx ;
257
+ tnode [j ].u . cc = buf + idx ;
258
258
259
259
// Copy characters inside [...] to buffer
260
260
while (pattern [++ i ] != ']' && i < plen )
@@ -318,13 +318,13 @@ TRE_DEF int tre_ncompile(const char *pattern, unsigned plen, tre_comp *tregex)
318
318
{
319
319
if (i >= plen || pattern [i ] < '0' || pattern [i ] > '9' )
320
320
return tre_err ("Non-digit min value in quantifier" );
321
- val = 10 * val + (pattern [i ++ ] - '0' );
321
+ val = 10 * val + (unsigned ) ( pattern [i ++ ] - '0' );
322
322
}
323
323
while (pattern [i ] != ',' && pattern [i ] != '}' );
324
324
325
325
if (val > TRE_MAXQUANT )
326
326
return tre_err ("Min value too big in quantifier" );
327
- tnode [j ].mn [0 ] = val ;
327
+ tnode [j ].u . mn [0 ] = val ;
328
328
329
329
if (pattern [i ] == ',' )
330
330
{
@@ -341,19 +341,19 @@ TRE_DEF int tre_ncompile(const char *pattern, unsigned plen, tre_comp *tregex)
341
341
{
342
342
if (i >= plen || pattern [i ] < '0' || pattern [i ] > '9' )
343
343
return tre_err ("Non-digit max value in quantifier" );
344
- val = 10 * val + (pattern [i ++ ] - '0' );
344
+ val = 10 * val + (unsigned ) ( pattern [i ++ ] - '0' );
345
345
}
346
346
347
- if (val > TRE_MAXQUANT || val < tnode [j ].mn [0 ])
347
+ if (val > TRE_MAXQUANT || val < tnode [j ].u . mn [0 ])
348
348
return tre_err ("Max value too big or less than min value in quantifier" );
349
349
}
350
350
}
351
351
tnode [j ].type = (i + 1 < plen && pattern [i + 1 ] == '?' ) ? (i ++ , TRE_LQUANT ) : TRE_QUANT ;
352
- tnode [j ].mn [1 ] = val ;
352
+ tnode [j ].u . mn [1 ] = val ;
353
353
} break ;
354
354
355
355
// Regular characters
356
- default : quable = 1 ; tnode [j ].type = TRE_CHAR ; tnode [j ].ch = pattern [i ]; break ;
356
+ default : quable = 1 ; tnode [j ].type = TRE_CHAR ; tnode [j ].u . ch = pattern [i ]; break ;
357
357
}
358
358
i ++ ;
359
359
j ++ ;
@@ -389,9 +389,9 @@ static int matchmetachar(char c, char mc)
389
389
}
390
390
391
391
// note: compiler makes sure '\\' is followed by one of 'dDwWsS\\'
392
- static int matchcharclass (char c , const unsigned char * str )
392
+ static int matchcharclass (char c , const char * str )
393
393
{
394
- unsigned char rmax ;
394
+ char rmax ;
395
395
while (* str != '\0' )
396
396
{
397
397
if (str [0 ] == '\\' )
@@ -436,10 +436,10 @@ static int matchone(const tre_node *tnode, char c)
436
436
{
437
437
switch (tnode -> type )
438
438
{
439
- case TRE_CHAR : return (tnode -> ch == c );
439
+ case TRE_CHAR : return (tnode -> u . ch == c );
440
440
case TRE_DOT : return TRE_MATCHDOT (c );
441
- case TRE_CLASS : return matchcharclass (c , tnode -> cc );
442
- case TRE_NCLASS : return !matchcharclass (c , tnode -> cc );
441
+ case TRE_CLASS : return matchcharclass (c , tnode -> u . cc );
442
+ case TRE_NCLASS : return !matchcharclass (c , tnode -> u . cc );
443
443
case TRE_DIGIT : return TRE_MATCHDIGIT (c );
444
444
case TRE_NDIGIT : return !TRE_MATCHDIGIT (c );
445
445
case TRE_ALPHA : return TRE_MATCHALNUM (c );
@@ -511,9 +511,9 @@ static const char *matchpattern(const tre_node *nodes, const char *text, const c
511
511
case TRE_LQMARK :
512
512
return matchquant_lazy (nodes , text , tend , 0 , 1 );
513
513
case TRE_QUANT :
514
- return matchquant (nodes , text , tend , nodes [1 ].mn [0 ], nodes [1 ].mn [1 ]);
514
+ return matchquant (nodes , text , tend , nodes [1 ].u . mn [0 ], nodes [1 ]. u .mn [1 ]);
515
515
case TRE_LQUANT :
516
- return matchquant_lazy (nodes , text , tend , nodes [1 ].mn [0 ], nodes [1 ].mn [1 ]);
516
+ return matchquant_lazy (nodes , text , tend , nodes [1 ].u . mn [0 ], nodes [1 ]. u .mn [1 ]);
517
517
case TRE_STAR :
518
518
return matchquant (nodes , text , tend , 0 , TRE_MAXPLUS );
519
519
case TRE_LSTAR :
@@ -554,15 +554,15 @@ void tre_print(const tre_comp *tregex)
554
554
printf ("type: %s" , tre_typenames [tnode [i ].type ]);
555
555
if (tnode [i ].type == TRE_CLASS || tnode [i ].type == TRE_NCLASS )
556
556
{
557
- printf (" \"%s\"" , tnode [i ].cc );
557
+ printf (" \"%s\"" , tnode [i ].u . cc );
558
558
}
559
559
else if (tnode [i ].type == TRE_QUANT || tnode [i ].type == TRE_LQUANT )
560
560
{
561
- printf (" {%d,%d}" , tnode [i ].mn [0 ], tnode [i ].mn [1 ]);
561
+ printf (" {%d,%d}" , tnode [i ].u . mn [0 ], tnode [i ]. u .mn [1 ]);
562
562
}
563
563
else if (tnode [i ].type == TRE_CHAR )
564
564
{
565
- printf (" '%c'" , tnode [i ].ch );
565
+ printf (" '%c'" , tnode [i ].u . ch );
566
566
}
567
567
printf ("\n" );
568
568
}
0 commit comments