trying to parse phone for single country including international prefix
 check for provided country

 ==== Attributes

 * +phone+ - phone for parsing
 * +country+ - country to parse phone with
548968
def parse_country(phone, country)
      data = Phonelib.phone_data[country]
      return nil unless data

      # if country was provided and it's a valid country, trying to
      # create e164 representation of phone number,
      # kind of normalization for parsing
      e164 = convert_to_e164 with_replaced_national_prefix(phone, data), data
      # if phone starts with international prefix of provided
      # country try to reanalyze without international prefix for
      # all countries
      return analyze(e164[1..-1], nil) if Core::PLUS_SIGN == e164[0]
      # trying to parse number for provided country
      parse_single_country e164, data
    end
1017460
def format_phone(phone)
      regex = Regexp.new('[A-Z]+[a-z]+')
      if !phone.blank? && (phone != 'N/A' || phone != '0') && !regex.match(phone)
        phone_stripped = phone.gsub(/[^0-9]/, '')
        phone_step2 = phone_stripped && phone_stripped[0] == '1' ? phone_stripped[1..-1] : phone_stripped
        final_phone = !(phone_step2 && phone_step2.length < 10) ? "(#{phone_step2[0..2]}) #{(phone_step2[3..5])}-#{(phone_step2[6..9])}" : phone
      else
        final_phone = nil
      end
      final_phone
    end
312402
def extract_country_code(input, options={})
      options[:region] ||= Phoney.region
      intl_prefix = international_call_prefix_for(input, region: options[:region])
      
      # only try to extract a country code if we're dialing internationally
      if intl_prefix
        rest   = input[intl_prefix.count(NUMPAD_CHARS)..-1]
        region = Phoney::Region.all.find { |r| rest.start_with? r.country_code.to_s }
        
        region.country_code.to_s if region
      end
    end
839702
def _parse_phone(self, val):
        

        ret = {
            'type': None,
            'value': None
        }

        try:

            ret['type'] = val[1]['type']

        except (IndexError, KeyError, ValueError, TypeError):

                pass

        ret['value'] = val[3].strip()

        try:

            self.vars['phone'].append(ret)

        except AttributeError:

            self.vars['phone'] = []
            self.vars['phone'].append(ret)
12336
function strip_country_phone_code(formatted_number, metadata)
{
	if (!formatted_number || formatted_number[0] !== '+' || formatted_number === '+')
	{
		return formatted_number
	}

	for (const country_phone_code of Object.keys(metadata.country_phone_code_to_countries))
	{
		if (formatted_number.indexOf(country_phone_code) === '+'.length)
		{
			return formatted_number.slice('+'.length + country_phone_code.length).trim()
		}
	}

	return formatted_number
}
1374248
def _get_metadata_for_region(region_code):
    """"""
    country_calling_code = country_code_for_region(region_code)
    main_country = region_code_for_country_code(country_calling_code)
    # Set to a default instance of the metadata. This allows us to
    # function with an incorrect region code, even if formatting only
    # works for numbers specified with "+".
    return PhoneMetadata.metadata_for_region(main_country, _EMPTY_METADATA)
746382
def _parse_address(self, address_string):
        ''''''
        match = utils.match(self.rules, address_string, flags=re.VERBOSE | re.U)
        if match:
            match_as_dict = match.groupdict()
            match_as_dict.update({'country_id': self.country})
            # combine results
            cleaned_dict = self._combine_results(match_as_dict)
            # create object containing results
            return address.Address(**cleaned_dict)

        return False
1159563
def parse_phone(parts, allow_multiple=False):
  
  
  # Get text substitutions (ex: 'three' -> '3')
  text_subs = misc.phone_text_subs()
  Small = text_subs['Small']
  Magnitude = text_subs['Magnitude']
  Others = text_subs['Others']

  phone_pattern = r'1?(?:[2-9][0-8][0-9])\s?(?:[2-9][0-9]{2})\s?(?:[0-9]{2})\s?(?:[0-9]{2})'
  phone_pattern_spaces = r'1?\W?[2-9]\W?[0-8]\W?[0-9]\W?[2-9]\W?[0-9]\W?[0-9]\W?[0-9]\W?[0-9]\W?[0-9]\W?[0-9]'

  found_phones = []
  return_parts = []
  # Check each part for phone # and remove from parts if found
  for part in parts:
    body = part
    # remove '420' references to avoid false positives
    body = re.sub(r'420 ?friendly', '', body)
    body = body.replace(' 420 ', '')
    body = body.replace('420 sp', '')

    # Replace all disguising characters in the body
    for key in Small:
      body = re.sub(r'-?'+re.escape(key)+r'-?', str(Small[key]), body)
    for key in Magnitude:
      body = re.sub(r'-?'+re.escape(key)+r'-?', str(Magnitude[key]), body)
    for key in Others:
      body = re.sub(r'-?'+re.escape(key)+r'-?', str(Others[key]), body)
    body = re.sub(r'\W', ' ', body)
    body = re.sub(r' +', ' ', body)

    if len(re.sub(r'\D', '', body)) < 10:
      # Less than 10 numeric digits in part - no phone number here
      return_parts.append(part)
      continue;

    phones = re.findall(phone_pattern, body)

    if len(phones) == 0:
      # No phone number in standard format
      phones = re.findall(phone_pattern_spaces, body)
      if len(phones) > 0:
        # Phone number had spaces between digits
        for found in phones:
          found_phones.append(re.sub(r'\D', '', found))

    else:
      # Found phone in standard format
      for found in phones:
        found_phones.append(re.sub(r'\D', '', found))

    if found_phones:
      # Phone has been found, remove from part)
      for found in found_phones:
        filtered_part = parser_helpers.remove_phone(part, found)
      if re.sub(r'\W', '', filtered_part):
        # get rid of now-empty parts
        return_parts.append(filtered_part)
    else:
      # Phone not found yet, add part to output
      return_parts.append(part)

  if not allow_multiple:
    # Get most commonly occurring phone
    found_phone = ''
    if len(found_phones) > 0:
      found_phone = max(set(found_phones), key=found_phones.count)

    # Return the phone along with the original parts (minus any occurrences of the phone number)
    return (found_phone, return_parts)
  else:
    # return all phones
    return (list(set(found_phones)), return_parts)
493899
private void parseCountries(List<String> content) throws Exception {
        for (String line : content) {
            Matcher matcher = COUNTRY_REGEX_LINE.matcher(line);
            if (matcher.matches()) {
                String countryCode = matcher.group(1);
                String currencyCode = matcher.group(2);
                registerCountry(countryCode, currencyCode);
            }
        }
    }
586275
function ParseInternationalNumber(number) {
    var ret;

    // Parse and strip the country code.
    var countryCode = ParseCountryCode(number);
    if (!countryCode)
      return null;
    number = number.substr(countryCode.length);

    // Lookup the meta data for the region (or regions) and if the rest of
    // the number parses for that region, return the parsed number.
    var entry = dataBase[countryCode];
    if (Array.isArray(entry)) {
      for (var n = 0; n < entry.length; ++n) {
        if (typeof entry[n] == "string")
          entry[n] = ParseMetaData(countryCode, entry[n]);
        if (n > 0)
          entry[n].formats = entry[0].formats;
        ret = ParseNationalNumber(number, entry[n])
        if (ret)
          return ret;
      }
      return null;
    }
    if (typeof entry == "string")
      entry = dataBase[countryCode] = ParseMetaData(countryCode, entry);
    return ParseNationalNumber(number, entry);
  }
780065
function ParseMetaData(countryCode, md) {
    var array = eval(md.replace(BACKSLASH, "\\\\"));
    md = ParseArray(array,
                    META_DATA_ENCODING,
                    { countryCode: countryCode });
    regionCache[md.region] = md;
    return md;
  }
883120
def full_regex_for_data(data, type, country_optional = true)
      regex = []
      regex << '0{2}?'
      regex << "(#{data[Core::INTERNATIONAL_PREFIX]})?"
      regex << "(#{data[Core::COUNTRY_CODE]})#{country_optional ? '?' : ''}"
      regex << "(#{data[Core::NATIONAL_PREFIX_FOR_PARSING] || data[Core::NATIONAL_PREFIX]})?"
      regex << "(#{type_regex(data[Core::TYPES][Core::GENERAL], type)})" if data[Core::TYPES]

      cr("^#{regex.join}$")
    end
870829
def get_country(self):
        """"""

        doc = self._request(self.ws_prefix + ".getInfo", True)

        country = _extract(doc, "country")

        if country is None or country == "None":
            return None
        else:
            return Country(country, self.network)
703686
def country_code=(country_code)
      if country_code
        if country_code.is_a?(String)
          @country_code = country_code.strip.upcase.to_sym
        elsif country_code.is_a?(Symbol)
          @country_code = country_code.upcase
        end
      end
    end
983287
def phone_match_data?(phone, data, possible = false)
      country_code = "#{data[Core::COUNTRY_CODE]}"
      inter_prefix = "(#{data[Core::INTERNATIONAL_PREFIX]})?"
      return unless phone.match cr("^0{2}?#{inter_prefix}#{country_code}")

      type = possible ? Core::POSSIBLE_PATTERN : Core::VALID_PATTERN
      phone.match full_regex_for_data(data, type, false)
    end
537156
def _prefix_number_with_country_calling_code(country_code, num_format, formatted_number):
    """"""
    if num_format == PhoneNumberFormat.E164:
        return _PLUS_SIGN + unicod(country_code) + formatted_number
    elif num_format == PhoneNumberFormat.INTERNATIONAL:
        return _PLUS_SIGN + unicod(country_code) + U_SPACE + formatted_number
    elif num_format == PhoneNumberFormat.RFC3966:
        return _RFC3966_PREFIX + _PLUS_SIGN + unicod(country_code) + U_DASH + formatted_number
    else:
        return formatted_number
1156272
def country_or_default_country(country)
      country ||= (original_starts_with_plus? ? nil : Phonelib.default_country)
      country && country.to_s.upcase
    end