parse the countries
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);
            }
        }
    }
1069196
def match_xxx_for_country( name, xxx )  # xxx e.g. cities|states|beers|breweries
    #      auto-add required country code (from folder structure)
    #  note: always let match_xxx_for_country_n_state go first

    # note: allow  /cities and /1--hokkaido--cities
    xxx_pattern = "(?:#{xxx}|[0-9]+--[^\\/]+?--#{xxx})"    # note: double escape \\ required for backslash

    ##
    ## todo: add $-anchor at the end of pattern - why? why not?? (will include .txt or .yaml??)

    if name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{xxx_pattern}/   ||    # (1)
       name =~ /(?:^|\/)#{WORLD_COUNTRY_MODERN_PATTERN}\/#{xxx_pattern}/    ||    # (2)
       name =~ /(?:^|\/)#{WORLD_COUNTRY_CODE_PATTERN}\/#{xxx_pattern}/      ||    # (3)
       name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/[0-9]+--[^\/]+\/#{xxx_pattern}/ ||   # (4)
       name =~ /(?:^|\/)#{WORLD_COUNTRY_CODE_PATTERN}-[^\/]+--#{xxx}/    # (5)

      country_key = $1.dup
      yield( country_key )
      true # bingo - match found

      ######
      # (1)  new style: e.g. /at-austria/beers or ^at-austria!/cities
      #
      # (2)  new-new style e.g. /1--at-austria--central/cities
      #
      # (3)  classic style: e.g. /at/beers (europe/at/cities)
      #
      # (4) new style w/ state w/o abbrev/code e.g. /ja-japon/1--hokkaido/cities
      #
      # (5)  compact style (country part of filename):
      #   e.g. /at-austria--cities or /europe/at-austria--cities
    else
      false # no match found
    end
  end
520169
def valid_for_country?(country)
      country = country.to_s.upcase
      tdata = analyze(sanitized, passed_country(country))
      tdata.find do |iso2, data|
        country == iso2 && data[:valid].any?
      end.is_a? Array
    end
551401
function (params) {
        var countries = _data;
        var subset = [], i = 0;
        if (params.whitelist) {
            var whitelist = params.whitelist.split(",");
            for (i = 0; i < _data.length; i++) {
                if (whitelist.indexOf(_data[i][1]) !== -1) {
                    subset.push(_data[i]);
                }
            }
            countries = subset;
        } else if (params.blacklist) {
            var blacklist = params.blacklist.split(",");
            for (i = 0; i < _data.length; i++) {
                if (blacklist.indexOf(_data[i][1]) === -1) {
                    subset.push(_data[i]);
                }
            }
            countries = subset;
        }

        if (params.preferred) {
            countries = _applyPreferredCountries(countries, params.preferred, params.preferredDelim);
        }

        _countries = countries;

        // now init the regions
        _initRegions();
    }
1274206
def clean_text(self, country, guess=False, **kwargs):
        
        code = country.lower().strip()
        if code in self.names:
            return code
        country = countrynames.to_code(country, fuzzy=guess)
        if country is not None:
            return country.lower()
212143
static function fetchCountryList()
    {
        if ( isset( $GLOBALS['CountryList'] ) )
            return $GLOBALS['CountryList'];

        $ini = eZINI::instance( 'country.ini' );
        $countries = $ini->getNamedArray();
        eZCountryType::fetchTranslatedNames( $countries );
        $GLOBALS['CountryList'] = $countries;
        return $countries;
    }
582674
function getCountryByName(name, useAlias) {
  if (!_.isString(name)) return undefined;

  return _.find(countries, (country) => {
    if (useAlias) {
      return country.name.toUpperCase() === name.toUpperCase()
        ||  _.find(country.alias, (alias) => (alias.toUpperCase() === name.toUpperCase()));
    }
    return country.name.toUpperCase() === name.toUpperCase();
  });
}
400113
def detect_and_parse(phone, country)
      result = {}
      Phonelib.phone_data.each do |key, data|
        parsed = parse_single_country(phone, data)
        if (!Phonelib.strict_double_prefix_check || key == country) && double_prefix_allowed?(data, phone, parsed && parsed[key])
          parsed = parse_single_country(changed_dp_phone(key, phone), data)
        end
        result.merge!(parsed) unless parsed.nil?
      end
      result
    end
356170
def _read_country_names(self, countries_file=None):
        """"""
        if not countries_file:
            countries_file = os.path.join(os.path.dirname(__file__), self.COUNTRY_FILE_DEFAULT)
        with open(countries_file) as f:
            countries_json = f.read()

        return json.loads(countries_json)
284229
def groups(self) -> typing.Iterator['Group']:
        
        for country in self.countries:
            for group in country.groups:

                yield group
952515
protected static Country parse(String line) throws IOException {
        try {
            int pos = line.indexOf(' ');
            if (pos < 0) throw new IOException("Invalid format, could not parse 2 char code");
            String code2 = line.substring(0, pos);
            int pos2 = line.indexOf(' ', pos+1);
            if (pos2 < 0) throw new IOException("Invalid format, could not parse 3 char code");
            String code3 = line.substring(pos+1, pos2);
            int pos3 = line.indexOf(' ', pos2+1);
            if (pos3 < 0) throw new IOException("Invalid format, could not parse 3 char digit code");
            String num3 = line.substring(pos2+1, pos3);
            // rest of line is the long name
            String longName = line.substring(pos3+1).trim();
            // was there a name?
            if (longName == null || longName.equals("")) {
                throw new IOException("Country name was null or empty");
            }

            // parse long name into its short name (strip anything after the last comma)
            String name = longName;
            int pos4 = longName.lastIndexOf(',');
            if (pos4 > 0) {
                // strip out the final part such as ", Republic of" from something like "Nigeria, Republic Of"
                name = longName.substring(0, pos4);
            }

            // create the new country
            return new Country(code2, name, longName);
        } catch (Exception e) {
            throw new IOException("Failed while parsing country for line: " + line, e);
        }
    }
739163
public static function validate($countries)
    {
        $valid = array();

        //If data is not passed as an array, do so.
        if (!is_array($countries)) {
            $countries = \explode(' ', $countries);
            $countries = \array_filter($countries);
        }

        //Foreach value, check if it is a valid self::$iso3166 value
        foreach ($countries as $country) {
            $country = \preg_replace('/[^a-z]/i', '', $country);
            $country = \strtoupper($country);
            if (\in_array($country, self::$iso3166, true)) {
                $valid[] = $country;
            }
        }

        $data = \implode(' ', $valid);

        return (\strlen($data) > 0) ? $data : false;
    }
1138248
public function countries($by = null, $value = null)
    {
        $countries = json_decode(file_get_contents(__DIR__ . '/../../data/countries.json'), true);

        if (is_null($by) && is_null($value)) {
            $countries = collect($countries)->values()->all();
        } else {
            if ($by == 'locale') {
                $value = str_replace(' ', '_', $value);
                $value = str_replace('-', '_', $value);
            }

            if ($by == 'locale' && strlen($value) == 2) {
                if ($value == 'en') {
                    $value = 'en_US';
                } elseif ($value == 'br') {
                    $value = 'pt_BR';
                } else {
                    $value = $value.'_'.strtoupper($value);
                }
            }

            $countries = (object) collect($countries)->filter(function ($item) use ($by, $value) {
                return strtolower($item[$by]) == strtolower($value);
            })->values()->first();
        }

        return $countries;
    }
1231057
def user_parse(data):
        """"""
        yield 'id', data.get('id') or data.get('user_id')
        first_name, _, last_name = data['name'].partition(' ')
        yield 'first_name', first_name
        yield 'last_name', last_name
        yield 'picture', data.get('profile_image_url')
        yield 'locale', data.get('lang')
        yield 'link', data.get('url')
        yield 'username', data.get('screen_name')
        city, _, country = map(lambda s: s.strip(),
                               data.get('location', '').partition(','))
        yield 'city', city
        yield 'country', country
1174326
def getCountry(value):
        
        if not helpers.has_len(value):
            return False

        return COUNTRIES.get(str(value).lower(), False)
908050
function countryNameToCode (name) {
  const country = countries.find((country) => country.name === name)

  if (!country) {
    return name
  }

  return country.code
}
195595
public function countries(array $countryCodes = null): array
    {
        if (!Configure::read('countries')) {
            Configure::load('CkTools.countries');
        }
        if ($countryCodes) {
            $countries = Configure::read('countries');
            $subset = [];
            foreach ($countryCodes as $countryCode) {
                $subset[$countryCode] = $countries[$countryCode] ?? $countryCode;
            }

            return $subset;
        }

        return Configure::read('countries');
    }