MCPcopy Create free account
hub / github.com/coreutils/coreutils / initialize_regex

Function initialize_regex

src/ptx.c:420–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418`------------------------------------------------------------------------*/
419
420static void
421initialize_regex (void)
422{
423 /* Initialize the case folding table. */
424
425 if (ignore_case)
426 for (int character = 0; character < CHAR_SET_SIZE; character++)
427 folded_chars[character] = toupper (character);
428
429 /* Unless the user already provided a description of the end of line or
430 end of sentence sequence, select an end of line sequence to compile.
431 If the user provided an empty definition, thus disabling end of line
432 or sentence feature, make it null to speed up tests. If GNU
433 extensions are enabled, use end of sentence like in GNU emacs. If
434 disabled, use end of lines. */
435
436 if (context_regex.string)
437 {
438 if (!*context_regex.string)
439 context_regex.string = NULL;
440 }
441 else if (gnu_extensions && !input_reference)
442 context_regex.string = "[.?!][]\"')}]*\\($\\|\t\\| \\)[ \t\n]*";
443 else
444 context_regex.string = "\n";
445
446 if (context_regex.string)
447 compile_regex (&context_regex);
448
449 /* If the user has already provided a non-empty regexp to describe
450 words, compile it. Else, unless this has already been done through
451 a user provided Break character file, construct a fastmap of
452 characters that may appear in a word. If GNU extensions enabled,
453 include only letters of the underlying character set. If disabled,
454 include almost everything, even punctuation; stop only on white
455 space. */
456
457 if (word_regex.string)
458 compile_regex (&word_regex);
459 else if (!break_file)
460 {
461 if (gnu_extensions)
462 {
463
464 /* Simulate \w+. */
465
466 for (int character = 0; character < CHAR_SET_SIZE; character++)
467 word_fastmap[character] = !! isalpha (character);
468 }
469 else
470 {
471
472 /* Simulate [^ \t\n]+. */
473
474 memset (word_fastmap, 1, CHAR_SET_SIZE);
475 word_fastmap[' '] = 0;
476 word_fastmap['\t'] = 0;
477 word_fastmap['\n'] = 0;

Callers 1

mainFunction · 0.85

Calls 1

compile_regexFunction · 0.85

Tested by

no test coverage detected