Skip to content

Commit 69914a6

Browse files
committed
Added --with-delimiters and --with-flags
Fixes #2
1 parent 3e58f83 commit 69914a6

File tree

2 files changed

+59
-17
lines changed

2 files changed

+59
-17
lines changed

src/Build.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ protected function configure(): void
7474
'Whether the regexp is meant to be used whole',
7575
true
7676
);
77+
$this->addOption(
78+
'with-delimiters',
79+
null,
80+
InputOption::VALUE_NONE,
81+
"Output the regexp's delimiter"
82+
);
83+
$this->addOption(
84+
'with-flags',
85+
null,
86+
InputOption::VALUE_NONE,
87+
"Output the regexp's flags (requires --with-delimiters)"
88+
);
7789

7890
$this->addArgument('strings', InputArgument::IS_ARRAY);
7991
}
@@ -91,6 +103,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
91103
$builder->standalone = $input->getOption('standalone');
92104
$regexp = $builder->build($strings);
93105

106+
if ($input->getOption('with-delimiters'))
107+
{
108+
$regexp = $config['delimiter'][0] . $regexp . $config['delimiter'][-1];
109+
if ($input->getOption('with-flags'))
110+
{
111+
$regexp .= $this->sortFlags($input->getOption('flags'));
112+
}
113+
}
114+
94115
$filepath = $input->getOption('outfile');
95116
if ($filepath === '-')
96117
{

tests/BuildTest.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,44 @@ public function getSuccessTests(): array
132132
],
133133
'[\\u{1F600}\\u{1F601}]'
134134
],
135-
// [
136-
// [
137-
// 'strings' => ["\u{1F600}", "\u{1F601}"],
138-
// '--preset' => 'javascript',
139-
// '--standalone' => true
140-
// ],
141-
// '/\\uD83D[\\uDE00\\uDE01]/'
142-
// ],
143-
// [
144-
// [
145-
// 'strings' => ["\u{1F600}", "\u{1F601}"],
146-
// '--flags' => 'u',
147-
// '--preset' => 'javascript',
148-
// '--standalone' => true
149-
// ],
150-
// '/[\\u{1F600}\\u{1F601}]/u'
151-
// ],
135+
[
136+
[
137+
'strings' => ["\u{1F600}", "\u{1F601}"],
138+
'--preset' => 'javascript',
139+
'--with-delimiters' => true,
140+
'--with-flags' => true
141+
],
142+
'/\\uD83D[\\uDE00\\uDE01]/'
143+
],
144+
[
145+
[
146+
'strings' => ["\u{1F600}", "\u{1F601}"],
147+
'--flags' => 'u',
148+
'--preset' => 'javascript',
149+
'--with-delimiters' => true,
150+
'--with-flags' => true
151+
],
152+
'/[\\u{1F600}\\u{1F601}]/u'
153+
],
154+
[
155+
[
156+
'strings' => ["\u{1F600}", "\u{1F601}"],
157+
'--preset' => 'pcre',
158+
'--with-delimiters' => true,
159+
'--with-flags' => true
160+
],
161+
'/\\xF0\\x9F\\x98[\\x80\\x81]/'
162+
],
163+
[
164+
[
165+
'strings' => ["\u{1F600}", "\u{1F601}"],
166+
'--flags' => 'u',
167+
'--preset' => 'pcre',
168+
'--with-delimiters' => true,
169+
'--with-flags' => true
170+
],
171+
'/[\\x{1F600}\\x{1F601}]/u'
172+
],
152173
[
153174
[
154175
'strings' => ["\u{1F600}", "\u{1F601}"],

0 commit comments

Comments
 (0)