Code Duplication    Length = 19-22 lines in 2 locations

src/MetaCharacters.php 2 locations

@@ 164-185 (lines=22) @@
161
	* @param  string $expr
162
	* @return bool
163
	*/
164
	protected function exprIsChar($expr)
165
	{
166
		$regexps = [
167
			// Escaped literal or escape sequence such as \w but not \R
168
			'(^\\\\[adefhnrstvwDHNSVW\\W]$)D',
169
170
			// Unicode properties such as \pL or \p{Lu}
171
			'(^\\\\p(?:.|\\{[^}]+\\})$)Di',
172
173
			// An escape sequence such as \x1F or \x{2600}
174
			'(^\\\\x(?:[0-9a-f]{2}|\\{[^}]+\\})$)Di'
175
		];
176
		foreach ($regexps as $regexp)
177
		{
178
			if (preg_match($regexp, $expr))
179
			{
180
				return true;
181
			}
182
		}
183
184
		return false;
185
	}
186
187
	/**
188
	* Test whether given expression is quantifiable
@@ 193-211 (lines=19) @@
190
	* @param  string $expr
191
	* @return bool
192
	*/
193
	protected function exprIsQuantifiable($expr)
194
	{
195
		$regexps = [
196
			// A dot or \R
197
			'(^(?:\\.|\\\\R)$)D',
198
199
			// A character class
200
			'(^\\[\\^?(?:([^\\\\\\]]|\\\\.)(?:-(?-1))?)++\\]$)D'
201
		];
202
		foreach ($regexps as $regexp)
203
		{
204
			if (preg_match($regexp, $expr))
205
			{
206
				return true;
207
			}
208
		}
209
210
		return $this->exprIsChar($expr);
211
	}
212
}