Skip to content

Commit a792b72

Browse files
NWilsonGreg Minshall
andcommitted
Add /i option to pcre2demo.c
Co-authored-by: Greg Minshall <minshall@umich.edu>
1 parent 9d1a620 commit a792b72

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

doc/pcre2sample.3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ this:
5050
.sp
5151
./pcre2demo 'cat|dog' 'the cat sat on the mat'
5252
./pcre2demo -g 'cat|dog' 'the dog sat on the cat'
53+
./pcre2demo -i 'cat' 'the dog sat on the CAT'
5354
.sp
5455
Note that there is a much more comprehensive test program, called
5556
.\" HREF

src/pcre2demo.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ PCRE2_SPTR name_table;
7575

7676
int crlf_is_newline;
7777
int errornumber;
78-
int find_all;
78+
int find_all, caseless_match;
7979
int i;
8080
int rc;
8181
int utf8;
@@ -93,16 +93,21 @@ pcre2_match_data *match_data;
9393

9494

9595
/**************************************************************************
96-
* First, sort out the command line. There is only one possible option at *
97-
* the moment, "-g" to request repeated matching to find all occurrences, *
98-
* like Perl's /g option. We set the variable find_all to a non-zero value *
99-
* if the -g option is present. *
96+
* First, sort out the command line. Options: *
97+
* - "-g" to request repeated matching to find all occurrences, *
98+
* like Perl's /g option. We set the variable find_all to a non-zero *
99+
* value if the -g option is present. *
100+
* - "-i" to request caseless matching, like Perl's /i option. We set the *
101+
* variable caseless_match to PCRE2_CASELESS if the -i option is *
102+
* present. *
100103
**************************************************************************/
101104

102105
find_all = 0;
106+
caseless_match = 0;
103107
for (i = 1; i < argc; i++)
104108
{
105109
if (strcmp(argv[i], "-g") == 0) find_all = 1;
110+
else if (strcmp(argv[i], "-i") == 0) caseless_match = PCRE2_CASELESS;
106111
else if (argv[i][0] == '-')
107112
{
108113
printf("Unrecognised option %s\n", argv[i]);
@@ -138,7 +143,7 @@ subject_length = (PCRE2_SIZE)strlen((char *)subject);
138143
re = pcre2_compile(
139144
pattern, /* the pattern */
140145
PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */
141-
0, /* default options */
146+
caseless_match, /* possibly enable caseless */
142147
&errornumber, /* for error number */
143148
&erroroffset, /* for error offset */
144149
NULL); /* use default compile context */

0 commit comments

Comments
 (0)