Filter out country codes properly.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 28e2639dc5
commit d38f6fbfd1

@ -117,33 +117,36 @@
NSArray *countryCodes = NSLocale.ISOCountryCodes;
if (searchTerm.length > 0) {
countryCodes = [countryCodes filter:^int(NSString *countryCode) {
NSString *countryName = [self countryNameFromCountryCode:countryCode];
NSString *callingCode = [self callingCodeFromCountryCode:countryCode];
if (callingCode == nil || [callingCode isEqualToString:@"+0"]) {
// Filter out countries without a valid calling code.
return NO;
}
countryCodes = [countryCodes filter:^int(NSString *countryCode) {
NSString *countryName = [self countryNameFromCountryCode:countryCode];
NSString *callingCode = [self callingCodeFromCountryCode:countryCode];
if ([self name:countryName matchesQuery:searchTerm]) {
return YES;
}
if (countryName.length < 1 || callingCode.length < 1 || [callingCode isEqualToString:@"+0"]) {
// Filter out countries without a valid calling code.
return NO;
}
if ([self name:countryCode matchesQuery:searchTerm]) {
return YES;
}
if (searchTerm.length < 1) {
return YES;
}
// We rely on the already internationalized string; as that is what
// the user would see entered (i.e. with COUNTRY_CODE_PREFIX).
if ([self name:countryName matchesQuery:searchTerm]) {
return YES;
}
if ([callingCode containsString:searchTerm]) {
return YES;
}
return NO;
}];
}
if ([self name:countryCode matchesQuery:searchTerm]) {
return YES;
}
// We rely on the already internationalized string; as that is what
// the user would see entered (i.e. with COUNTRY_CODE_PREFIX).
if ([callingCode containsString:searchTerm]) {
return YES;
}
return NO;
}];
return [self sortedCountryCodesByName:countryCodes];
}

Loading…
Cancel
Save