diff --git a/libPhoneNumber.xcodeproj/project.pbxproj b/libPhoneNumber.xcodeproj/project.pbxproj index cc067ea8..e78f29a4 100755 --- a/libPhoneNumber.xcodeproj/project.pbxproj +++ b/libPhoneNumber.xcodeproj/project.pbxproj @@ -53,7 +53,6 @@ 940725A924BE77420011AE05 /* NBShortNumberUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 940725A724BE77420011AE05 /* NBShortNumberUtil.h */; settings = {ATTRIBUTES = (Public, ); }; }; 940725AA24BE77420011AE05 /* NBShortNumberUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 940725A824BE77420011AE05 /* NBShortNumberUtil.m */; }; 940725AC24BF63050011AE05 /* NBShortNumberInfoTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 940725AB24BF63050011AE05 /* NBShortNumberInfoTest.m */; }; - 940725AD24BF63500011AE05 /* NBMetadataHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FD12C2681A87401B00B53856 /* NBMetadataHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; 940725AF24BF79BE0011AE05 /* NBGeneratedShortNumberMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 940725AE24BF79BE0011AE05 /* NBGeneratedShortNumberMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; }; 940725B224BF7B040011AE05 /* NBShortNumberTestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 940725B124BF7B040011AE05 /* NBShortNumberTestHelper.m */; }; 940725B524BF90290011AE05 /* NBShortNumberMetadataHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 940725B324BF90290011AE05 /* NBShortNumberMetadataHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -503,7 +502,6 @@ 940725A924BE77420011AE05 /* NBShortNumberUtil.h in Headers */, 9407259B24BE768A0011AE05 /* libPhoneNumberShortNumber.h in Headers */, 940725AF24BF79BE0011AE05 /* NBGeneratedShortNumberMetadata.h in Headers */, - 940725AD24BF63500011AE05 /* NBMetadataHelper.h in Headers */, 940725B524BF90290011AE05 /* NBShortNumberMetadataHelper.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/libPhoneNumber/NBMetadataHelper.m b/libPhoneNumber/NBMetadataHelper.m index d287c9bb..45698615 100644 --- a/libPhoneNumber/NBMetadataHelper.m +++ b/libPhoneNumber/NBMetadataHelper.m @@ -149,7 +149,7 @@ - (NSString *)countryCodeFromRegionCode:(NSString *)regionCode { * @param {?string} regionCode * @return {i18n.phonenumbers.PhoneMetadata} */ -- (NBPhoneMetaData *)getMetadataForRegion:(NSString *)regionCode { +- (NBPhoneMetaData * _Nullable)getMetadataForRegion:(NSString * _Nonnull)regionCode { regionCode = StringByTrimming(regionCode); if (regionCode.length == 0) { return nil; @@ -178,12 +178,12 @@ - (NBPhoneMetaData *)getMetadataForRegion:(NSString *)regionCode { * @param countryCallingCode countryCallingCode * @return {i18n.phonenumbers.PhoneMetadata} */ -- (NBPhoneMetaData *)getMetadataForNonGeographicalRegion:(NSNumber *)countryCallingCode { +- (NBPhoneMetaData * _Nullable)getMetadataForNonGeographicalRegion:(NSNumber * _Nonnull)countryCallingCode { NSString *countryCallingCodeStr = countryCallingCode.stringValue; return [self getMetadataForRegion:countryCallingCodeStr]; } -+ (BOOL)hasValue:(NSString *)string { ++ (BOOL)hasValue:(NSString * _Nonnull)string { string = StringByTrimming(string); return string.length != 0; } diff --git a/libPhoneNumber/NBPhoneNumberUtil.h b/libPhoneNumber/NBPhoneNumberUtil.h index 2bd7cf43..ff85a39d 100644 --- a/libPhoneNumber/NBPhoneNumberUtil.h +++ b/libPhoneNumber/NBPhoneNumberUtil.h @@ -13,126 +13,128 @@ @interface NBPhoneNumberUtil : NSObject -+ (NBPhoneNumberUtil *)sharedInstance; -- (instancetype)initWithMetadataHelper:(NBMetadataHelper *)helper; ++ (NBPhoneNumberUtil * _Nonnull)sharedInstance; +- (instancetype _Nonnull)initWithMetadataHelper:(NBMetadataHelper * _Nonnull)helper; -- (instancetype)init NS_UNAVAILABLE; +- (instancetype _Nonnull)init NS_UNAVAILABLE; -@property(nonatomic, strong, readonly) NSDictionary *DIGIT_MAPPINGS; +@property(nonatomic, strong, readonly, nonnull) NSDictionary * DIGIT_MAPPINGS; // regular expressions -- (NSArray *)matchesByRegex:(NSString *)sourceString regex:(NSString *)pattern; -- (NSArray *)matchedStringByRegex:(NSString *)sourceString regex:(NSString *)pattern; -- (NSString *)replaceStringByRegex:(NSString *)sourceString - regex:(NSString *)pattern - withTemplate:(NSString *)templateString; -- (int)stringPositionByRegex:(NSString *)sourceString regex:(NSString *)pattern; +- (NSArray * _Nullable)matchesByRegex:(NSString * _Nonnull)sourceString regex:(NSString * _Nonnull)pattern; +- (NSArray * _Nullable)matchedStringByRegex:(NSString * _Nonnull)sourceString regex:(NSString * _Nonnull)pattern; +- (NSString * _Nonnull)replaceStringByRegex:(NSString * _Nonnull)sourceString + regex:(NSString * _Nonnull)pattern + withTemplate:(NSString * _Nonnull)templateString; +- (int)stringPositionByRegex:(NSString * _Nullable)sourceString regex:(NSString * _Nullable)pattern; // libPhoneNumber Util functions -- (NSString *)convertAlphaCharactersInNumber:(NSString *)number; - -- (NSString *)normalize:(NSString *)phoneNumber; -- (NSString *)normalizeDigitsOnly:(NSString *)number; -- (NSString *)normalizeDiallableCharsOnly:(NSString *)number; - -- (BOOL)isNumberGeographical:(NBPhoneNumber *)phoneNumber; - -- (NSString *)extractPossibleNumber:(NSString *)phoneNumber; -- (NSNumber *)extractCountryCode:(NSString *)fullNumber nationalNumber:(NSString **)nationalNumber; -- (NSString *)countryCodeByCarrier; - -- (NSString *)getNddPrefixForRegion:(NSString *)regionCode stripNonDigits:(BOOL)stripNonDigits; -- (NSString *)getNationalSignificantNumber:(NBPhoneNumber *)phoneNumber; - -- (NSArray *)getSupportedRegions; - -- (NBEPhoneNumberType)getNumberType:(NBPhoneNumber *)phoneNumber; - -- (NSNumber *)getCountryCodeForRegion:(NSString *)regionCode; - -- (NSString *)getRegionCodeForCountryCode:(NSNumber *)countryCallingCode; -- (NSArray *)getRegionCodesForCountryCode:(NSNumber *)countryCallingCode; -- (NSString *)getRegionCodeForNumber:(NBPhoneNumber *)phoneNumber; - -- (NBPhoneNumber *)getExampleNumber:(NSString *)regionCode error:(NSError **)error; -- (NBPhoneNumber *)getExampleNumberForType:(NSString *)regionCode - type:(NBEPhoneNumberType)type - error:(NSError **)error; -- (NBPhoneNumber *)getExampleNumberForNonGeoEntity:(NSNumber *)countryCallingCode - error:(NSError **)error; - -- (BOOL)canBeInternationallyDialled:(NBPhoneNumber *)number error:(NSError **)error; - -- (BOOL)truncateTooLongNumber:(NBPhoneNumber *)number; - -- (BOOL)isValidNumber:(NBPhoneNumber *)number; -- (BOOL)isViablePhoneNumber:(NSString *)phoneNumber; -- (BOOL)isAlphaNumber:(NSString *)number; -- (BOOL)isValidNumberForRegion:(NBPhoneNumber *)number regionCode:(NSString *)regionCode; -- (BOOL)isNANPACountry:(NSString *)regionCode; -- (BOOL)isLeadingZeroPossible:(NSNumber *)countryCallingCode; - -- (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber *)number error:(NSError **)error; - -- (BOOL)isPossibleNumber:(NBPhoneNumber *)number; -- (BOOL)isPossibleNumber:(NBPhoneNumber *)number error:(NSError **)error; -- (BOOL)isPossibleNumberString:(NSString *)number - regionDialingFrom:(NSString *)regionDialingFrom - error:(NSError **)error; - -- (NBEMatchType)isNumberMatch:(id)firstNumberIn second:(id)secondNumberIn error:(NSError **)error; - -- (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber *)phoneNumber error:(NSError **)error; -- (int)getLengthOfNationalDestinationCode:(NBPhoneNumber *)phoneNumber error:(NSError **)error; - -- (BOOL)maybeStripNationalPrefixAndCarrierCode:(NSString **)numberStr - metadata:(NBPhoneMetaData *)metadata - carrierCode:(NSString **)carrierCode; -- (NBECountryCodeSource)maybeStripInternationalPrefixAndNormalize:(NSString **)numberStr - possibleIddPrefix:(NSString *)possibleIddPrefix; - -- (NSNumber *)maybeExtractCountryCode:(NSString *)number - metadata:(NBPhoneMetaData *)defaultRegionMetadata - nationalNumber:(NSString **)nationalNumber - keepRawInput:(BOOL)keepRawInput - phoneNumber:(NBPhoneNumber **)phoneNumber - error:(NSError **)error; - -- (NBPhoneNumber *)parse:(NSString *)numberToParse - defaultRegion:(NSString *)defaultRegion - error:(NSError **)error; -- (NBPhoneNumber *)parseAndKeepRawInput:(NSString *)numberToParse - defaultRegion:(NSString *)defaultRegion - error:(NSError **)error; -- (NBPhoneNumber *)parseWithPhoneCarrierRegion:(NSString *)numberToParse error:(NSError **)error; - -- (NSString *)format:(NBPhoneNumber *)phoneNumber - numberFormat:(NBEPhoneNumberFormat)numberFormat - error:(NSError **)error; -- (NSString *)formatByPattern:(NBPhoneNumber *)number - numberFormat:(NBEPhoneNumberFormat)numberFormat - userDefinedFormats:(NSArray *)userDefinedFormats - error:(NSError **)error; -- (NSString *)formatNumberForMobileDialing:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom - withFormatting:(BOOL)withFormatting - error:(NSError **)error; -- (NSString *)formatOutOfCountryCallingNumber:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom - error:(NSError **)error; -- (NSString *)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom - error:(NSError **)error; -- (NSString *)formatNationalNumberWithCarrierCode:(NBPhoneNumber *)number - carrierCode:(NSString *)carrierCode - error:(NSError **)error; -- (NSString *)formatInOriginalFormat:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom - error:(NSError **)error; -- (NSString *)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber *)number - fallbackCarrierCode:(NSString *)fallbackCarrierCode - error:(NSError **)error; -- (BOOL)formattingRuleHasFirstGroupOnly:(NSString *)nationalPrefixFormattingRule; +- (NSString * _Nonnull)convertAlphaCharactersInNumber:(NSString * _Nonnull)number; + +- (NSString * _Nonnull)normalize:(NSString * _Nonnull)number; +- (NSString * _Nonnull)normalizeDigitsOnly:(NSString * _Nonnull)number; +- (NSString * _Nonnull)normalizeDiallableCharsOnly:(NSString * _Nonnull)number; + +- (BOOL)isNumberGeographical:(NBPhoneNumber * _Nonnull)phoneNumber; + +- (NSString * _Nonnull)extractPossibleNumber:(NSString * _Nonnull)number; +- (NSNumber * _Nonnull)extractCountryCode:(NSString * _Nonnull)fullNumber nationalNumber:(NSString * _Nullable * _Nullable)nationalNumber; +- (NSString * _Nonnull)countryCodeByCarrier; + +- (NSString * _Nullable)getNddPrefixForRegion:(NSString * _Nullable)regionCode stripNonDigits:(BOOL)stripNonDigits; +- (NSString * _Nonnull)getNationalSignificantNumber:(NBPhoneNumber * _Nonnull)phoneNumber; + +- (NSArray * _Nullable)getSupportedRegions; + +- (NBEPhoneNumberType)getNumberType:(NBPhoneNumber * _Nonnull)phoneNumber; + +- (NSNumber * _Nonnull)getCountryCodeForRegion:(NSString * _Nullable)regionCode; + +- (NSString * _Nonnull)getRegionCodeForCountryCode:(NSNumber * _Nonnull)countryCallingCode; +- (NSArray * _Nullable)getRegionCodesForCountryCode:(NSNumber * _Nonnull)countryCallingCode; +- (NSString * _Nullable)getRegionCodeForNumber:(NBPhoneNumber * _Nullable)phoneNumber; + +- (NBPhoneNumber * _Nullable)getExampleNumber:(NSString * _Nonnull)regionCode error:(NSError * _Nullable __autoreleasing * _Nullable)error; +- (NBPhoneNumber * _Nullable)getExampleNumberForType:(NSString * _Nonnull)regionCode + type:(NBEPhoneNumberType)type + error:(NSError * _Nullable __autoreleasing * _Nullable)error; +- (NBPhoneNumber * _Nullable)getExampleNumberForNonGeoEntity:(NSNumber * _Nonnull)countryCallingCode + error:(NSError * _Nullable * _Nullable)error; + +- (BOOL)canBeInternationallyDialled:(NBPhoneNumber * _Nonnull)number error:(NSError * _Nullable * _Nullable)error; + +- (BOOL)truncateTooLongNumber:(NBPhoneNumber * _Nonnull)number; + +- (BOOL)isValidNumber:(NBPhoneNumber * _Nonnull)number; +- (BOOL)isViablePhoneNumber:(NSString * _Nonnull)phoneNumber; +- (BOOL)isAlphaNumber:(NSString * _Nonnull)number; +- (BOOL)isValidNumberForRegion:(NBPhoneNumber * _Nonnull)number regionCode:(NSString * _Nonnull)regionCode; +- (BOOL)isNANPACountry:(NSString * _Nullable)regionCode; +- (BOOL)isLeadingZeroPossible:(NSNumber * _Nonnull)countryCallingCode; + +- (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber * _Nonnull)number + error:(NSError * _Nullable * _Nullable)error; + +- (BOOL)isPossibleNumber:(NBPhoneNumber * _Nonnull)number; +- (BOOL)isPossibleNumber:(NBPhoneNumber * _Nonnull)number error:(NSError * _Nullable * _Nullable)error; +- (BOOL)isPossibleNumberString:(NSString * _Nonnull)number + regionDialingFrom:(NSString * _Nullable)regionDialingFrom + error:(NSError * _Nullable * _Nullable)error; + +- (NBEMatchType)isNumberMatch:(id _Nonnull)firstNumberIn second:(id _Nonnull)secondNumberIn error:(NSError * _Nullable * _Nullable)error; + +- (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber * _Nonnull)phoneNumber error:(NSError * _Nullable * _Nullable)error; +- (int)getLengthOfNationalDestinationCode:(NBPhoneNumber * _Nonnull)phoneNumber error:(NSError * _Nullable * _Nullable)error; + +- (BOOL)maybeStripNationalPrefixAndCarrierCode:(NSString * _Nullable * _Nullable)number + metadata:(NBPhoneMetaData * _Nonnull)metadata + carrierCode:(NSString * _Nullable * _Nullable)carrierCode; +- (NBECountryCodeSource)maybeStripInternationalPrefixAndNormalize:(NSString * _Nullable * _Nullable)numberStr + possibleIddPrefix:(NSString * _Nonnull)possibleIddPrefix; + +- (NSNumber * _Nonnull)maybeExtractCountryCode:(NSString * _Nonnull)number + metadata:(NBPhoneMetaData * _Nullable)defaultRegionMetadata + nationalNumber:(NSString * _Nullable * _Nullable)nationalNumber + keepRawInput:(BOOL)keepRawInput + phoneNumber:(NBPhoneNumber * _Nullable * _Nullable)phoneNumber + error:(NSError * _Nullable * _Nullable)error; + +- (NBPhoneNumber * _Nullable)parse:(NSString * _Nullable)numberToParse + defaultRegion:(NSString * _Nullable)defaultRegion + error:(NSError * _Nullable * _Nullable)error; +- (NBPhoneNumber * _Nullable)parseAndKeepRawInput:(NSString * _Nonnull)numberToParse + defaultRegion:(NSString * _Nullable)defaultRegion + error:(NSError * _Nullable * _Nullable)error; +- (NBPhoneNumber * _Nullable)parseWithPhoneCarrierRegion:(NSString * _Nullable)numberToParse + error:(NSError * _Nullable * _Nullable)error; + +- (NSString * _Nullable)format:(NBPhoneNumber * _Nonnull)phoneNumber + numberFormat:(NBEPhoneNumberFormat)numberFormat + error:(NSError * _Nullable * _Nullable)error; +- (NSString * _Nullable)formatByPattern:(NBPhoneNumber * _Nonnull)number + numberFormat:(NBEPhoneNumberFormat)numberFormat + userDefinedFormats:(NSArray * _Nullable)userDefinedFormats + error:(NSError * _Nullable * _Nullable)error; +- (NSString * _Nullable)formatNumberForMobileDialing:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom + withFormatting:(BOOL)withFormatting + error:(NSError * _Nullable * _Nullable)error; +- (NSString * _Nullable)formatOutOfCountryCallingNumber:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom + error:(NSError * _Nullable * _Nullable)error; +- (NSString * _Nullable)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom + error:(NSError * _Nullable * _Nullable)error; +- (NSString * _Nullable)formatNationalNumberWithCarrierCode:(NBPhoneNumber * _Nonnull)number + carrierCode:(NSString * _Nullable)carrierCode + error:(NSError * _Nullable * _Nullable)error; +- (NSString * _Nullable)formatInOriginalFormat:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom + error:(NSError * _Nullable * _Nullable)error; +- (NSString * _Nullable)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber * _Nonnull)number + fallbackCarrierCode:(NSString * _Nonnull)fallbackCarrierCode + error:(NSError * _Nullable * _Nullable)error; +- (BOOL)formattingRuleHasFirstGroupOnly:(NSString * _Nullable)nationalPrefixFormattingRule; /** * Returns the mobile token for the provided country calling code if it has one, otherwise @@ -142,6 +144,7 @@ * @param countryCallingCode the country calling code for which we want the mobile token. * @return the mobile token, as a string, for the given country calling code. */ -- (NSString *)getCountryMobileTokenFromCountryCode:(NSInteger)countryCallingCode; +- (NSString * _Nonnull)getCountryMobileTokenFromCountryCode:(NSInteger)countryCallingCode; @end + diff --git a/libPhoneNumber/NBPhoneNumberUtil.m b/libPhoneNumber/NBPhoneNumberUtil.m index 1300c974..336758d7 100644 --- a/libPhoneNumber/NBPhoneNumberUtil.m +++ b/libPhoneNumber/NBPhoneNumberUtil.m @@ -110,7 +110,7 @@ @implementation NBPhoneNumberUtil #pragma mark - Deprecated methods -+ (NBPhoneNumberUtil *)sharedInstance { ++ (NBPhoneNumberUtil * _Nonnull)sharedInstance { static NBPhoneNumberUtil *sharedOnceInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -119,7 +119,7 @@ + (NBPhoneNumberUtil *)sharedInstance { return sharedOnceInstance; } -- (instancetype)initWithMetadataHelper:(NBMetadataHelper *)helper { +- (instancetype _Nonnull)initWithMetadataHelper:(NBMetadataHelper * _Nonnull)helper { self = [super init]; if (self != nil) { _lockPatternCache = [[NSLock alloc] init]; @@ -134,15 +134,15 @@ - (instancetype)initWithMetadataHelper:(NBMetadataHelper *)helper { #pragma mark - NSError -- (NSError *)errorWithObject:(id)obj withDomain:(NSString *)domain { +- (NSError * _Nonnull)errorWithObject:(id _Nonnull)obj withDomain:(NSString * _Nullable)domain { NSDictionary *userInfo = [NSDictionary dictionaryWithObject:obj forKey:NSLocalizedDescriptionKey]; NSError *error = [NSError errorWithDomain:domain code:0 userInfo:userInfo]; return error; } -- (NSRegularExpression *)entireRegularExpressionWithPattern:(NSString *)regexPattern +- (NSRegularExpression * _Nonnull)entireRegularExpressionWithPattern:(NSString * _Nonnull)regexPattern options:(NSRegularExpressionOptions)options - error:(NSError **)error { + error:(NSError * _Nullable * _Nullable)error { [_entireStringCacheLock lock]; @try { @@ -167,9 +167,9 @@ - (NSRegularExpression *)entireRegularExpressionWithPattern:(NSString *)regexPat } } -- (NSRegularExpression *)regularExpressionWithPattern:(NSString *)pattern - options:(NSRegularExpressionOptions)options - error:(NSError **)error { +- (NSRegularExpression * _Nonnull)regularExpressionWithPattern:(NSString * _Nonnull)pattern + options:(NSRegularExpressionOptions)options + error:(NSError * _Nullable * _Nullable)error { [_lockPatternCache lock]; @try { @@ -190,7 +190,7 @@ - (NSRegularExpression *)regularExpressionWithPattern:(NSString *)pattern } } -- (NSMutableArray *)componentsSeparatedByRegex:(NSString *)sourceString regex:(NSString *)pattern { +- (NSMutableArray * _Nonnull)componentsSeparatedByRegex:(NSString * _Nonnull)sourceString regex:(NSString * _Nonnull)pattern { NSString *replacedString = [self replaceStringByRegex:sourceString regex:pattern withTemplate:@""]; @@ -199,7 +199,7 @@ - (NSMutableArray *)componentsSeparatedByRegex:(NSString *)sourceString regex:(N return resArray; } -- (int)stringPositionByRegex:(NSString *)sourceString regex:(NSString *)pattern { +- (int)stringPositionByRegex:(NSString * _Nullable)sourceString regex:(NSString * _Nullable)pattern { if (sourceString == nil || sourceString.length <= 0 || pattern == nil || pattern.length <= 0) { return -1; } @@ -222,7 +222,7 @@ - (int)stringPositionByRegex:(NSString *)sourceString regex:(NSString *)pattern return foundPosition; } -- (int)indexOfStringByString:(NSString *)sourceString target:(NSString *)targetString { +- (int)indexOfStringByString:(NSString * _Nonnull)sourceString target:(NSString * _Nonnull)targetString { NSRange finded = [sourceString rangeOfString:targetString]; if (finded.location != NSNotFound) { return (int)finded.location; @@ -231,9 +231,9 @@ - (int)indexOfStringByString:(NSString *)sourceString target:(NSString *)targetS return -1; } -- (NSString *)replaceFirstStringByRegex:(NSString *)sourceString - regex:(NSString *)pattern - withTemplate:(NSString *)templateString { +- (NSString * _Nonnull)replaceFirstStringByRegex:(NSString * _Nonnull)sourceString + regex:(NSString * _Nonnull)pattern + withTemplate:(NSString * _Nullable)templateString { NSString *replacementResult = [sourceString copy]; NSError *error = nil; @@ -255,9 +255,9 @@ - (NSString *)replaceFirstStringByRegex:(NSString *)sourceString return replacementResult; } -- (NSString *)replaceStringByRegex:(NSString *)sourceString - regex:(NSString *)pattern - withTemplate:(NSString *)templateString { +- (NSString * _Nonnull)replaceStringByRegex:(NSString * _Nonnull)sourceString + regex:(NSString * _Nonnull)pattern + withTemplate:(NSString * _Nonnull)templateString { NSError *error = nil; NSRegularExpression *currentPattern = [self regularExpressionWithPattern:pattern options:0 @@ -295,7 +295,7 @@ - (NSString *)replaceStringByRegex:(NSString *)sourceString return [sourceString copy]; } -- (NSTextCheckingResult *)matchFirstByRegex:(NSString *)sourceString regex:(NSString *)pattern { +- (NSTextCheckingResult * _Nullable)matchFirstByRegex:(NSString * _Nonnull)sourceString regex:(NSString * _Nonnull)pattern { NSError *error = nil; NSRegularExpression *currentPattern = [self regularExpressionWithPattern:pattern options:0 @@ -307,7 +307,7 @@ - (NSTextCheckingResult *)matchFirstByRegex:(NSString *)sourceString regex:(NSSt return nil; } -- (NSArray *)matchesByRegex:(NSString *)sourceString regex:(NSString *)pattern { +- (NSArray * _Nullable)matchesByRegex:(NSString * _Nonnull)sourceString regex:(NSString * _Nonnull)pattern { NSError *error = nil; NSRegularExpression *currentPattern = [self regularExpressionWithPattern:pattern options:0 @@ -318,7 +318,7 @@ - (NSArray *)matchesByRegex:(NSString *)sourceString regex:(NSString *)pattern { return matches; } -- (NSArray *)matchedStringByRegex:(NSString *)sourceString regex:(NSString *)pattern { +- (NSArray * _Nullable)matchedStringByRegex:(NSString * _Nonnull)sourceString regex:(NSString * _Nonnull)pattern { NSArray *matches = [self matchesByRegex:sourceString regex:pattern]; NSMutableArray *matchString = [[NSMutableArray alloc] init]; @@ -330,7 +330,7 @@ - (NSArray *)matchedStringByRegex:(NSString *)sourceString regex:(NSString *)pat return matchString; } -- (BOOL)isStartingStringByRegex:(NSString *)sourceString regex:(NSString *)pattern { +- (BOOL)isStartingStringByRegex:(NSString * _Nonnull)sourceString regex:(NSString * _Nonnull)pattern { NSError *error = nil; NSRegularExpression *currentPattern = [self regularExpressionWithPattern:pattern options:0 @@ -348,9 +348,9 @@ - (BOOL)isStartingStringByRegex:(NSString *)sourceString regex:(NSString *)patte return NO; } -- (NSString *)stringByReplacingOccurrencesString:(NSString *)sourceString - withMap:(NSDictionary *)dicMap - removeNonMatches:(BOOL)bRemove { +- (NSString * _Nonnull)stringByReplacingOccurrencesString:(NSString * _Nonnull)sourceString + withMap:(NSDictionary * _Nullable)dicMap + removeNonMatches:(BOOL)bRemove { NSMutableString *targetString = [[NSMutableString alloc] init]; NSUInteger length = sourceString.length; for (NSUInteger i = 0; i < length; i++) { @@ -369,7 +369,7 @@ - (NSString *)stringByReplacingOccurrencesString:(NSString *)sourceString return targetString; } -- (BOOL)isAllDigits:(NSString *)sourceString { +- (BOOL)isAllDigits:(NSString * _Nonnull)sourceString { NSCharacterSet *nonNumbers = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; NSRange r = [sourceString rangeOfCharacterFromSet:nonNumbers]; return r.location == NSNotFound; @@ -384,7 +384,7 @@ - (BOOL)isAllDigits:(NSString *)sourceString { * @return {string} the national significant number of the PhoneNumber object * passed in. */ -- (NSString *)getNationalSignificantNumber:(NBPhoneNumber *)phoneNumber { +- (NSString * _Nonnull)getNationalSignificantNumber:(NBPhoneNumber * _Nonnull)phoneNumber { // If leading zero(s) have been set, we prefix this now. Note this is not a // national prefix. NSString *nationalNumber = [phoneNumber.nationalNumber stringValue]; @@ -466,7 +466,7 @@ - (void)initRegularExpressionSet { }); } -- (NSDictionary *)DIGIT_MAPPINGS { +- (NSDictionary * _Nonnull)DIGIT_MAPPINGS { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ DIGIT_MAPPINGS = [NSDictionary @@ -571,7 +571,7 @@ - (void)initNormalizationMappings { * 'Tel:') or an empty string if no character used to start phone numbers * (such as + or any digit) is found in the number. */ -- (NSString *)extractPossibleNumber:(NSString *)number { +- (NSString * _Nonnull)extractPossibleNumber:(NSString * _Nonnull)number { number = NormalizeNonBreakingSpace(number); NSString *possibleNumber = @""; @@ -609,7 +609,7 @@ - (NSString *)extractPossibleNumber:(NSString *)number { * @return {boolean} NO if the number could be a phone number of some sort, * otherwise NO. */ -- (BOOL)isViablePhoneNumber:(NSString *)phoneNumber { +- (BOOL)isViablePhoneNumber:(NSString * _Nonnull)phoneNumber { phoneNumber = NormalizeNonBreakingSpace(phoneNumber); if (phoneNumber.length < MIN_LENGTH_FOR_NSN_) { @@ -636,7 +636,7 @@ - (BOOL)isViablePhoneNumber:(NSString *)phoneNumber { * - param {string} number a string of characters representing a phone number. * @return {string} the normalized string version of the phone number. */ -- (NSString *)normalize:(NSString *)number { +- (NSString * _Nonnull)normalize:(NSString * _Nonnull)number { if ([self matchesEntirely:VALID_ALPHA_PHONE_PATTERN_STRING string:number]) { return [self normalizeHelper:number normalizationReplacements:ALL_NORMALIZATION_MAPPINGS @@ -658,7 +658,7 @@ - (NSString *)normalize:(NSString *)number { * @private */ -- (void)normalizeSB:(NSString **)number { +- (void)normalizeSB:(NSString * _Nullable * _Nullable)number { if (number == NULL) { return; } @@ -674,7 +674,7 @@ - (void)normalizeSB:(NSString **)number { * - param {string} number a string of characters representing a phone number. * @return {string} the normalized string version of the phone number. */ -- (NSString *)normalizeDigitsOnly:(NSString *)number { +- (NSString * _Nonnull)normalizeDigitsOnly:(NSString * _Nonnull)number { number = NormalizeNonBreakingSpace(number); return [self stringByReplacingOccurrencesString:number @@ -690,7 +690,7 @@ - (NSString *)normalizeDigitsOnly:(NSString *)number { * - param {string} number a string of characters representing a phone number. * @return {string} the normalized string version of the phone number. */ -- (NSString *)normalizeDiallableCharsOnly:(NSString *)number { +- (NSString * _Nonnull)normalizeDiallableCharsOnly:(NSString * _Nonnull)number { number = NormalizeNonBreakingSpace(number); return [self stringByReplacingOccurrencesString:number @@ -706,7 +706,7 @@ - (NSString *)normalizeDiallableCharsOnly:(NSString *)number { * - param {string} number a string of characters representing a phone number. * @return {string} the normalized string version of the phone number. */ -- (NSString *)convertAlphaCharactersInNumber:(NSString *)number { +- (NSString * _Nonnull)convertAlphaCharactersInNumber:(NSString * _Nonnull)number { number = NormalizeNonBreakingSpace(number); return [self stringByReplacingOccurrencesString:number withMap:ALL_NORMALIZATION_MAPPINGS @@ -759,7 +759,7 @@ - (NSString *)convertAlphaCharactersInNumber:(NSString *)number { * which clients want to know the length of the area code. * @return {number} the length of area code of the PhoneNumber object passed in. */ -- (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber *)phoneNumber error:(NSError **)error { +- (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber * _Nonnull)phoneNumber error:(NSError * _Nullable * _Nullable)error { int res = 0; @try { res = [self getLengthOfGeographicalAreaCode:phoneNumber]; @@ -773,7 +773,7 @@ - (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber *)phoneNumber error:(NSErr return res; } -- (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber *)phoneNumber { +- (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber * _Nonnull)phoneNumber { NSString *regionCode = [self getRegionCodeForNumber:phoneNumber]; NBPhoneMetaData *metadata = [self.helper getMetadataForRegion:regionCode]; @@ -831,7 +831,7 @@ - (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber *)phoneNumber { * which clients want to know the length of the NDC. * @return {number} the length of NDC of the PhoneNumber object passed in. */ -- (int)getLengthOfNationalDestinationCode:(NBPhoneNumber *)phoneNumber error:(NSError **)error { +- (int)getLengthOfNationalDestinationCode:(NBPhoneNumber * _Nonnull)phoneNumber error:(NSError * _Nullable * _Nullable)error { int res = 0; @try { @@ -847,7 +847,7 @@ - (int)getLengthOfNationalDestinationCode:(NBPhoneNumber *)phoneNumber error:(NS return res; } -- (int)getLengthOfNationalDestinationCode:(NBPhoneNumber *)phoneNumber { +- (int)getLengthOfNationalDestinationCode:(NBPhoneNumber * _Nonnull)phoneNumber { NBPhoneNumber *copiedProto = nil; if ([NBMetadataHelper hasValue:phoneNumber.extension]) { @@ -901,7 +901,7 @@ - (int)getLengthOfNationalDestinationCode:(NBPhoneNumber *)phoneNumber { return (int)((NSString *)[numberGroups objectAtIndex:1]).length; } -- (NSString *)getCountryMobileTokenFromCountryCode:(NSInteger)countryCallingCode { +- (NSString * _Nonnull)getCountryMobileTokenFromCountryCode:(NSInteger)countryCallingCode { NSString *mobileToken = MOBILE_TOKEN_MAPPINGS[@(countryCallingCode)]; if (mobileToken != nil) { return mobileToken; @@ -924,9 +924,9 @@ - (NSString *)getCountryMobileTokenFromCountryCode:(NSInteger)countryCallingCode * @return {string} the normalized string version of the phone number. * @private */ -- (NSString *)normalizeHelper:(NSString *)sourceString - normalizationReplacements:(NSDictionary *)normalizationReplacements - removeNonMatches:(BOOL)removeNonMatches { +- (NSString * _Nonnull)normalizeHelper:(NSString * _Nonnull)sourceString + normalizationReplacements:(NSDictionary * _Nullable)normalizationReplacements + removeNonMatches:(BOOL)removeNonMatches { NSUInteger numberLength = sourceString.length; NSMutableString *normalizedNumber = [[NSMutableString alloc] init]; @@ -955,7 +955,7 @@ - (NSString *)normalizeHelper:(NSString *)sourceString * @return {boolean} NO if the national prefix formatting rule has the first * group only. */ -- (BOOL)formattingRuleHasFirstGroupOnly:(NSString *)nationalPrefixFormattingRule { +- (BOOL)formattingRuleHasFirstGroupOnly:(NSString * _Nullable)nationalPrefixFormattingRule { BOOL hasFound = [self stringPositionByRegex:nationalPrefixFormattingRule regex:FIRST_GROUP_ONLY_PREFIX_PATTERN] >= 0; return (([nationalPrefixFormattingRule length] == 0) || hasFound); @@ -970,7 +970,7 @@ - (BOOL)formattingRuleHasFirstGroupOnly:(NSString *)nationalPrefixFormattingRule * @return {boolean} NO if the phone number has a geographical association. * @private */ -- (BOOL)isNumberGeographical:(NBPhoneNumber *)phoneNumber { +- (BOOL)isNumberGeographical:(NBPhoneNumber * _Nonnull)phoneNumber { NBEPhoneNumberType numberType = [self getNumberType:phoneNumber]; // TODO: Include mobile phone numbers from countries like Indonesia, which // has some mobile numbers that are geographical. @@ -989,7 +989,7 @@ - (BOOL)isNumberGeographical:(NBPhoneNumber *)phoneNumber { * @return {boolean} NO if region code is valid. * @private */ -- (BOOL)isValidRegionCode:(NSString *)regionCode { +- (BOOL)isValidRegionCode:(NSString * _Nonnull)regionCode { // In Java we check whether the regionCode is contained in supportedRegions // that is built out of all the values of countryCallingCodeToRegionCodeMap // (countryCodeToRegionCodeMap in JS) minus REGION_CODE_FOR_NON_GEO_ENTITY. @@ -1009,7 +1009,7 @@ - (BOOL)isValidRegionCode:(NSString *)regionCode { * @return {boolean} NO if country calling code code is valid. * @private */ -- (BOOL)hasValidCountryCallingCode:(NSNumber *)countryCallingCode { +- (BOOL)hasValidCountryCallingCode:(NSNumber * _Nonnull)countryCallingCode { id res = [self.helper regionCodeFromCountryCode:countryCallingCode]; if (res != nil) { return YES; @@ -1035,9 +1035,9 @@ - (BOOL)hasValidCountryCallingCode:(NSNumber *)countryCallingCode { * phone number should be formatted into. * @return {string} the formatted phone number. */ -- (NSString *)format:(NBPhoneNumber *)phoneNumber - numberFormat:(NBEPhoneNumberFormat)numberFormat - error:(NSError **)error { +- (NSString * _Nullable)format:(NBPhoneNumber * _Nonnull)phoneNumber + numberFormat:(NBEPhoneNumberFormat)numberFormat + error:(NSError * _Nullable * _Nullable)error { NSString *res = nil; @try { res = [self format:phoneNumber numberFormat:numberFormat]; @@ -1049,7 +1049,7 @@ - (NSString *)format:(NBPhoneNumber *)phoneNumber return res; } -- (NSString *)format:(NBPhoneNumber *)phoneNumber numberFormat:(NBEPhoneNumberFormat)numberFormat { +- (NSString * _Nonnull)format:(NBPhoneNumber * _Nonnull)phoneNumber numberFormat:(NBEPhoneNumberFormat)numberFormat { if ([phoneNumber.nationalNumber isEqualToNumber:@0] && [NBMetadataHelper hasValue:phoneNumber.rawInput]) { // Unparseable numbers that kept their raw input just use that. @@ -1123,10 +1123,10 @@ - (NSString *)format:(NBPhoneNumber *)phoneNumber numberFormat:(NBEPhoneNumberFo * rules specified by clients. * @return {string} the formatted phone number. */ -- (NSString *)formatByPattern:(NBPhoneNumber *)number - numberFormat:(NBEPhoneNumberFormat)numberFormat - userDefinedFormats:(NSArray *)userDefinedFormats - error:(NSError **)error { +- (NSString * _Nullable)formatByPattern:(NBPhoneNumber * _Nonnull)number + numberFormat:(NBEPhoneNumberFormat)numberFormat + userDefinedFormats:(NSArray * _Nullable)userDefinedFormats + error:(NSError * _Nullable * _Nullable)error { NSString *res = nil; @try { res = [self formatByPattern:number @@ -1140,9 +1140,9 @@ - (NSString *)formatByPattern:(NBPhoneNumber *)number return res; } -- (NSString *)formatByPattern:(NBPhoneNumber *)number - numberFormat:(NBEPhoneNumberFormat)numberFormat - userDefinedFormats:(NSArray *)userDefinedFormats { +- (NSString * _Nullable)formatByPattern:(NBPhoneNumber * _Nonnull)number + numberFormat:(NBEPhoneNumberFormat)numberFormat + userDefinedFormats:(NSArray * _Nullable)userDefinedFormats { NSNumber *countryCallingCode = number.countryCode; NSString *nationalSignificantNumber = [self getNationalSignificantNumber:number]; @@ -1228,9 +1228,9 @@ - (NSString *)formatByPattern:(NBPhoneNumber *)number * @return {string} the formatted phone number in national format for dialing * using the carrier as specified in the {@code carrierCode}. */ -- (NSString *)formatNationalNumberWithCarrierCode:(NBPhoneNumber *)number - carrierCode:(NSString *)carrierCode - error:(NSError **)error { +- (NSString * _Nullable)formatNationalNumberWithCarrierCode:(NBPhoneNumber * _Nonnull)number + carrierCode:(NSString * _Nullable)carrierCode + error:(NSError * _Nullable * _Nullable)error { NSString *res = nil; @try { res = [self formatNationalNumberWithCarrierCode:number carrierCode:carrierCode]; @@ -1244,8 +1244,8 @@ - (NSString *)formatNationalNumberWithCarrierCode:(NBPhoneNumber *)number return res; } -- (NSString *)formatNationalNumberWithCarrierCode:(NBPhoneNumber *)number - carrierCode:(NSString *)carrierCode { +- (NSString * _Nullable)formatNationalNumberWithCarrierCode:(NBPhoneNumber * _Nonnull)number + carrierCode:(NSString * _Nullable)carrierCode { NSNumber *countryCallingCode = number.countryCode; NSString *nationalSignificantNumber = [self getNationalSignificantNumber:number]; @@ -1280,8 +1280,8 @@ - (NSString *)formatNationalNumberWithCarrierCode:(NBPhoneNumber *)number * @return {i18n.phonenumbers.PhoneMetadata} * @private */ -- (NBPhoneMetaData *)getMetadataForRegionOrCallingCode:(NSNumber *)countryCallingCode - regionCode:(NSString *)regionCode { +- (NBPhoneMetaData * _Nullable)getMetadataForRegionOrCallingCode:(NSNumber * _Nonnull)countryCallingCode + regionCode:(NSString * _Nullable)regionCode { NBMetadataHelper *helper = self.helper; return [regionCode isEqualToString:NB_REGION_CODE_FOR_NON_GEO_ENTITY] @@ -1309,9 +1309,9 @@ - (NBPhoneMetaData *)getMetadataForRegionOrCallingCode:(NSNumber *)countryCallin * using the number's preferred_domestic_carrier_code, or the * {@code fallbackCarrierCode} passed in if none is found. */ -- (NSString *)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber *)number - fallbackCarrierCode:(NSString *)fallbackCarrierCode - error:(NSError **)error { +- (NSString * _Nullable)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber * _Nonnull)number + fallbackCarrierCode:(NSString * _Nonnull)fallbackCarrierCode + error:(NSError * _Nullable * _Nullable)error { NSString *res = nil; @try { res = [self formatNationalNumberWithCarrierCode:number carrierCode:fallbackCarrierCode]; @@ -1326,8 +1326,8 @@ - (NSString *)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber *)numb return res; } -- (NSString *)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber *)number - fallbackCarrierCode:(NSString *)fallbackCarrierCode { +- (NSString * _Nullable)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber * _Nonnull)number + fallbackCarrierCode:(NSString * _Nonnull)fallbackCarrierCode { NSString *domesticCarrierCode = number.preferredDomesticCarrierCode != nil ? number.preferredDomesticCarrierCode : fallbackCarrierCode; @@ -1347,10 +1347,10 @@ - (NSString *)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber *)numb * formatting symbols, such as spaces and dashes. * @return {string} the formatted phone number. */ -- (NSString *)formatNumberForMobileDialing:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom - withFormatting:(BOOL)withFormatting - error:(NSError **)error { +- (NSString * _Nullable)formatNumberForMobileDialing:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom + withFormatting:(BOOL)withFormatting + error:(NSError * _Nullable * _Nullable)error { NSString *res = nil; @try { res = [self formatNumberForMobileDialing:number @@ -1364,9 +1364,9 @@ - (NSString *)formatNumberForMobileDialing:(NBPhoneNumber *)number return res; } -- (NSString *)formatNumberForMobileDialing:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom - withFormatting:(BOOL)withFormatting { +- (NSString * _Nullable)formatNumberForMobileDialing:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom + withFormatting:(BOOL)withFormatting { NSNumber *countryCallingCode = number.countryCode; if ([self hasValidCountryCallingCode:countryCallingCode] == NO) { @@ -1451,9 +1451,9 @@ - (NSString *)formatNumberForMobileDialing:(NBPhoneNumber *)number * - param {string} regionCallingFrom the region where the call is being placed. * @return {string} the formatted phone number. */ -- (NSString *)formatOutOfCountryCallingNumber:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom - error:(NSError **)error { +- (NSString * _Nullable)formatOutOfCountryCallingNumber:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom + error:(NSError * _Nullable * _Nullable)error { NSString *res = nil; @try { res = [self formatOutOfCountryCallingNumber:number regionCallingFrom:regionCallingFrom]; @@ -1466,8 +1466,8 @@ - (NSString *)formatOutOfCountryCallingNumber:(NBPhoneNumber *)number return res; } -- (NSString *)formatOutOfCountryCallingNumber:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom { +- (NSString * _Nullable)formatOutOfCountryCallingNumber:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom { if ([self isValidRegionCode:regionCallingFrom] == NO) { return [self format:number numberFormat:NBEPhoneNumberFormatINTERNATIONAL]; } @@ -1553,10 +1553,10 @@ - (NSString *)formatOutOfCountryCallingNumber:(NBPhoneNumber *)number * @return {string} the formatted phone number. * @private */ -- (NSString *)prefixNumberWithCountryCallingCode:(NSNumber *)countryCallingCode - phoneNumberFormat:(NBEPhoneNumberFormat)numberFormat - formattedNationalNumber:(NSString *)formattedNationalNumber - formattedExtension:(NSString *)formattedExtension { +- (NSString * _Nonnull)prefixNumberWithCountryCallingCode:(NSNumber * _Nonnull)countryCallingCode + phoneNumberFormat:(NBEPhoneNumberFormat)numberFormat + formattedNationalNumber:(NSString * _Nonnull)formattedNationalNumber + formattedExtension:(NSString * _Nonnull)formattedExtension { switch (numberFormat) { case NBEPhoneNumberFormatE164: return [NSString stringWithFormat:@"+%@%@%@", countryCallingCode, formattedNationalNumber, @@ -1591,9 +1591,9 @@ - (NSString *)prefixNumberWithCountryCallingCode:(NSNumber *)countryCallingCode * if the original number has one. * @return {string} the formatted phone number in its original number format. */ -- (NSString *)formatInOriginalFormat:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom - error:(NSError **)error { +- (NSString * _Nullable)formatInOriginalFormat:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom + error:(NSError * _Nullable * _Nullable)error { NSString *res = nil; @try { res = [self formatInOriginalFormat:number regionCallingFrom:regionCallingFrom]; @@ -1606,8 +1606,8 @@ - (NSString *)formatInOriginalFormat:(NBPhoneNumber *)number return res; } -- (NSString *)formatInOriginalFormat:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom { +- (NSString * _Nullable)formatInOriginalFormat:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom { if ([NBMetadataHelper hasValue:number.rawInput] && ([self hasFormattingPatternForNumber:number] == NO)) { // We check if we have the formatting pattern because without that, we might @@ -1735,9 +1735,9 @@ - (NSString *)formatInOriginalFormat:(NBPhoneNumber *)number * @return {boolean} * @private */ -- (BOOL)rawInputContainsNationalPrefix:(NSString *)rawInput - nationalPrefix:(NSString *)nationalPrefix - regionCode:(NSString *)regionCode { +- (BOOL)rawInputContainsNationalPrefix:(NSString * _Nonnull)rawInput + nationalPrefix:(NSString * _Nonnull)nationalPrefix + regionCode:(NSString * _Nonnull)regionCode { BOOL isValid = NO; NSString *normalizedNationalNumber = [self normalizeDigitsOnly:rawInput]; if ([self isStartingStringByRegex:normalizedNationalNumber regex:nationalPrefix]) { @@ -1763,7 +1763,7 @@ - (BOOL)rawInputContainsNationalPrefix:(NSString *)rawInput * @return {boolean} * @private */ -- (BOOL)hasUnexpectedItalianLeadingZero:(NBPhoneNumber *)number { +- (BOOL)hasUnexpectedItalianLeadingZero:(NBPhoneNumber * _Nonnull)number { return number.italianLeadingZero && [self isLeadingZeroPossible:number.countryCode] == NO; } @@ -1772,7 +1772,7 @@ - (BOOL)hasUnexpectedItalianLeadingZero:(NBPhoneNumber *)number { * @return {boolean} * @private */ -- (BOOL)hasFormattingPatternForNumber:(NBPhoneNumber *)number { +- (BOOL)hasFormattingPatternForNumber:(NBPhoneNumber * _Nonnull)number { NSNumber *countryCallingCode = number.countryCode; NSString *phoneNumberRegion = [self getRegionCodeForCountryCode:countryCallingCode]; NBPhoneMetaData *metadata = [self getMetadataForRegionOrCallingCode:countryCallingCode @@ -1814,9 +1814,9 @@ - (BOOL)hasFormattingPatternForNumber:(NBPhoneNumber *)number { * - param {string} regionCallingFrom the region where the call is being placed. * @return {string} the formatted phone number. */ -- (NSString *)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom - error:(NSError **)error { +- (NSString * _Nullable)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom + error:(NSError * _Nullable * _Nullable)error { NSString *res = nil; @try { res = [self formatOutOfCountryKeepingAlphaChars:number regionCallingFrom:regionCallingFrom]; @@ -1828,8 +1828,8 @@ - (NSString *)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber *)number return res; } -- (NSString *)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber *)number - regionCallingFrom:(NSString *)regionCallingFrom { +- (NSString * _Nullable)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber * _Nonnull)number + regionCallingFrom:(NSString * _Nonnull)regionCallingFrom { NSString *rawInput = number.rawInput; // If there is no raw input, then we can't keep alpha characters because there // aren't any. In this case, we return formatOutOfCountryCallingNumber. @@ -1952,10 +1952,10 @@ - (NSString *)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber *)number * @return {string} the formatted phone number. * @private */ -- (NSString *)formatNsn:(NSString *)phoneNumber - metadata:(NBPhoneMetaData *)metadata - phoneNumberFormat:(NBEPhoneNumberFormat)numberFormat - carrierCode:(NSString *)opt_carrierCode { +- (NSString * _Nonnull)formatNsn:(NSString * _Nonnull)phoneNumber + metadata:(NBPhoneMetaData * _Nonnull)metadata + phoneNumberFormat:(NBEPhoneNumberFormat)numberFormat + carrierCode:(NSString * _Nullable)opt_carrierCode { NSArray *intlNumberFormats = metadata.intlNumberFormats; // When the intlNumberFormats exists, we use that to format national number // for the INTERNATIONAL format instead of using the numberDesc.numberFormats. @@ -1984,8 +1984,8 @@ - (NSString *)formatNsn:(NSString *)phoneNumber * @return {i18n.phonenumbers.NumberFormat} * @private */ -- (NBNumberFormat *)chooseFormattingPatternForNumber:(NSArray *)availableFormats - nationalNumber:(NSString *)nationalNumber { +- (NBNumberFormat * _Nullable)chooseFormattingPatternForNumber:(NSArray * _Nullable)availableFormats + nationalNumber:(NSString * _Nonnull)nationalNumber { for (NBNumberFormat *numFormat in availableFormats) { NSUInteger size = [numFormat.leadingDigitsPatterns count]; // We always use the last leading_digits_pattern, as it is the most detailed. @@ -2015,10 +2015,10 @@ - (NBNumberFormat *)chooseFormattingPatternForNumber:(NSArray *)availableFormats * @return {string} the formatted phone number. * @private */ -- (NSString *)formatNsnUsingPattern:(NSString *)nationalNumber - formattingPattern:(NBNumberFormat *)formattingPattern - numberFormat:(NBEPhoneNumberFormat)numberFormat - carrierCode:(NSString *)opt_carrierCode { +- (NSString * _Nonnull)formatNsnUsingPattern:(NSString * _Nonnull)nationalNumber + formattingPattern:(NBNumberFormat * _Nonnull)formattingPattern + numberFormat:(NBEPhoneNumberFormat)numberFormat + carrierCode:(NSString * _Nullable)opt_carrierCode { NSString *numberFormatRule = formattingPattern.format; NSString *domesticCarrierCodeFormattingRule = formattingPattern.domesticCarrierCodeFormattingRule; NSString *formattedNationalNumber = @""; @@ -2029,7 +2029,7 @@ - (NSString *)formatNsnUsingPattern:(NSString *)nationalNumber NSString *carrierCodeFormattingRule = [self replaceStringByRegex:domesticCarrierCodeFormattingRule regex:CC_PATTERN - withTemplate:opt_carrierCode]; + withTemplate:opt_carrierCode ?: @""]; // Now replace the $FG in the formatting rule with the first group and // the carrier code combined in the appropriate way. numberFormatRule = [self replaceFirstStringByRegex:numberFormatRule @@ -2081,7 +2081,7 @@ - (NSString *)formatNsnUsingPattern:(NSString *)nationalNumber * geographical numbers), call {@link #getExampleNumberForNonGeoEntity} * instead. */ -- (NBPhoneNumber *)getExampleNumber:(NSString *)regionCode error:(NSError *__autoreleasing *)error { +- (NBPhoneNumber * _Nullable)getExampleNumber:(NSString * _Nonnull)regionCode error:(NSError * _Nullable __autoreleasing * _Nullable)error { NBPhoneNumber *res = [self getExampleNumberForType:regionCode type:NBEPhoneNumberTypeFIXED_LINE error:error]; @@ -2100,9 +2100,9 @@ - (NBPhoneNumber *)getExampleNumber:(NSString *)regionCode error:(NSError *__aut * For 001 (representing non-geographical numbers), call * {@link #getExampleNumberForNonGeoEntity} instead. */ -- (NBPhoneNumber *)getExampleNumberForType:(NSString *)regionCode - type:(NBEPhoneNumberType)type - error:(NSError *__autoreleasing *)error { +- (NBPhoneNumber * _Nullable)getExampleNumberForType:(NSString * _Nonnull)regionCode + type:(NBEPhoneNumberType)type + error:(NSError * _Nullable __autoreleasing * _Nullable)error { NBPhoneNumber *res = nil; if ([self isValidRegionCode:regionCode] == NO) { @@ -2130,8 +2130,8 @@ - (NBPhoneNumber *)getExampleNumberForType:(NSString *)regionCode * such information, or the country calling code passed in does not belong * to a non-geographical entity. */ -- (NBPhoneNumber *)getExampleNumberForNonGeoEntity:(NSNumber *)countryCallingCode - error:(NSError *__autoreleasing *)error { +- (NBPhoneNumber * _Nullable)getExampleNumberForNonGeoEntity:(NSNumber * _Nonnull)countryCallingCode + error:(NSError * _Nullable * _Nullable)error { NBPhoneNumber *res = nil; NBPhoneMetaData *metadata = [self.helper getMetadataForNonGeographicalRegion:countryCallingCode]; @@ -2177,9 +2177,9 @@ - (NBPhoneNumber *)getExampleNumberForNonGeoEntity:(NSNumber *)countryCallingCod * @return {string} the formatted extension if any. * @private */ -- (NSString *)maybeGetFormattedExtension:(NBPhoneNumber *)number - metadata:(NBPhoneMetaData *)metadata - numberFormat:(NBEPhoneNumberFormat)numberFormat { +- (NSString * _Nonnull)maybeGetFormattedExtension:(NBPhoneNumber * _Nonnull)number + metadata:(NBPhoneMetaData * _Nonnull)metadata + numberFormat:(NBEPhoneNumberFormat)numberFormat { if ([NBMetadataHelper hasValue:number.extension] == NO) { return @""; } else { @@ -2201,8 +2201,8 @@ - (NSString *)maybeGetFormattedExtension:(NBPhoneNumber *)number * @return {i18n.phonenumbers.PhoneNumberDesc} * @private */ -- (NBPhoneNumberDesc *)getNumberDescByType:(NBPhoneMetaData *)metadata - type:(NBEPhoneNumberType)type { +- (NBPhoneNumberDesc * _Nonnull)getNumberDescByType:(NBPhoneMetaData * _Nonnull)metadata + type:(NBEPhoneNumberType)type { switch (type) { case NBEPhoneNumberTypePREMIUM_RATE: return metadata.premiumRate; @@ -2239,7 +2239,7 @@ - (NBPhoneNumberDesc *)getNumberDescByType:(NBPhoneMetaData *)metadata * to know the type. * @return {i18n.phonenumbers.PhoneNumberType} the type of the phone number. */ -- (NBEPhoneNumberType)getNumberType:(NBPhoneNumber *)phoneNumber { +- (NBEPhoneNumberType)getNumberType:(NBPhoneNumber * _Nonnull)phoneNumber { NSString *regionCode = [self getRegionCodeForNumber:phoneNumber]; NBPhoneMetaData *metadata = [self getMetadataForRegionOrCallingCode:phoneNumber.countryCode regionCode:regionCode]; @@ -2257,8 +2257,8 @@ - (NBEPhoneNumberType)getNumberType:(NBPhoneNumber *)phoneNumber { * @return {i18n.phonenumbers.PhoneNumberType} * @private */ -- (NBEPhoneNumberType)getNumberTypeHelper:(NSString *)nationalNumber - metadata:(NBPhoneMetaData *)metadata { +- (NBEPhoneNumberType)getNumberTypeHelper:(NSString * _Nonnull)nationalNumber + metadata:(NBPhoneMetaData * _Nonnull)metadata { NBPhoneNumberDesc *generalNumberDesc = metadata.generalDesc; if ([self isNumberMatchingDesc:nationalNumber numberDesc:generalNumberDesc] == NO) { @@ -2323,7 +2323,7 @@ - (NBEPhoneNumberType)getNumberTypeHelper:(NSString *)nationalNumber * @return {boolean} * @private */ -- (BOOL)isNumberMatchingDesc:(NSString *)nationalNumber numberDesc:(NBPhoneNumberDesc *)numberDesc { +- (BOOL)isNumberMatchingDesc:(NSString * _Nonnull)nationalNumber numberDesc:(NBPhoneNumberDesc * _Nonnull)numberDesc { NSNumber *actualLength = [NSNumber numberWithUnsignedInteger:nationalNumber.length]; if (numberDesc.possibleLength.count > 0 && @@ -2344,7 +2344,7 @@ - (BOOL)isNumberMatchingDesc:(NSString *)nationalNumber numberDesc:(NBPhoneNumbe * @return {boolean} a boolean that indicates whether the number is of a valid * pattern. */ -- (BOOL)isValidNumber:(NBPhoneNumber *)number { +- (BOOL)isValidNumber:(NBPhoneNumber * _Nonnull)number { NSString *regionCode = [self getRegionCodeForNumber:number]; return [self isValidNumberForRegion:number regionCode:regionCode]; } @@ -2369,7 +2369,7 @@ - (BOOL)isValidNumber:(NBPhoneNumber *)number { * @return {boolean} a boolean that indicates whether the number is of a valid * pattern. */ -- (BOOL)isValidNumberForRegion:(NBPhoneNumber *)number regionCode:(NSString *)regionCode { +- (BOOL)isValidNumberForRegion:(NBPhoneNumber * _Nonnull)number regionCode:(NSString * _Nonnull)regionCode { NSNumber *countryCode = [number.countryCode copy]; NBPhoneMetaData *metadata = [self getMetadataForRegionOrCallingCode:countryCode regionCode:regionCode]; @@ -2407,7 +2407,7 @@ - (BOOL)isValidNumberForRegion:(NBPhoneNumber *)number regionCode:(NSString *)re * @return {?string} the region where the phone number is from, or nil * if no region matches this calling code. */ -- (NSString *)getRegionCodeForNumber:(NBPhoneNumber *)phoneNumber { +- (NSString * _Nullable)getRegionCodeForNumber:(NBPhoneNumber * _Nullable)phoneNumber { if (phoneNumber == nil) { return nil; } @@ -2431,8 +2431,8 @@ - (NSString *)getRegionCodeForNumber:(NBPhoneNumber *)phoneNumber { * @private */ -- (NSString *)getRegionCodeForNumberFromRegionList:(NBPhoneNumber *)phoneNumber - regionCodes:(NSArray *)regionCodes { +- (NSString * _Nullable)getRegionCodeForNumberFromRegionList:(NBPhoneNumber * _Nonnull)phoneNumber + regionCodes:(NSArray * _Nonnull)regionCodes { NSString *nationalNumber = [self getNationalSignificantNumber:phoneNumber]; NSUInteger regionCodesCount = [regionCodes count]; @@ -2464,7 +2464,7 @@ - (NSString *)getRegionCodeForNumberFromRegionList:(NBPhoneNumber *)phoneNumber * - param {number} countryCallingCode the country calling code. * @return {string} */ -- (NSString *)getRegionCodeForCountryCode:(NSNumber *)countryCallingCode { +- (NSString * _Nonnull)getRegionCodeForCountryCode:(NSNumber * _Nonnull)countryCallingCode { NSArray *regionCodes = [self.helper regionCodeFromCountryCode:countryCallingCode]; return regionCodes == nil ? NB_UNKNOWN_REGION : [regionCodes objectAtIndex:0]; } @@ -2478,7 +2478,7 @@ - (NSString *)getRegionCodeForCountryCode:(NSNumber *)countryCallingCode { * - param {number} countryCallingCode the country calling code. * @return {Array.} */ -- (NSArray *)getRegionCodesForCountryCode:(NSNumber *)countryCallingCode { +- (NSArray * _Nullable)getRegionCodesForCountryCode:(NSNumber * _Nonnull)countryCallingCode { NSArray *regionCodes = [self.helper regionCodeFromCountryCode:countryCallingCode]; return regionCodes == nil ? nil : regionCodes; } @@ -2492,7 +2492,7 @@ - (NSArray *)getRegionCodesForCountryCode:(NSNumber *)countryCallingCode { * @return {number} the country calling code for the region denoted by * regionCode. */ -- (NSNumber *)getCountryCodeForRegion:(NSString *)regionCode { +- (NSNumber * _Nonnull)getCountryCodeForRegion:(NSString * _Nullable)regionCode { if ([self isValidRegionCode:regionCode] == NO) { return @0; } @@ -2518,7 +2518,7 @@ - (NSNumber *)getCountryCodeForRegion:(NSString *)regionCode { * @throws {string} if the region is invalid * @private */ -- (NSNumber *)getCountryCodeForValidRegion:(NSString *)regionCode error:(NSError **)error { +- (NSNumber * _Nonnull)getCountryCodeForValidRegion:(NSString * _Nonnull)regionCode error:(NSError * _Nullable * _Nullable)error { NBPhoneMetaData *metadata = [self.helper getMetadataForRegion:regionCode]; if (metadata == nil) { @@ -2554,7 +2554,7 @@ - (NSNumber *)getCountryCodeForValidRegion:(NSString *)regionCode error:(NSError * @return {?string} the dialling prefix for the region denoted by * regionCode. */ -- (NSString *)getNddPrefixForRegion:(NSString *)regionCode stripNonDigits:(BOOL)stripNonDigits { +- (NSString * _Nullable)getNddPrefixForRegion:(NSString * _Nullable)regionCode stripNonDigits:(BOOL)stripNonDigits { NBPhoneMetaData *metadata = [self.helper getMetadataForRegion:regionCode]; if (metadata == nil) { return nil; @@ -2581,7 +2581,7 @@ - (NSString *)getNddPrefixForRegion:(NSString *)regionCode stripNonDigits:(BOOL) * - param {?string} regionCode the ISO 3166-1 two-letter region code. * @return {boolean} NO if regionCode is one of the regions under NANPA. */ -- (BOOL)isNANPACountry:(NSString *)regionCode { +- (BOOL)isNANPACountry:(NSString * _Nullable)regionCode { BOOL isExists = NO; NSArray *res = [self.helper regionCodeFromCountryCode:[NSNumber numberWithUnsignedInteger:NANPA_COUNTRY_CODE_]]; @@ -2604,7 +2604,7 @@ - (BOOL)isNANPACountry:(NSString *)regionCode { * - param {number} countryCallingCode the country calling code. * @return {boolean} */ -- (BOOL)isLeadingZeroPossible:(NSNumber *)countryCallingCode { +- (BOOL)isLeadingZeroPossible:(NSNumber * _Nonnull)countryCallingCode { NBPhoneMetaData *mainMetadataForCallingCode = [self getMetadataForRegionOrCallingCode:countryCallingCode regionCode:[self getRegionCodeForCountryCode:countryCallingCode]]; @@ -2623,7 +2623,7 @@ - (BOOL)isLeadingZeroPossible:(NSNumber *)countryCallingCode { * - param {string} number the number that needs to be checked. * @return {boolean} NO if the number is a valid vanity number. */ -- (BOOL)isAlphaNumber:(NSString *)number { +- (BOOL)isAlphaNumber:(NSString * _Nonnull)number { if ([self isViablePhoneNumber:number] == NO) { // Number is too short, or doesn't match the basic phone number pattern. return NO; @@ -2646,7 +2646,7 @@ - (BOOL)isAlphaNumber:(NSString *)number { * checked. * @return {boolean} NO if the number is possible. */ -- (BOOL)isPossibleNumber:(NBPhoneNumber *)number error:(NSError **)error { +- (BOOL)isPossibleNumber:(NBPhoneNumber * _Nonnull)number error:(NSError * _Nullable * _Nullable)error { BOOL res = NO; @try { res = [self isPossibleNumber:number]; @@ -2658,7 +2658,7 @@ - (BOOL)isPossibleNumber:(NBPhoneNumber *)number error:(NSError **)error { return res; } -- (BOOL)isPossibleNumber:(NBPhoneNumber *)number { +- (BOOL)isPossibleNumber:(NBPhoneNumber * _Nonnull)number { return [self isPossibleNumberWithReason:number] == NBEValidationResultIS_POSSIBLE; } @@ -2666,8 +2666,8 @@ - (BOOL)isPossibleNumber:(NBPhoneNumber *)number { * Helper method to check a number against possible lengths for this region, based on the metadata * being passed in, and determine whether it matches, or is too short or too long. */ -- (NBEValidationResult)validateNumberLength:(NSString *)number - metadata:(NBPhoneMetaData *)metadata { +- (NBEValidationResult)validateNumberLength:(NSString * _Nonnull)number + metadata:(NBPhoneMetaData * _Nonnull)metadata { return [self validateNumberLength:number metadata:metadata type:NBEPhoneNumberTypeUNKNOWN]; } @@ -2675,8 +2675,8 @@ - (NBEValidationResult)validateNumberLength:(NSString *)number * Helper method to check a number against possible lengths for this number type, and determine * whether it matches, or is too short or too long. */ -- (NBEValidationResult)validateNumberLength:(NSString *)number - metadata:(NBPhoneMetaData *)metadata +- (NBEValidationResult)validateNumberLength:(NSString * _Nonnull)number + metadata:(NBPhoneMetaData * _Nonnull)metadata type:(NBEPhoneNumberType)type { NBPhoneNumberDesc *descForType = [self getNumberDescByType:metadata type:type]; // There should always be "possibleLengths" set for every element. @@ -2766,8 +2766,8 @@ - (NBEValidationResult)validateNumberLength:(NSString *)number * - return {i18n.phonenumbers.PhoneNumberUtil.ValidationResult} * @private */ -- (NBEValidationResult)testNumberLength:(NSString *)number - desc:(NBPhoneNumberDesc *)phoneNumberDesc { +- (NBEValidationResult)testNumberLength:(NSString * _Nonnull)number + desc:(NBPhoneNumberDesc * _Nonnull)phoneNumberDesc { NSArray *possibleLengths = phoneNumberDesc.possibleLength; NSArray *localLengths = phoneNumberDesc.possibleLengthLocalOnly; @@ -2825,8 +2825,8 @@ - (NBEValidationResult)testNumberLength:(NSString *)number * @return {ValidationResult} a * ValidationResult object which indicates whether the number is possible. */ -- (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber *)number - error:(NSError *__autoreleasing *)error { +- (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber * _Nonnull)number + error:(NSError * _Nullable * _Nullable)error { NBEValidationResult res = NBEValidationResultUNKNOWN; @try { res = [self isPossibleNumberWithReason:number]; @@ -2839,7 +2839,7 @@ - (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber *)number return res; } -- (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber *)number { +- (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber * _Nonnull)number { NSString *nationalNumber = [self getNationalSignificantNumber:number]; NSNumber *countryCode = number.countryCode; // Note: For Russian Fed and NANPA numbers, we just use the rules from the @@ -2881,9 +2881,9 @@ - (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber *)number { * (Mountain View, CA, to be more specific). * @return {boolean} NO if the number is possible. */ -- (BOOL)isPossibleNumberString:(NSString *)number - regionDialingFrom:(NSString *)regionDialingFrom - error:(NSError **)error { +- (BOOL)isPossibleNumberString:(NSString * _Nonnull)number + regionDialingFrom:(NSString * _Nullable)regionDialingFrom + error:(NSError * _Nullable * _Nullable)error { number = NormalizeNonBreakingSpace(number); BOOL res = [self isPossibleNumber:[self parse:number @@ -2902,7 +2902,7 @@ - (BOOL)isPossibleNumberString:(NSString *)number * @return {boolean} NO if a valid phone number can be successfully extracted. */ -- (BOOL)truncateTooLongNumber:(NBPhoneNumber *)number { +- (BOOL)truncateTooLongNumber:(NBPhoneNumber * _Nonnull)number { if ([self isValidNumber:number]) { return YES; } @@ -2933,7 +2933,7 @@ - (BOOL)truncateTooLongNumber:(NBPhoneNumber *)number { * - param {!goog.string.StringBuffer} nationalNumber * @return {number} */ -- (NSNumber *)extractCountryCode:(NSString *)fullNumber nationalNumber:(NSString **)nationalNumber { +- (NSNumber * _Nonnull)extractCountryCode:(NSString * _Nonnull)fullNumber nationalNumber:(NSString * _Nullable * _Nullable)nationalNumber { fullNumber = NormalizeNonBreakingSpace(fullNumber); if ((fullNumber.length == 0) || ([[fullNumber substringToIndex:1] isEqualToString:@"0"])) { @@ -2975,7 +2975,7 @@ - (NSNumber *)extractCountryCode:(NSString *)fullNumber nationalNumber:(NSString * @return {!Array.} region codes supported by the library. */ -- (NSArray *)getSupportedRegions { +- (NSArray * _Nullable)getSupportedRegions { NSArray *allKeys = [[self.helper countryCodeToCountryNumberDictionary] allKeys]; NSPredicate *predicateIsNaN = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { @@ -3057,12 +3057,12 @@ - (NSArray *)getSupportedRegions { * extracted. * @throws {i18n.phonenumbers.Error} */ -- (NSNumber *)maybeExtractCountryCode:(NSString *)number - metadata:(NBPhoneMetaData *)defaultRegionMetadata - nationalNumber:(NSString **)nationalNumber - keepRawInput:(BOOL)keepRawInput - phoneNumber:(NBPhoneNumber **)phoneNumber - error:(NSError **)error { +- (NSNumber * _Nonnull)maybeExtractCountryCode:(NSString * _Nonnull)number + metadata:(NBPhoneMetaData * _Nullable)defaultRegionMetadata + nationalNumber:(NSString * _Nullable * _Nullable)nationalNumber + keepRawInput:(BOOL)keepRawInput + phoneNumber:(NBPhoneNumber * _Nullable * _Nullable)phoneNumber + error:(NSError * _Nullable * _Nullable)error { if (nationalNumber == NULL || phoneNumber == NULL || number.length <= 0) { return @0; } @@ -3160,7 +3160,7 @@ - (NSNumber *)maybeExtractCountryCode:(NSString *)number /** * Returns true if there is any possible number data set for a particular PhoneNumberDesc. */ -- (BOOL)descHasPossibleNumberData:(NBPhoneNumberDesc *)desc { +- (BOOL)descHasPossibleNumberData:(NBPhoneNumberDesc * _Nonnull)desc { // If this is empty, it means numbers of this type inherit from the "general desc" -> the value // "-1" means that no numbers exist for this type. return [desc.possibleLength count] != 1 || @@ -3178,7 +3178,7 @@ - (BOOL)descHasPossibleNumberData:(NBPhoneNumberDesc *)desc { * @return {boolean} NO if an international prefix was present. * @private */ -- (BOOL)parsePrefixAsIdd:(NSString *)iddPattern sourceString:(NSString **)number { +- (BOOL)parsePrefixAsIdd:(NSString * _Nonnull)iddPattern sourceString:(NSString * _Nullable * _Nullable)number { if (number == NULL) { return NO; } @@ -3229,8 +3229,8 @@ - (BOOL)parsePrefixAsIdd:(NSString *)iddPattern sourceString:(NSString **)number * from the number, otherwise CountryCodeSource.FROM_DEFAULT_COUNTRY if * the number did not seem to be in international format. */ -- (NBECountryCodeSource)maybeStripInternationalPrefixAndNormalize:(NSString **)numberStr - possibleIddPrefix:(NSString *)possibleIddPrefix { +- (NBECountryCodeSource)maybeStripInternationalPrefixAndNormalize:(NSString * _Nullable * _Nullable)numberStr + possibleIddPrefix:(NSString * _Nonnull)possibleIddPrefix { if (numberStr == NULL || (*numberStr).length == 0) { return NBECountryCodeSourceFROM_DEFAULT_COUNTRY; } @@ -3266,9 +3266,9 @@ - (NBECountryCodeSource)maybeStripInternationalPrefixAndNormalize:(NSString **)n * @return {boolean} NO if a national prefix or carrier code (or both) could * be extracted. */ -- (BOOL)maybeStripNationalPrefixAndCarrierCode:(NSString **)number - metadata:(NBPhoneMetaData *)metadata - carrierCode:(NSString **)carrierCode { +- (BOOL)maybeStripNationalPrefixAndCarrierCode:(NSString * _Nullable * _Nullable)number + metadata:(NBPhoneMetaData * _Nonnull)metadata + carrierCode:(NSString * _Nullable * _Nullable)carrierCode { if (number == NULL) { return NO; } @@ -3329,7 +3329,7 @@ - (BOOL)maybeStripNationalPrefixAndCarrierCode:(NSString **)number if ((noTransform && numOfGroups > 0 && [NBMetadataHelper hasValue:firstMatchStringWithGroup]) || (!noTransform && numOfGroups > 1)) { if (carrierCode != NULL && (*carrierCode) != nil) { - (*carrierCode) = [(*carrierCode) stringByAppendingString:firstMatchStringWithGroup]; + (*carrierCode) = [(*carrierCode) stringByAppendingString:firstMatchStringWithGroup ?: @""]; } } else if ((noTransform && numOfGroups > 0 && [NBMetadataHelper hasValue:firstMatchString]) || (!noTransform && numOfGroups > 1)) { @@ -3353,7 +3353,7 @@ - (BOOL)maybeStripNationalPrefixAndCarrierCode:(NSString **)number * that we wish to strip the extension from. * @return {string} the phone extension. */ -- (NSString *)maybeStripExtension:(NSString **)number { +- (NSString * _Nonnull)maybeStripExtension:(NSString * _Nonnull * _Nonnull)number { if (number == NULL) { return @""; } @@ -3399,7 +3399,7 @@ - (NSString *)maybeStripExtension:(NSString **)number { * cannot be inferred. * @private */ -- (BOOL)checkRegionForParsing:(NSString *)numberToParse defaultRegion:(NSString *)defaultRegion { +- (BOOL)checkRegionForParsing:(NSString * _Nonnull)numberToParse defaultRegion:(NSString * _Nonnull)defaultRegion { // If the number is nil or empty, we can't infer the region. return [self isValidRegionCode:defaultRegion] || (numberToParse != nil && numberToParse.length > 0 && @@ -3428,9 +3428,9 @@ - (BOOL)checkRegionForParsing:(NSString *)numberToParse defaultRegion:(NSString * viable phone number or if no default region was supplied and the number * is not in international format (does not start with +). */ -- (NBPhoneNumber *)parse:(NSString *)numberToParse - defaultRegion:(NSString *)defaultRegion - error:(NSError **)error { +- (NBPhoneNumber * _Nullable)parse:(NSString * _Nullable)numberToParse + defaultRegion:(NSString * _Nullable)defaultRegion + error:(NSError * _Nullable * _Nullable)error { NSError *anError = nil; NBPhoneNumber *phoneNumber = [self parseHelper:numberToParse defaultRegion:defaultRegion @@ -3453,14 +3453,15 @@ - (NBPhoneNumber *)parse:(NSString *)numberToParse * number using +1 (AT&T is a US Carrier) as the default country code. * This also works for multi-SIM phones, using the SIM region of default voice line. */ -- (NBPhoneNumber *)parseWithPhoneCarrierRegion:(NSString *)numberToParse error:(NSError **)error { +- (NBPhoneNumber * _Nullable)parseWithPhoneCarrierRegion:(NSString * _Nullable)numberToParse + error:(NSError * _Nullable * _Nullable)error{ numberToParse = NormalizeNonBreakingSpace(numberToParse); NSString *defaultRegion = [self countryCodeByCarrier]; return [self parse:numberToParse defaultRegion:defaultRegion error:error]; } -- (NSString *)countryCodeByCarrier { +- (NSString * _Nonnull)countryCodeByCarrier { #if !TARGET_OS_TV return [[CNContactsUserDefaults sharedDefaults].countryCode uppercaseString]; #else @@ -3485,9 +3486,9 @@ - (NSString *)countryCodeByCarrier { * @throws {i18n.phonenumbers.Error} if the string is not considered to be a * viable phone number or if no default region was supplied. */ -- (NBPhoneNumber *)parseAndKeepRawInput:(NSString *)numberToParse - defaultRegion:(NSString *)defaultRegion - error:(NSError **)error { +- (NBPhoneNumber * _Nullable)parseAndKeepRawInput:(NSString * _Nonnull)numberToParse + defaultRegion:(NSString * _Nullable)defaultRegion + error:(NSError * _Nullable * _Nullable)error { if ([self isValidRegionCode:defaultRegion] == NO) { if (numberToParse.length > 0 && [numberToParse hasPrefix:@"+"] == NO) { NSDictionary *userInfo = [NSDictionary @@ -3514,8 +3515,8 @@ - (NBPhoneNumber *)parseAndKeepRawInput:(NSString *)numberToParse * buffer to fill in. * @private */ -- (void)setItalianLeadingZerosForPhoneNumber:(NSString *)nationalNumber - phoneNumber:(NBPhoneNumber *)phoneNumber { +- (void)setItalianLeadingZerosForPhoneNumber:(NSString * _Nonnull)nationalNumber + phoneNumber:(NBPhoneNumber * _Nonnull)phoneNumber { if (nationalNumber.length > 1 && [nationalNumber hasPrefix:@"0"]) { phoneNumber.italianLeadingZero = YES; NSInteger numberOfLeadingZeros = 1; @@ -3553,11 +3554,11 @@ - (void)setItalianLeadingZerosForPhoneNumber:(NSString *)nationalNumber * @throws {i18n.phonenumbers.Error} * @private */ -- (NBPhoneNumber *)parseHelper:(NSString *)numberToParse - defaultRegion:(NSString *)defaultRegion - keepRawInput:(BOOL)keepRawInput - checkRegion:(BOOL)checkRegion - error:(NSError **)error { +- (NBPhoneNumber * _Nullable)parseHelper:(NSString * _Nullable)numberToParse + defaultRegion:(NSString * _Nullable)defaultRegion + keepRawInput:(BOOL)keepRawInput + checkRegion:(BOOL)checkRegion + error:(NSError * _Nullable * _Nullable)error { numberToParse = NormalizeNonBreakingSpace(numberToParse); if (numberToParse == nil) { @@ -3750,8 +3751,8 @@ - (NBPhoneNumber *)parseHelper:(NSString *)numberToParse * the national significant number. * @private */ -- (void)buildNationalNumberForParsing:(NSString *)numberToParse - nationalNumber:(NSString **)nationalNumber { +- (void)buildNationalNumberForParsing:(NSString * _Nonnull)numberToParse + nationalNumber:(NSString * _Nonnull * _Nonnull)nationalNumber { if (nationalNumber == NULL) return; NSMutableString *result = [[NSMutableString alloc] init]; @@ -3832,7 +3833,7 @@ - (void)buildNationalNumberForParsing:(NSString *)numberToParse * SHORT_NSN_MATCH, NSN_MATCH or EXACT_MATCH depending on the level of * equality of the two numbers, described in the method definition. */ -- (NBEMatchType)isNumberMatch:(id)firstNumberIn second:(id)secondNumberIn error:(NSError **)error { +- (NBEMatchType)isNumberMatch:(id _Nonnull)firstNumberIn second:(id _Nonnull)secondNumberIn error:(NSError * _Nullable * _Nullable)error { NBEMatchType res = 0; @try { res = [self isNumberMatch:firstNumberIn second:secondNumberIn]; @@ -3844,7 +3845,7 @@ - (NBEMatchType)isNumberMatch:(id)firstNumberIn second:(id)secondNumberIn error: return res; } -- (NBEMatchType)isNumberMatch:(id)firstNumberIn second:(id)secondNumberIn { +- (NBEMatchType)isNumberMatch:(id _Nonnull)firstNumberIn second:(id _Nonnull)secondNumberIn { // If the input arguements are strings parse them to a proto buffer format. // Else make copies of the phone numbers so that the numbers passed in are not // edited. @@ -3988,8 +3989,8 @@ - (NBEMatchType)isNumberMatch:(id)firstNumberIn second:(id)secondNumberIn { * @return {boolean} NO if one PhoneNumber is the suffix of the other one. * @private */ -- (BOOL)isNationalNumberSuffixOfTheOther:(NBPhoneNumber *)firstNumber - second:(NBPhoneNumber *)secondNumber { +- (BOOL)isNationalNumberSuffixOfTheOther:(NBPhoneNumber * _Nonnull)firstNumber + second:(NBPhoneNumber * _Nonnull)secondNumber { NSString *firstNumberNationalNumber = [NSString stringWithFormat:@"%@", firstNumber.nationalNumber]; NSString *secondNumberNationalNumber = @@ -4012,7 +4013,7 @@ - (BOOL)isNationalNumberSuffixOfTheOther:(NBPhoneNumber *)firstNumber * @return {boolean} NO if the number can only be dialled from within the * country. */ -- (BOOL)canBeInternationallyDialled:(NBPhoneNumber *)number error:(NSError **)error { +- (BOOL)canBeInternationallyDialled:(NBPhoneNumber * _Nonnull)number error:(NSError * _Nullable * _Nullable)error { BOOL res = NO; @try { res = [self canBeInternationallyDialled:number]; @@ -4024,7 +4025,7 @@ - (BOOL)canBeInternationallyDialled:(NBPhoneNumber *)number error:(NSError **)er return res; } -- (BOOL)canBeInternationallyDialled:(NBPhoneNumber *)number { +- (BOOL)canBeInternationallyDialled:(NBPhoneNumber * _Nonnull)number { NBPhoneMetaData *metadata = [self.helper getMetadataForRegion:[self getRegionCodeForNumber:number]]; if (metadata == nil) { @@ -4046,7 +4047,7 @@ - (BOOL)canBeInternationallyDialled:(NBPhoneNumber *)number { * @return {boolean} NO if str can be matched entirely against regex. * @private */ -- (BOOL)matchesEntirely:(NSString *)regex string:(NSString *)str { +- (BOOL)matchesEntirely:(NSString * _Nonnull)regex string:(NSString * _Nonnull)str { if ([regex isEqualToString:@"NA"]) { return NO; } diff --git a/libPhoneNumberGeocoding/Metadata/NBGeocoderMetadataHelper.h b/libPhoneNumberGeocoding/Metadata/NBGeocoderMetadataHelper.h index 928d4144..f0d2bcf8 100644 --- a/libPhoneNumberGeocoding/Metadata/NBGeocoderMetadataHelper.h +++ b/libPhoneNumberGeocoding/Metadata/NBGeocoderMetadataHelper.h @@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN * @return a text description for the given language code for the given phone number, or nil if * there were no search results found for the given phone number. */ -- (NSString *)searchPhoneNumber:(NBPhoneNumber *)phoneNumber; +- (NSString * _Nullable)searchPhoneNumber:(NBPhoneNumber *)phoneNumber; @end diff --git a/libPhoneNumberGeocoding/Metadata/NBGeocoderMetadataHelper.m b/libPhoneNumberGeocoding/Metadata/NBGeocoderMetadataHelper.m index 3d8582a2..1192df87 100644 --- a/libPhoneNumberGeocoding/Metadata/NBGeocoderMetadataHelper.m +++ b/libPhoneNumberGeocoding/Metadata/NBGeocoderMetadataHelper.m @@ -73,7 +73,7 @@ - (instancetype)initWithCountryCode:(NSNumber *)countryCode withLanguage:(NSStri return [self initWithCountryCode:countryCode withLanguage:languageCode withBundle:databaseBundle]; } -- (NSString *)searchPhoneNumber:(NBPhoneNumber *)phoneNumber { +- (NSString * _Nullable)searchPhoneNumber:(NBPhoneNumber *)phoneNumber { @synchronized(self) { if (![phoneNumber.countryCode isEqualToNumber:_countryCode]) { _countryCode = phoneNumber.countryCode; diff --git a/libPhoneNumberShortNumber/NBShortNumberMetadataHelper.h b/libPhoneNumberShortNumber/NBShortNumberMetadataHelper.h index 5095589c..4dcee6e1 100644 --- a/libPhoneNumberShortNumber/NBShortNumberMetadataHelper.h +++ b/libPhoneNumberShortNumber/NBShortNumberMetadataHelper.h @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN * @param regionCode regionCode * @return {i18n.phonenumbers.PhoneMetadata} */ -- (NBPhoneMetaData *)shortNumberMetadataForRegion:(NSString *)regionCode; +- (NBPhoneMetaData * _Nullable)shortNumberMetadataForRegion:(NSString * _Nonnull)regionCode; @end diff --git a/libPhoneNumberShortNumber/NBShortNumberMetadataHelper.m b/libPhoneNumberShortNumber/NBShortNumberMetadataHelper.m index 077b2f5f..33c922f6 100644 --- a/libPhoneNumberShortNumber/NBShortNumberMetadataHelper.m +++ b/libPhoneNumberShortNumber/NBShortNumberMetadataHelper.m @@ -63,7 +63,7 @@ - (instancetype)initWithZippedDataBytes:(z_const Bytef *)data return self; } -- (NBPhoneMetaData *)shortNumberMetadataForRegion:(NSString *)regionCode { +- (NBPhoneMetaData * _Nullable)shortNumberMetadataForRegion:(NSString * _Nonnull)regionCode { regionCode = StringByTrimming(regionCode); if (regionCode.length == 0) { return nil; diff --git a/libPhoneNumberShortNumber/NBShortNumberUtil.h b/libPhoneNumberShortNumber/NBShortNumberUtil.h index 8208b3db..b9b312a0 100644 --- a/libPhoneNumberShortNumber/NBShortNumberUtil.h +++ b/libPhoneNumberShortNumber/NBShortNumberUtil.h @@ -65,7 +65,7 @@ typedef NS_ENUM(NSUInteger, NBEShortNumberCost) { * @param regionDialingFrom the region from which the number is dialed * @return whether the short number matches a valid pattern */ -- (BOOL)isValidShortNumber:(NBPhoneNumber *)phoneNumber forRegion:(NSString *)regionDialingFrom; +- (BOOL)isValidShortNumber:(NBPhoneNumber * _Nonnull)phoneNumber forRegion:(NSString * _Nonnull)regionDialingFrom; /** * Tests whether a short number matches a valid pattern. If a country calling code is shared by @@ -76,7 +76,7 @@ typedef NS_ENUM(NSUInteger, NBEShortNumberCost) { * @param phoneNumber the short number for which we want to test the validity * @return whether the short number matches a valid pattern */ -- (BOOL)isValidShortNumber:(NBPhoneNumber *)phoneNumber; +- (BOOL)isValidShortNumber:(NBPhoneNumber * _Nonnull)phoneNumber; /** * Gets the expected cost category of a short number when dialed from a region (however, nothing diff --git a/libPhoneNumberShortNumber/NBShortNumberUtil.m b/libPhoneNumberShortNumber/NBShortNumberUtil.m index 33986a01..019dd78d 100644 --- a/libPhoneNumberShortNumber/NBShortNumberUtil.m +++ b/libPhoneNumberShortNumber/NBShortNumberUtil.m @@ -79,7 +79,7 @@ - (BOOL)isPossibleShortNumber:(NBPhoneNumber *)phoneNumber { return NO; } -- (BOOL)isValidShortNumber:(NBPhoneNumber *)phoneNumber forRegion:(NSString *)regionDialingFrom { +- (BOOL)isValidShortNumber:(NBPhoneNumber * _Nonnull)phoneNumber forRegion:(NSString * _Nonnull)regionDialingFrom { if (![self doesPhoneNumber:phoneNumber matchesRegion:regionDialingFrom]) { return NO; } @@ -99,7 +99,7 @@ - (BOOL)isValidShortNumber:(NBPhoneNumber *)phoneNumber forRegion:(NSString *)re return [self matchesPossibleNumber:shortNumber andNationalNumber:shortNumberDesc]; } -- (BOOL)isValidShortNumber:(NBPhoneNumber *)phoneNumber { +- (BOOL)isValidShortNumber:(NBPhoneNumber * _Nonnull)phoneNumber { NSArray *regionCodes = [_phoneUtil getRegionCodesForCountryCode:phoneNumber.countryCode]; NSString *regionCode = [self regionCodeForShortNumber:phoneNumber fromRegionList:regionCodes]; @@ -109,7 +109,7 @@ - (BOOL)isValidShortNumber:(NBPhoneNumber *)phoneNumber { return YES; } - return [self isValidShortNumber:phoneNumber forRegion:regionCode]; + return [self isValidShortNumber:phoneNumber forRegion:regionCode ?: @""]; } - (NBEShortNumberCost)expectedCostOfPhoneNumber:(NBPhoneNumber *)phoneNumber @@ -228,7 +228,7 @@ - (BOOL)isEmergencyNumber:(NSString *)number forRegion:(NSString *)regionCode { // In these countries, if extra digits are added to an emergency number, it no longer connects // to the emergency service. -- (NSSet *)regionsWhereEmergencyNumbersMustBeExact { +- (NSSet * _Nonnull)regionsWhereEmergencyNumbersMustBeExact { static NSSet *regions; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -241,7 +241,7 @@ - (BOOL)isEmergencyNumber:(NSString *)number forRegion:(NSString *)regionCode { * Helper method to check that the country calling code of the number matches the region it's * being dialed from. */ -- (BOOL)doesPhoneNumber:(NBPhoneNumber *)phoneNumber matchesRegion:(NSString *)regionCode { +- (BOOL)doesPhoneNumber:(NBPhoneNumber * _Nonnull)phoneNumber matchesRegion:(NSString * _Nonnull)regionCode { NSArray *regionCodes = [_phoneUtil getRegionCodesForCountryCode:phoneNumber.countryCode]; return [regionCodes containsObject:regionCode]; @@ -258,7 +258,7 @@ - (BOOL)doesPhoneNumber:(NBPhoneNumber *)phoneNumber matchesRegion:(NSString *)r * @param number the phone number for which the national significant number is needed * @return the national significant number of the PhoneNumber object passed in */ -+ (NSString *)nationalSignificantNumberFromPhoneNumber:(NBPhoneNumber *)phoneNumber { ++ (NSString * _Nonnull)nationalSignificantNumberFromPhoneNumber:(NBPhoneNumber * _Nonnull)phoneNumber { // If leading zero(s) have been set, we prefix this now. Note this is not a national prefix. NSMutableString *nationalNumber = [[NSMutableString alloc] init]; if (phoneNumber.italianLeadingZero) { @@ -281,8 +281,8 @@ - (BOOL)matchesPossibleNumber:(NSString *)number andNationalNumber:(NBPhoneNumbe // Helper method to get the region code for a given phone number, from a list of possible region // codes. If the list contains more than one region, the first region for which the number is // valid is returned. -- (NSString *)regionCodeForShortNumber:(NBPhoneNumber *)number - fromRegionList:(NSArray *)regionCodes { +- (NSString * _Nullable)regionCodeForShortNumber:(NBPhoneNumber * _Nonnull)number + fromRegionList:(NSArray * _Nonnull)regionCodes { if (regionCodes.count == 0) { return nil; } else if (regionCodes.count == 1) { diff --git a/libPhoneNumberShortNumber/libPhoneNumberShortNumber.h b/libPhoneNumberShortNumber/libPhoneNumberShortNumber.h index d2f4e4bd..2ad93ea5 100644 --- a/libPhoneNumberShortNumber/libPhoneNumberShortNumber.h +++ b/libPhoneNumberShortNumber/libPhoneNumberShortNumber.h @@ -18,3 +18,4 @@ FOUNDATION_EXPORT const unsigned char libPhoneNumberShortNumberVersionString[]; // using statements like #import #import #import +#import diff --git a/libPhoneNumberTests/NBPhoneNumberUtilTest.m b/libPhoneNumberTests/NBPhoneNumberUtilTest.m index a09f533a..ea41db97 100644 --- a/libPhoneNumberTests/NBPhoneNumberUtilTest.m +++ b/libPhoneNumberTests/NBPhoneNumberUtilTest.m @@ -2121,12 +2121,12 @@ - (void)testMaybeExtractCountryCode { number = [[NBPhoneNumber alloc] init]; phoneNumber = @"2345-6789"; numberToFill = @""; - XCTAssertEqual(@0, [_aUtil maybeExtractCountryCode:phoneNumber - metadata:metadata - nationalNumber:&numberToFill - keepRawInput:YES - phoneNumber:&number - error:nil]); + XCTAssertEqualObjects(@0, [_aUtil maybeExtractCountryCode:phoneNumber + metadata:metadata + nationalNumber:&numberToFill + keepRawInput:YES + phoneNumber:&number + error:nil]); XCTAssertEqual(NBECountryCodeSourceFROM_DEFAULT_COUNTRY, [number.countryCodeSource integerValue], @"Did not figure out CountryCodeSource correctly"); @@ -2200,12 +2200,12 @@ - (void)testMaybeExtractCountryCode { numberToFill = @""; { NSError *anError = nil; - XCTAssertEqual(@0, [_aUtil maybeExtractCountryCode:phoneNumber - metadata:metadata - nationalNumber:&numberToFill - keepRawInput:YES - phoneNumber:&number - error:&anError]); + XCTAssertEqualObjects(@0, [_aUtil maybeExtractCountryCode:phoneNumber + metadata:metadata + nationalNumber:&numberToFill + keepRawInput:YES + phoneNumber:&number + error:&anError]); XCTAssertEqual(NBECountryCodeSourceFROM_DEFAULT_COUNTRY, [number.countryCodeSource integerValue]); }