BasicNumberUnlocalizer::getNumberRegex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace ValueParsers;
4
5
/**
6
 * @see \ValueFormatters\BasicNumberLocalizer
7
 *
8
 * @since 0.3
9
 *
10
 * @license GPL-2.0-or-later
11
 * @author Daniel Kinzler
12
 */
13
class BasicNumberUnlocalizer implements NumberUnlocalizer {
14
15
	/**
16
	 * @see NumberUnlocalizer::unlocalizeNumber
17
	 *
18
	 * @param string $number string to process
19
	 *
20
	 * @return string unlocalized number, in a form suitable for floatval resp. intval.
21
	 */
22 19
	public function unlocalizeNumber( $number ) {
23 19
		return preg_replace( '/[^-+\d.EX]+/i', '', $number );
24
	}
25
26
	/**
27
	 * @see NumberUnlocalizer::getNumberRegex
28
	 *
29
	 * This implementation returns an expression that will match a number
30
	 * in english notation, including scientific notation.
31
	 *
32
	 * @param string $delimiter The regex delimiter, used for escaping.
33
	 *
34
	 * @return string regular expression
35
	 */
36 33
	public function getNumberRegex( $delimiter = '/' ) {
37 33
		return '(?:[-+]\s*)?(?:[\d,]+\.\d*|\.?\d+)(?:[eE][-+]?\d+)?';
38
	}
39
40
	/**
41
	 * @see NumberUnlocalizer::getUnitRegex
42
	 *
43
	 * @param string $delimiter Unused.
44
	 *
45
	 * @return string An empty string.
46
	 */
47 10
	public function getUnitRegex( $delimiter = '/' ) {
48
		// TODO: Discuss and specify what QuantityParser should accept.
49 10
		return '';
50
	}
51
52
}
53