MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / AddFoldedRange

Function AddFoldedRange

extern/re2/re2/parse.cc:345–394  ·  view source on GitHub ↗

Add lo-hi to the class, along with their fold-equivalent characters. If lo-hi is already in the class, assume that the fold-equivalent chars are there too, so there's no work to do.

Source from the content-addressed store, hash-verified

343// If lo-hi is already in the class, assume that the fold-equivalent
344// chars are there too, so there's no work to do.
345static void AddFoldedRange(CharClassBuilder* cc, Rune lo, Rune hi, int depth) {
346 // AddFoldedRange calls itself recursively for each rune in the fold cycle.
347 // Most folding cycles are small: there aren't any bigger than four in the
348 // current Unicode tables. make_unicode_casefold.py checks that
349 // the cycles are not too long, and we double-check here using depth.
350 if (depth > 10) {
351 LOG(DFATAL) << "AddFoldedRange recurses too much.";
352 return;
353 }
354
355 if (!cc->AddRange(lo, hi)) // lo-hi was already there? we're done
356 return;
357
358 while (lo <= hi) {
359 const CaseFold* f = LookupCaseFold(unicode_casefold, num_unicode_casefold, lo);
360 if (f == NULL) // lo has no fold, nor does anything above lo
361 break;
362 if (lo < f->lo) { // lo has no fold; next rune with a fold is f->lo
363 lo = f->lo;
364 continue;
365 }
366
367 // Add in the result of folding the range lo - f->hi
368 // and that range's fold, recursively.
369 Rune lo1 = lo;
370 Rune hi1 = std::min<Rune>(hi, f->hi);
371 switch (f->delta) {
372 default:
373 lo1 += f->delta;
374 hi1 += f->delta;
375 break;
376 case EvenOdd:
377 if (lo1%2 == 1)
378 lo1--;
379 if (hi1%2 == 0)
380 hi1++;
381 break;
382 case OddEven:
383 if (lo1%2 == 0)
384 lo1--;
385 if (hi1%2 == 1)
386 hi1++;
387 break;
388 }
389 AddFoldedRange(cc, lo1, hi1, depth+1);
390
391 // Pick up where this fold left off.
392 lo = f->hi + 1;
393 }
394}
395
396// Pushes the literal rune r onto the stack.
397bool Regexp::ParseState::PushLiteral(Rune r) {

Callers 1

AddRangeFlagsMethod · 0.85

Calls 2

LookupCaseFoldFunction · 0.85
AddRangeMethod · 0.80

Tested by

no test coverage detected