Skip to content

Commit 768c6ec

Browse files
authored
Merge pull request #392 from LowAmmo/Issue391-analyzer-warnings
Issue #391 - Adding nullability specifiers to NBPhoneNumberUtil functions
2 parents 3220b40 + 90510c9 commit 768c6ec

File tree

16 files changed

+351
-348
lines changed

16 files changed

+351
-348
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
.target(
1515
name: "libPhoneNumber",
1616
path: "libPhoneNumber",
17-
exclude: ["GeneratePhoneNumberHeader.sh", "Info.plist"],
17+
exclude: ["Info.plist"],
1818
publicHeadersPath: ".",
1919
cSettings: [
2020
.headerSearchPath("Internal")

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let package = Package(
2020
.target(
2121
name: "libPhoneNumber",
2222
path: "libPhoneNumber",
23-
exclude: ["GeneratePhoneNumberHeader.sh", "Info.plist"],
23+
exclude: ["Info.plist"],
2424
publicHeadersPath: ".",
2525
cSettings: [
2626
.headerSearchPath("Internal")

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.target(
2222
name: "libPhoneNumber",
2323
path: "libPhoneNumber",
24-
exclude: ["GeneratePhoneNumberHeader.sh", "Info.plist"],
24+
exclude: ["Info.plist"],
2525
publicHeadersPath: ".",
2626
cSettings: [
2727
.headerSearchPath("Internal")

libPhoneNumber.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
940725A924BE77420011AE05 /* NBShortNumberUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 940725A724BE77420011AE05 /* NBShortNumberUtil.h */; settings = {ATTRIBUTES = (Public, ); }; };
5454
940725AA24BE77420011AE05 /* NBShortNumberUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 940725A824BE77420011AE05 /* NBShortNumberUtil.m */; };
5555
940725AC24BF63050011AE05 /* NBShortNumberInfoTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 940725AB24BF63050011AE05 /* NBShortNumberInfoTest.m */; };
56-
940725AD24BF63500011AE05 /* NBMetadataHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FD12C2681A87401B00B53856 /* NBMetadataHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
5756
940725AF24BF79BE0011AE05 /* NBGeneratedShortNumberMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 940725AE24BF79BE0011AE05 /* NBGeneratedShortNumberMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; };
5857
940725B224BF7B040011AE05 /* NBShortNumberTestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 940725B124BF7B040011AE05 /* NBShortNumberTestHelper.m */; };
5958
940725B524BF90290011AE05 /* NBShortNumberMetadataHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 940725B324BF90290011AE05 /* NBShortNumberMetadataHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -503,7 +502,6 @@
503502
940725A924BE77420011AE05 /* NBShortNumberUtil.h in Headers */,
504503
9407259B24BE768A0011AE05 /* libPhoneNumberShortNumber.h in Headers */,
505504
940725AF24BF79BE0011AE05 /* NBGeneratedShortNumberMetadata.h in Headers */,
506-
940725AD24BF63500011AE05 /* NBMetadataHelper.h in Headers */,
507505
940725B524BF90290011AE05 /* NBShortNumberMetadataHelper.h in Headers */,
508506
);
509507
runOnlyForDeploymentPostprocessing = 0;

libPhoneNumber/Internal/NBRegularExpressionCache.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ - (NSRegularExpression *)regularExpressionForPattern:(NSString *)pattern error:(
4646
NSRegularExpression *regEx = [[NSRegularExpression alloc] initWithPattern:pattern
4747
options:kNilOptions
4848
error:&regExError];
49-
if (regEx == nil && error != nil) {
49+
if (regEx == nil) {
5050
if (error != NULL) {
5151
*error = regExError;
5252
}

libPhoneNumber/NBMetadataHelper.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ - (NSString *)countryCodeFromRegionCode:(NSString *)regionCode {
149149
* @param {?string} regionCode
150150
* @return {i18n.phonenumbers.PhoneMetadata}
151151
*/
152-
- (NBPhoneMetaData *)getMetadataForRegion:(NSString *)regionCode {
152+
- (NBPhoneMetaData * _Nullable)getMetadataForRegion:(NSString * _Nonnull)regionCode {
153153
regionCode = StringByTrimming(regionCode);
154154
if (regionCode.length == 0) {
155155
return nil;
@@ -178,12 +178,12 @@ - (NBPhoneMetaData *)getMetadataForRegion:(NSString *)regionCode {
178178
* @param countryCallingCode countryCallingCode
179179
* @return {i18n.phonenumbers.PhoneMetadata}
180180
*/
181-
- (NBPhoneMetaData *)getMetadataForNonGeographicalRegion:(NSNumber *)countryCallingCode {
181+
- (NBPhoneMetaData * _Nullable)getMetadataForNonGeographicalRegion:(NSNumber * _Nonnull)countryCallingCode {
182182
NSString *countryCallingCodeStr = countryCallingCode.stringValue;
183183
return [self getMetadataForRegion:countryCallingCodeStr];
184184
}
185185

186-
+ (BOOL)hasValue:(NSString *)string {
186+
+ (BOOL)hasValue:(NSString * _Nonnull)string {
187187
string = StringByTrimming(string);
188188
return string.length != 0;
189189
}

libPhoneNumber/NBPhoneNumberUtil.h

Lines changed: 118 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -13,126 +13,128 @@
1313

1414
@interface NBPhoneNumberUtil : NSObject
1515

16-
+ (NBPhoneNumberUtil *)sharedInstance;
17-
- (instancetype)initWithMetadataHelper:(NBMetadataHelper *)helper;
16+
+ (NBPhoneNumberUtil * _Nonnull)sharedInstance;
17+
- (instancetype _Nonnull)initWithMetadataHelper:(NBMetadataHelper * _Nonnull)helper;
1818

19-
- (instancetype)init NS_UNAVAILABLE;
19+
- (instancetype _Nonnull)init NS_UNAVAILABLE;
2020

21-
@property(nonatomic, strong, readonly) NSDictionary *DIGIT_MAPPINGS;
21+
@property(nonatomic, strong, readonly, nonnull) NSDictionary * DIGIT_MAPPINGS;
2222

2323
// regular expressions
24-
- (NSArray *)matchesByRegex:(NSString *)sourceString regex:(NSString *)pattern;
25-
- (NSArray *)matchedStringByRegex:(NSString *)sourceString regex:(NSString *)pattern;
26-
- (NSString *)replaceStringByRegex:(NSString *)sourceString
27-
regex:(NSString *)pattern
28-
withTemplate:(NSString *)templateString;
29-
- (int)stringPositionByRegex:(NSString *)sourceString regex:(NSString *)pattern;
24+
- (NSArray * _Nullable)matchesByRegex:(NSString * _Nonnull)sourceString regex:(NSString * _Nonnull)pattern;
25+
- (NSArray * _Nullable)matchedStringByRegex:(NSString * _Nonnull)sourceString regex:(NSString * _Nonnull)pattern;
26+
- (NSString * _Nonnull)replaceStringByRegex:(NSString * _Nonnull)sourceString
27+
regex:(NSString * _Nonnull)pattern
28+
withTemplate:(NSString * _Nonnull)templateString;
29+
- (int)stringPositionByRegex:(NSString * _Nullable)sourceString regex:(NSString * _Nullable)pattern;
3030

3131
// libPhoneNumber Util functions
32-
- (NSString *)convertAlphaCharactersInNumber:(NSString *)number;
33-
34-
- (NSString *)normalize:(NSString *)phoneNumber;
35-
- (NSString *)normalizeDigitsOnly:(NSString *)number;
36-
- (NSString *)normalizeDiallableCharsOnly:(NSString *)number;
37-
38-
- (BOOL)isNumberGeographical:(NBPhoneNumber *)phoneNumber;
39-
40-
- (NSString *)extractPossibleNumber:(NSString *)phoneNumber;
41-
- (NSNumber *)extractCountryCode:(NSString *)fullNumber nationalNumber:(NSString **)nationalNumber;
42-
- (NSString *)countryCodeByCarrier;
43-
44-
- (NSString *)getNddPrefixForRegion:(NSString *)regionCode stripNonDigits:(BOOL)stripNonDigits;
45-
- (NSString *)getNationalSignificantNumber:(NBPhoneNumber *)phoneNumber;
46-
47-
- (NSArray *)getSupportedRegions;
48-
49-
- (NBEPhoneNumberType)getNumberType:(NBPhoneNumber *)phoneNumber;
50-
51-
- (NSNumber *)getCountryCodeForRegion:(NSString *)regionCode;
52-
53-
- (NSString *)getRegionCodeForCountryCode:(NSNumber *)countryCallingCode;
54-
- (NSArray *)getRegionCodesForCountryCode:(NSNumber *)countryCallingCode;
55-
- (NSString *)getRegionCodeForNumber:(NBPhoneNumber *)phoneNumber;
56-
57-
- (NBPhoneNumber *)getExampleNumber:(NSString *)regionCode error:(NSError **)error;
58-
- (NBPhoneNumber *)getExampleNumberForType:(NSString *)regionCode
59-
type:(NBEPhoneNumberType)type
60-
error:(NSError **)error;
61-
- (NBPhoneNumber *)getExampleNumberForNonGeoEntity:(NSNumber *)countryCallingCode
62-
error:(NSError **)error;
63-
64-
- (BOOL)canBeInternationallyDialled:(NBPhoneNumber *)number error:(NSError **)error;
65-
66-
- (BOOL)truncateTooLongNumber:(NBPhoneNumber *)number;
67-
68-
- (BOOL)isValidNumber:(NBPhoneNumber *)number;
69-
- (BOOL)isViablePhoneNumber:(NSString *)phoneNumber;
70-
- (BOOL)isAlphaNumber:(NSString *)number;
71-
- (BOOL)isValidNumberForRegion:(NBPhoneNumber *)number regionCode:(NSString *)regionCode;
72-
- (BOOL)isNANPACountry:(NSString *)regionCode;
73-
- (BOOL)isLeadingZeroPossible:(NSNumber *)countryCallingCode;
74-
75-
- (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber *)number error:(NSError **)error;
76-
77-
- (BOOL)isPossibleNumber:(NBPhoneNumber *)number;
78-
- (BOOL)isPossibleNumber:(NBPhoneNumber *)number error:(NSError **)error;
79-
- (BOOL)isPossibleNumberString:(NSString *)number
80-
regionDialingFrom:(NSString *)regionDialingFrom
81-
error:(NSError **)error;
82-
83-
- (NBEMatchType)isNumberMatch:(id)firstNumberIn second:(id)secondNumberIn error:(NSError **)error;
84-
85-
- (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber *)phoneNumber error:(NSError **)error;
86-
- (int)getLengthOfNationalDestinationCode:(NBPhoneNumber *)phoneNumber error:(NSError **)error;
87-
88-
- (BOOL)maybeStripNationalPrefixAndCarrierCode:(NSString **)numberStr
89-
metadata:(NBPhoneMetaData *)metadata
90-
carrierCode:(NSString **)carrierCode;
91-
- (NBECountryCodeSource)maybeStripInternationalPrefixAndNormalize:(NSString **)numberStr
92-
possibleIddPrefix:(NSString *)possibleIddPrefix;
93-
94-
- (NSNumber *)maybeExtractCountryCode:(NSString *)number
95-
metadata:(NBPhoneMetaData *)defaultRegionMetadata
96-
nationalNumber:(NSString **)nationalNumber
97-
keepRawInput:(BOOL)keepRawInput
98-
phoneNumber:(NBPhoneNumber **)phoneNumber
99-
error:(NSError **)error;
100-
101-
- (NBPhoneNumber *)parse:(NSString *)numberToParse
102-
defaultRegion:(NSString *)defaultRegion
103-
error:(NSError **)error;
104-
- (NBPhoneNumber *)parseAndKeepRawInput:(NSString *)numberToParse
105-
defaultRegion:(NSString *)defaultRegion
106-
error:(NSError **)error;
107-
- (NBPhoneNumber *)parseWithPhoneCarrierRegion:(NSString *)numberToParse error:(NSError **)error;
108-
109-
- (NSString *)format:(NBPhoneNumber *)phoneNumber
110-
numberFormat:(NBEPhoneNumberFormat)numberFormat
111-
error:(NSError **)error;
112-
- (NSString *)formatByPattern:(NBPhoneNumber *)number
113-
numberFormat:(NBEPhoneNumberFormat)numberFormat
114-
userDefinedFormats:(NSArray *)userDefinedFormats
115-
error:(NSError **)error;
116-
- (NSString *)formatNumberForMobileDialing:(NBPhoneNumber *)number
117-
regionCallingFrom:(NSString *)regionCallingFrom
118-
withFormatting:(BOOL)withFormatting
119-
error:(NSError **)error;
120-
- (NSString *)formatOutOfCountryCallingNumber:(NBPhoneNumber *)number
121-
regionCallingFrom:(NSString *)regionCallingFrom
122-
error:(NSError **)error;
123-
- (NSString *)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber *)number
124-
regionCallingFrom:(NSString *)regionCallingFrom
125-
error:(NSError **)error;
126-
- (NSString *)formatNationalNumberWithCarrierCode:(NBPhoneNumber *)number
127-
carrierCode:(NSString *)carrierCode
128-
error:(NSError **)error;
129-
- (NSString *)formatInOriginalFormat:(NBPhoneNumber *)number
130-
regionCallingFrom:(NSString *)regionCallingFrom
131-
error:(NSError **)error;
132-
- (NSString *)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber *)number
133-
fallbackCarrierCode:(NSString *)fallbackCarrierCode
134-
error:(NSError **)error;
135-
- (BOOL)formattingRuleHasFirstGroupOnly:(NSString *)nationalPrefixFormattingRule;
32+
- (NSString * _Nonnull)convertAlphaCharactersInNumber:(NSString * _Nonnull)number;
33+
34+
- (NSString * _Nonnull)normalize:(NSString * _Nonnull)number;
35+
- (NSString * _Nonnull)normalizeDigitsOnly:(NSString * _Nonnull)number;
36+
- (NSString * _Nonnull)normalizeDiallableCharsOnly:(NSString * _Nonnull)number;
37+
38+
- (BOOL)isNumberGeographical:(NBPhoneNumber * _Nonnull)phoneNumber;
39+
40+
- (NSString * _Nonnull)extractPossibleNumber:(NSString * _Nonnull)number;
41+
- (NSNumber * _Nonnull)extractCountryCode:(NSString * _Nonnull)fullNumber nationalNumber:(NSString * _Nullable * _Nullable)nationalNumber;
42+
- (NSString * _Nonnull)countryCodeByCarrier;
43+
44+
- (NSString * _Nullable)getNddPrefixForRegion:(NSString * _Nullable)regionCode stripNonDigits:(BOOL)stripNonDigits;
45+
- (NSString * _Nonnull)getNationalSignificantNumber:(NBPhoneNumber * _Nonnull)phoneNumber;
46+
47+
- (NSArray * _Nullable)getSupportedRegions;
48+
49+
- (NBEPhoneNumberType)getNumberType:(NBPhoneNumber * _Nonnull)phoneNumber;
50+
51+
- (NSNumber * _Nonnull)getCountryCodeForRegion:(NSString * _Nullable)regionCode;
52+
53+
- (NSString * _Nonnull)getRegionCodeForCountryCode:(NSNumber * _Nonnull)countryCallingCode;
54+
- (NSArray * _Nullable)getRegionCodesForCountryCode:(NSNumber * _Nonnull)countryCallingCode;
55+
- (NSString * _Nullable)getRegionCodeForNumber:(NBPhoneNumber * _Nullable)phoneNumber;
56+
57+
- (NBPhoneNumber * _Nullable)getExampleNumber:(NSString * _Nonnull)regionCode error:(NSError * _Nullable __autoreleasing * _Nullable)error;
58+
- (NBPhoneNumber * _Nullable)getExampleNumberForType:(NSString * _Nonnull)regionCode
59+
type:(NBEPhoneNumberType)type
60+
error:(NSError * _Nullable __autoreleasing * _Nullable)error;
61+
- (NBPhoneNumber * _Nullable)getExampleNumberForNonGeoEntity:(NSNumber * _Nonnull)countryCallingCode
62+
error:(NSError * _Nullable * _Nullable)error;
63+
64+
- (BOOL)canBeInternationallyDialled:(NBPhoneNumber * _Nonnull)number error:(NSError * _Nullable * _Nullable)error;
65+
66+
- (BOOL)truncateTooLongNumber:(NBPhoneNumber * _Nonnull)number;
67+
68+
- (BOOL)isValidNumber:(NBPhoneNumber * _Nonnull)number;
69+
- (BOOL)isViablePhoneNumber:(NSString * _Nonnull)phoneNumber;
70+
- (BOOL)isAlphaNumber:(NSString * _Nonnull)number;
71+
- (BOOL)isValidNumberForRegion:(NBPhoneNumber * _Nonnull)number regionCode:(NSString * _Nonnull)regionCode;
72+
- (BOOL)isNANPACountry:(NSString * _Nullable)regionCode;
73+
- (BOOL)isLeadingZeroPossible:(NSNumber * _Nonnull)countryCallingCode;
74+
75+
- (NBEValidationResult)isPossibleNumberWithReason:(NBPhoneNumber * _Nonnull)number
76+
error:(NSError * _Nullable * _Nullable)error;
77+
78+
- (BOOL)isPossibleNumber:(NBPhoneNumber * _Nonnull)number;
79+
- (BOOL)isPossibleNumber:(NBPhoneNumber * _Nonnull)number error:(NSError * _Nullable * _Nullable)error;
80+
- (BOOL)isPossibleNumberString:(NSString * _Nonnull)number
81+
regionDialingFrom:(NSString * _Nullable)regionDialingFrom
82+
error:(NSError * _Nullable * _Nullable)error;
83+
84+
- (NBEMatchType)isNumberMatch:(id _Nonnull)firstNumberIn second:(id _Nonnull)secondNumberIn error:(NSError * _Nullable * _Nullable)error;
85+
86+
- (int)getLengthOfGeographicalAreaCode:(NBPhoneNumber * _Nonnull)phoneNumber error:(NSError * _Nullable * _Nullable)error;
87+
- (int)getLengthOfNationalDestinationCode:(NBPhoneNumber * _Nonnull)phoneNumber error:(NSError * _Nullable * _Nullable)error;
88+
89+
- (BOOL)maybeStripNationalPrefixAndCarrierCode:(NSString * _Nullable * _Nullable)number
90+
metadata:(NBPhoneMetaData * _Nonnull)metadata
91+
carrierCode:(NSString * _Nullable * _Nullable)carrierCode;
92+
- (NBECountryCodeSource)maybeStripInternationalPrefixAndNormalize:(NSString * _Nullable * _Nullable)numberStr
93+
possibleIddPrefix:(NSString * _Nonnull)possibleIddPrefix;
94+
95+
- (NSNumber * _Nonnull)maybeExtractCountryCode:(NSString * _Nonnull)number
96+
metadata:(NBPhoneMetaData * _Nullable)defaultRegionMetadata
97+
nationalNumber:(NSString * _Nullable * _Nullable)nationalNumber
98+
keepRawInput:(BOOL)keepRawInput
99+
phoneNumber:(NBPhoneNumber * _Nullable * _Nullable)phoneNumber
100+
error:(NSError * _Nullable * _Nullable)error;
101+
102+
- (NBPhoneNumber * _Nullable)parse:(NSString * _Nullable)numberToParse
103+
defaultRegion:(NSString * _Nullable)defaultRegion
104+
error:(NSError * _Nullable * _Nullable)error;
105+
- (NBPhoneNumber * _Nullable)parseAndKeepRawInput:(NSString * _Nonnull)numberToParse
106+
defaultRegion:(NSString * _Nullable)defaultRegion
107+
error:(NSError * _Nullable * _Nullable)error;
108+
- (NBPhoneNumber * _Nullable)parseWithPhoneCarrierRegion:(NSString * _Nullable)numberToParse
109+
error:(NSError * _Nullable * _Nullable)error;
110+
111+
- (NSString * _Nullable)format:(NBPhoneNumber * _Nonnull)phoneNumber
112+
numberFormat:(NBEPhoneNumberFormat)numberFormat
113+
error:(NSError * _Nullable * _Nullable)error;
114+
- (NSString * _Nullable)formatByPattern:(NBPhoneNumber * _Nonnull)number
115+
numberFormat:(NBEPhoneNumberFormat)numberFormat
116+
userDefinedFormats:(NSArray * _Nullable)userDefinedFormats
117+
error:(NSError * _Nullable * _Nullable)error;
118+
- (NSString * _Nullable)formatNumberForMobileDialing:(NBPhoneNumber * _Nonnull)number
119+
regionCallingFrom:(NSString * _Nonnull)regionCallingFrom
120+
withFormatting:(BOOL)withFormatting
121+
error:(NSError * _Nullable * _Nullable)error;
122+
- (NSString * _Nullable)formatOutOfCountryCallingNumber:(NBPhoneNumber * _Nonnull)number
123+
regionCallingFrom:(NSString * _Nonnull)regionCallingFrom
124+
error:(NSError * _Nullable * _Nullable)error;
125+
- (NSString * _Nullable)formatOutOfCountryKeepingAlphaChars:(NBPhoneNumber * _Nonnull)number
126+
regionCallingFrom:(NSString * _Nonnull)regionCallingFrom
127+
error:(NSError * _Nullable * _Nullable)error;
128+
- (NSString * _Nullable)formatNationalNumberWithCarrierCode:(NBPhoneNumber * _Nonnull)number
129+
carrierCode:(NSString * _Nullable)carrierCode
130+
error:(NSError * _Nullable * _Nullable)error;
131+
- (NSString * _Nullable)formatInOriginalFormat:(NBPhoneNumber * _Nonnull)number
132+
regionCallingFrom:(NSString * _Nonnull)regionCallingFrom
133+
error:(NSError * _Nullable * _Nullable)error;
134+
- (NSString * _Nullable)formatNationalNumberWithPreferredCarrierCode:(NBPhoneNumber * _Nonnull)number
135+
fallbackCarrierCode:(NSString * _Nonnull)fallbackCarrierCode
136+
error:(NSError * _Nullable * _Nullable)error;
137+
- (BOOL)formattingRuleHasFirstGroupOnly:(NSString * _Nullable)nationalPrefixFormattingRule;
136138

137139
/**
138140
* Returns the mobile token for the provided country calling code if it has one, otherwise
@@ -142,6 +144,7 @@
142144
* @param countryCallingCode the country calling code for which we want the mobile token.
143145
* @return the mobile token, as a string, for the given country calling code.
144146
*/
145-
- (NSString *)getCountryMobileTokenFromCountryCode:(NSInteger)countryCallingCode;
147+
- (NSString * _Nonnull)getCountryMobileTokenFromCountryCode:(NSInteger)countryCallingCode;
146148

147149
@end
150+

0 commit comments

Comments
 (0)