Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Parsing US number succeeds in tests fails in actual usage #4

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
15b495e
Adds missing country code to region code map for global networks
ajayrungta May 15, 2012
5fd6674
Updates regex for exact matching & x/pcre_extended pattern modifier
ajayrungta May 18, 2012
ac7b620
Updates MetaData on Phone Number Plan & formatting rules from GoogleCode
ajayrungta May 18, 2012
b7a1b91
Updates Testing MetaData on PhoneNumber Plan & formatting rules from …
ajayrungta May 18, 2012
f44515d
Removes IN testing phone number metadata and updates test case
ajayrungta May 18, 2012
f673f98
Updates MetaData on Phone Number Plan & formatting rules from GoogleCode
ajayrungta May 19, 2012
75cf006
Changes keepRawInput to true in PhoneNumberUtil::parse
ajayrungta May 19, 2012
f264aba
Changes namespace & updates classes/comments/tests accordingly
ajayrungta May 19, 2012
2f6b42e
Moves hardcoded keepRawInput value to PhoneNumberUtil:parse() parameters
ajayrungta May 21, 2012
0bd0c73
Mobile pattern update to match 8551###### as valid indian mobile number
ajayrungta May 25, 2012
a1313a7
Merge pull request #1 from practo/mobile_8551_250512
justjkk May 25, 2012
4dc985e
Mobile pattern update to match 8747###### as valid indian mobile number
ajayrungta May 26, 2012
6a3fc71
Merge pull request #2 from practo/mobile_8747_260512
justjkk May 26, 2012
e8ae4ac
Updates MetaData on Phone Number Plan & formatting rules from GoogleCode
ajayrungta Jun 1, 2012
1e05200
Mobile pattern update to match 8740###### as valid indian mobile number
ajayrungta Jun 1, 2012
a072acb
Merge pull request #3 from practo/mobile_8740_010612
justjkk Jun 1, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CountryCodeSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace libphonenumber;

/**
* Country code source from number
*/
class CountryCodeSource
{
const FROM_NUMBER_WITH_PLUS_SIGN = 0;
const FROM_NUMBER_WITH_IDD = 1;
const FROM_NUMBER_WITHOUT_PLUS_SIGN = 2;
const FROM_DEFAULT_COUNTRY = 3;
}
3 changes: 2 additions & 1 deletion CountryCodeToRegionCodeMap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace com\google\i18n\phonenumbers;
namespace libphonenumber;

class CountryCodeToRegionCodeMap {

Expand Down Expand Up @@ -181,6 +181,7 @@ class CountryCodeToRegionCodeMap {
690 => array('TK'),
691 => array('FM'),
692 => array('MH'),
800 => array('001'),
850 => array('KP'),
852 => array('HK'),
853 => array('MO'),
Expand Down
2 changes: 1 addition & 1 deletion CountryCodeToRegionCodeMapForTesting.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace com\google\i18n\phonenumbers;
namespace libphonenumber;

class CountryCodeToRegionCodeMapForTesting {

Expand Down
16 changes: 16 additions & 0 deletions MatchType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace libphonenumber;

/**
* Types of phone number matches
* See detailed description beside the isNumberMatch() method
*/
class MatchType
{
const NOT_A_NUMBER = 0;
const NO_MATCH = 1;
const SHORT_NSN_MATCH = 2;
const NSN_MATCH = 3;
const EXACT_MATCH = 4;
}
121 changes: 121 additions & 0 deletions Matcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

namespace libphonenumber;

/**
* Matcher for various regex matching
*/
class Matcher
{
/**
* @var string
*/
private $pattern;

/**
* @var string
*/
private $subject;

/**
* @var array
*/
private $groups = array();

/**
* @param string $pattern
* @param string $subject
*/
public function __construct($pattern, $subject)
{
$this->pattern = $pattern;
$this->subject = $subject;
}

/**
* @return bool
*/
public function matches()
{
return preg_match('/^(?:' . str_replace('/', '\/', $this->pattern) . ')$/x', $this->subject, $this->groups, PREG_OFFSET_CAPTURE) > 0;
}

/**
* @return bool
*/
public function lookingAt()
{
$this->fullPatternMatchesNumber = preg_match_all('/^(?:' . str_replace('/', '\/', $this->pattern) . ')/x', $this->subject, $this->groups, PREG_OFFSET_CAPTURE);

return $this->fullPatternMatchesNumber > 0;
}

/**
* @return bool
*/
public function find()
{
return preg_match('/(?:' . str_replace('/', '\/', $this->pattern) . ')/x', $this->subject, $this->groups, PREG_OFFSET_CAPTURE) > 0;
}


/**
* @return int
*/
public function groupCount()
{
return count($this->groups);
}

/**
* @param int $group
*
* @return string
*/
public function group($group = null)
{
return $this->groups[$group - 1][0];
}

/**
* @return int
*/
public function end()
{
$lastGroup = $this->groups[$this->fullPatternMatchesNumber - 1][0];

return $lastGroup[1] + strlen($lastGroup[0]);
}

/**
* @param string $replacement
*
* @return string
*/
public function replaceFirst($replacement)
{
return preg_replace('/' . str_replace('/', '\/', $this->pattern) . '/', $replacement, $this->subject, 1);
}

/**
* @param string $replacement
*
* @return string
*/
public function replaceAll($replacement)
{
return preg_replace('/' . str_replace('/', '\/', $this->pattern) . '/', $replacement, $this->subject);
}

/**
* @param string $input
*
* @return Matcher
*/
public function reset($input = "")
{
$this->subject = $input;

return $this;
}
}
Loading