1 | <?php |
||
14 | class FloatCoordinateParser extends LatLongParserBase { |
||
15 | |||
16 | const FORMAT_NAME = 'float-coordinate'; |
||
17 | |||
18 | /** |
||
19 | * @see LatLongParserBase::getParsedCoordinate |
||
20 | * |
||
21 | * @param string $coordinateSegment |
||
22 | * |
||
23 | * @return float |
||
24 | */ |
||
25 | 18 | protected function getParsedCoordinate( $coordinateSegment ) { |
|
28 | |||
29 | /** |
||
30 | * @see LatLongParserBase::areValidCoordinates |
||
31 | * |
||
32 | * @param string[] $normalizedCoordinateSegments |
||
33 | * |
||
34 | * @return bool |
||
35 | */ |
||
36 | 18 | protected function areValidCoordinates( array $normalizedCoordinateSegments ) { |
|
37 | // TODO: Implement localized decimal separator. |
||
38 | 18 | $baseRegExp = '\d{1,3}(\.\d{1,20})?'; |
|
39 | |||
40 | // Cache whether the coordinates are specified in directional format (a mixture of |
||
41 | // directional and non-directional is regarded invalid). |
||
42 | 18 | $directional = false; |
|
43 | |||
44 | 18 | $match = false; |
|
45 | |||
46 | 18 | foreach ( $normalizedCoordinateSegments as $i => $segment ) { |
|
47 | 18 | $segment = str_replace( ' ', '', $segment ); |
|
48 | |||
49 | $direction = '(' |
||
50 | 18 | . $this->getOption( self::OPT_NORTH_SYMBOL ) . '|' |
|
51 | 18 | . $this->getOption( self::OPT_SOUTH_SYMBOL ) . ')'; |
|
52 | |||
53 | 18 | if ( $i === 1 ) { |
|
54 | $direction = '(' |
||
55 | 18 | . $this->getOption( self::OPT_EAST_SYMBOL ) . '|' |
|
56 | 18 | . $this->getOption( self::OPT_WEST_SYMBOL ) . ')'; |
|
57 | } |
||
58 | |||
59 | 18 | $match = preg_match( |
|
60 | 18 | '/^(' . $baseRegExp . $direction . '|' . $direction . $baseRegExp . ')$/i', |
|
61 | 18 | $segment |
|
62 | ); |
||
63 | |||
64 | 18 | if ( $directional && !$match ) { |
|
65 | // Latitude is directional, longitude not. |
||
66 | break; |
||
67 | 18 | } elseif ( $match ) { |
|
68 | 10 | continue; |
|
69 | } |
||
70 | |||
71 | 8 | $match = preg_match( '/^(-)?' . $baseRegExp . '$/i', $segment ); |
|
72 | |||
73 | 8 | if ( !$match ) { |
|
74 | // Does neither match directional nor non-directional. |
||
75 | break; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | 18 | return ( 1 === $match ); |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * @see LatLongParserBase::splitString |
||
84 | * |
||
85 | * @param string $normalizedCoordinateString |
||
86 | * |
||
87 | * @throws ParseException if unable to split input string into two segments |
||
88 | * @return string[] |
||
89 | */ |
||
90 | 20 | protected function splitString( $normalizedCoordinateString ) { |
|
133 | |||
134 | } |
||
135 |