Compare commits

..

No commits in common. "martin/init-improvement" and "master" have entirely different histories.

14 changed files with 5649 additions and 448 deletions

View File

@ -1,26 +0,0 @@
update_metadata: MetaDataPlistCreator/createPlistFromHeader
@echo "creating plist file..."
mv libPhoneNumber/NBGeneratedPhoneNumberMetaData.h MetaDataPlistCreator
(cd MetaDataPlistCreator && createPlistFromHeader)
mv MetaDataPlistCreator/phoneNumberMap.plist libPhoneNumber
rm MetaDataPlistCreator/NBGeneratedPhoneNumberMetaData.h
MetaDataPlistCreator/createPlistFromHeader: libPhoneNumber/NBGeneratedPhoneNumberMetaData.h
@echo "creating binary..."
cp libPhoneNumber/NBGeneratedPhoneNumberMetaData.h MetaDataPlistCreator
xcodebuild -target MetaDataPlistCreator
mv build/Release/createPlistFromHeader MetaDataPlistCreator
libPhoneNumber/NBGeneratedPhoneNumberMetaData.h:
@echo "creating temporary header file..."
cd libPhoneNumberTests && ./metadataGenerator
cd libPhoneNumber && ./GeneratePhoneNumberHeader.sh
clean:
@echo "deleting all temporary files..."
rm -f libPhoneNumber/NBGeneratedPhoneNumberMetaData.h
rm -f libPhoneNumber/phoneNumberMap.plist
rm -f MetaDataPlistCreator/NBGeneratedPhoneNumberMetaData.h
rm -f MetaDataPlistCreator/phoneNumberMap.plist
rm -f MetaDataPlistCreator/createPlistFromHeader
rm -rf build

View File

@ -1,20 +0,0 @@
//
// MetaDataPlistCreator.h
// MetaDataPlistCreator
//
// Created by Martin Böttcher on 09.02.22.
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
//
#ifndef MetaDataPlistCreator_h
#define MetaDataPlistCreator_h
#include <zlib.h>
@interface MetaDataPlistCreator : NSObject
+ (BOOL) createPlistFile:(NSString*) path;
@end
#endif /* MetaDataPlistCreator_h */

View File

@ -1,122 +0,0 @@
//
// MetaDataPlistCreator.m
// MetaDataPlistCreator
//
// Created by Martin Böttcher on 09.02.22.
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MetaDataPlistCreator.h"
#import "NBGeneratedPhoneNumberMetaData.h"
@implementation MetaDataPlistCreator: NSObject
+ (BOOL) createPlistFile:(NSString*) path {
NSDictionary *result = [MetaDataPlistCreator jsonObjectFromZippedDataWithBytes:kPhoneNumberMetaData
compressedLength:kPhoneNumberMetaDataCompressedLength
expandedLength:kPhoneNumberMetaDataExpandedLength];
// The jsonMap is large and held in memory.
// It's contents are deeply nested and very repetitive.
// We can greatly reduce the memory used by jsonMap
// by traversing its contents and de-duplicating repeated values.
result = [MetaDataPlistCreator deduplicateJsonMap:result];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:result requiringSecureCoding:NO error:NULL];
return data != nil && [data writeToFile:path atomically:YES];
}
+ (NSDictionary<NSObject *, NSObject *> *)deduplicateJsonMap:(NSDictionary<NSObject *, NSObject *> *)inputMap {
NSMutableSet<NSObject *> *valueSet = [NSMutableSet new];
NSObject *result = [self deduplicateJsonValue:inputMap valueSet:valueSet];
return (NSDictionary<NSObject *, NSObject *> *) result;
}
+ (NSObject *)deduplicateJsonValue:(NSObject *)jsonValue valueSet:(NSMutableSet<NSObject *> *)valueSet {
NSObject *_Nullable existingValue = [valueSet member:jsonValue];
if (existingValue != nil) {
assert([existingValue isKindOfClass:jsonValue.class]);
return existingValue;
} else {
[valueSet addObject:jsonValue];
}
if ([jsonValue isKindOfClass:NSArray.class]) {
return [self deduplicateJsonArray:(NSArray<NSObject *> *) jsonValue
valueSet:valueSet];
} else if ([jsonValue isKindOfClass:NSDictionary.class]) {
return [self deduplicateJsonDictionary:(NSDictionary<NSObject *, NSObject *> *) jsonValue
valueSet:valueSet];
} else if ([jsonValue isKindOfClass:NSString.class] ||
[jsonValue isKindOfClass:NSNumber.class] ||
[jsonValue isKindOfClass:NSData.class] ||
[jsonValue isKindOfClass:NSNull.class]) {
return jsonValue;
} else {
NSLog(@"Unexpected value: %@, %@", jsonValue.class, jsonValue);
return jsonValue;
}
}
+ (NSArray<NSObject *> *)deduplicateJsonArray:(NSArray<NSObject *> *)jsonArray
valueSet:(NSMutableSet<NSObject *> *)valueSet {
NSMutableArray<NSObject *> *result = [NSMutableArray new];
for (NSObject *jsonValue in jsonArray) {
[result addObject:[self deduplicateJsonValue:jsonValue valueSet:valueSet]];
}
return result;
}
+ (NSDictionary<NSObject *, NSObject *> *)deduplicateJsonDictionary:(NSDictionary<NSObject *, NSObject *> *)jsonDictionary
valueSet:(NSMutableSet<NSObject *> *)valueSet {
NSMutableDictionary<NSObject *, NSObject *> *result = [NSMutableDictionary new];
[jsonDictionary enumerateKeysAndObjectsUsingBlock:^(NSObject * _Nonnull jsonKey,
NSObject * _Nonnull jsonValue,
BOOL * _Nonnull stop) {
result[(id<NSCopying>) jsonKey] = [self deduplicateJsonValue:jsonValue valueSet:valueSet];
}];
return result;
}
/**
* Expand gzipped data into a JSON object.
* @param bytes Array<Bytef> of zipped data.
* @param compressedLength Length of the compressed bytes.
* @param expandedLength Length of the expanded bytes.
* @return JSON dictionary.
*/
+ (NSDictionary *)jsonObjectFromZippedDataWithBytes:(z_const Bytef [])bytes
compressedLength:(NSUInteger)compressedLength
expandedLength:(NSUInteger)expandedLength {
// Data is a gzipped JSON file that is embedded in the binary.
// See GeneratePhoneNumberHeader.sh and PhoneNumberMetaData.h for details.
NSMutableData* gunzippedData = [NSMutableData dataWithLength:expandedLength];
z_stream zStream;
memset(&zStream, 0, sizeof(zStream));
__attribute((unused)) int err = inflateInit2(&zStream, 16);
NSAssert(err == Z_OK, @"Unable to init stream. err = %d", err);
zStream.next_in = bytes;
zStream.avail_in = (uint)compressedLength;
zStream.next_out = (Bytef *)gunzippedData.bytes;
zStream.avail_out = (uint)gunzippedData.length;
err = inflate(&zStream, Z_FINISH);
NSAssert(err == Z_STREAM_END, @"Unable to inflate compressed data. err = %d", err);
err = inflateEnd(&zStream);
NSAssert(err == Z_OK, @"Unable to inflate compressed data. err = %d", err);
NSError *error = nil;
NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:gunzippedData
options:0
error:&error];
NSAssert(error == nil, @"Unable to convert JSON - %@", error);
return jsonObject;
}
@end

View File

@ -1,14 +0,0 @@
//
// main.m
// MetaDataPlistCreator
//
// Created by Martin Böttcher on 09.02.22.
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MetaDataPlistCreator.h"
int main(int argc, const char * argv[]) {
return [MetaDataPlistCreator createPlistFile:@"phoneNumberMap.plist"] ? 0 : 1;
}

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "libPhoneNumber-iOS"
s.version = "0.9.16"
s.version = "0.9.15"
s.summary = "iOS library for parsing, formatting, storing and validating international phone numbers from libphonenumber library."
s.description = <<-DESC
libPhoneNumber for iOS
@ -11,13 +11,12 @@ DESC
s.authors = { "iziz" => "zen.isis@gmail.com", "hyukhur" => "hyukhur@gmail.com" }
s.source = { :git => "https://github.com/iziz/libPhoneNumber-iOS.git", :tag => s.version.to_s }
s.libraries = 'z'
s.dependency 'CocoaLumberjack'
s.ios.framework = 'CoreTelephony'
s.ios.deployment_target = "11.0"
s.ios.deployment_target = "6.0"
s.osx.deployment_target = "10.9"
s.watchos.deployment_target = "2.0"
s.tvos.deployment_target = "9.0"
s.requires_arc = true
s.resources = 'libPhoneNumber/phoneNumberMap.plist'
s.source_files = 'libPhoneNumber/NBPhoneNumberDefines.{h,m}', 'libPhoneNumber/NBPhoneNumber.{h,m}', 'libPhoneNumber/NBNumberFormat.{h,m}', 'libPhoneNumber/NBPhoneNumberDesc.{h,m}', 'libPhoneNumber/NBPhoneMetaData.{h,m}', 'libPhoneNumber/NBPhoneNumberUtil.{h,m}', 'libPhoneNumber/NBMetadataHelper.{h,m}', 'libPhoneNumber/NBAsYouTypeFormatter.{h,m}', 'libPhoneNumber/NSArray+NBAdditions.{h,m}', 'libPhoneNumber/Internal/NBRegExMatcher.{h,m}', 'libPhoneNumber/Internal/NBRegularExpressionCache.{h,m}'
s.private_header_files = 'libPhoneNumber/NBGeneratedPhoneNumberMetaData.h'
s.source_files = 'libPhoneNumber/NBPhoneNumberDefines.{h,m}', 'libPhoneNumber/NBPhoneNumber.{h,m}', 'libPhoneNumber/NBNumberFormat.{h,m}', 'libPhoneNumber/NBPhoneNumberDesc.{h,m}', 'libPhoneNumber/NBPhoneMetaData.{h,m}', 'libPhoneNumber/NBPhoneNumberUtil.{h,m}', 'libPhoneNumber/NBMetadataHelper.{h,m}', 'libPhoneNumber/NBAsYouTypeFormatter.{h,m}', 'libPhoneNumber/NSArray+NBAdditions.{h,m}', 'libPhoneNumber/NBGeneratedPhoneNumberMetaData.h', 'libPhoneNumber/Internal/NBRegExMatcher.{h,m}', 'libPhoneNumber/Internal/NBRegularExpressionCache.{h,m}'
end

View File

@ -43,8 +43,6 @@
14B7A2B41DE9BF160051AED7 /* NBPhoneNumberDefines.m in Sources */ = {isa = PBXBuildFile; fileRef = A81D6A281BECC43A00F68F34 /* NBPhoneNumberDefines.m */; };
14B7A2B51DE9BF160051AED7 /* NBPhoneNumberUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = FD8B84321934C35F00C350EB /* NBPhoneNumberUtil.m */; };
14B7A2B61DE9BF160051AED7 /* NBAsYouTypeFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = FD8B84271934C35F00C350EB /* NBAsYouTypeFormatter.m */; };
14E06D5127B3DAFA007754F4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 14E06D5027B3DAFA007754F4 /* main.m */; };
14E06D5727B3DDF0007754F4 /* MetaDataPlistCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = 14E06D5627B3DDF0007754F4 /* MetaDataPlistCreator.m */; };
1F31D52E1DDD46B100257818 /* libPhoneNumberwatchOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F31D52C1DDD46B100257818 /* libPhoneNumberwatchOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F31D5321DDD46B900257818 /* NBMetadataHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FD12C2681A87401B00B53856 /* NBMetadataHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F31D5331DDD46BD00257818 /* NBMetadataHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = FD12C2691A87401B00B53856 /* NBMetadataHelper.m */; };
@ -133,6 +131,10 @@
8B1FEF9D1EB7BF6C00FBDE87 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD6AE8FA1BEE72B600263DE1 /* ViewController.swift */; };
8B1FEF9E1EB7BF7000FBDE87 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FD6AE8FC1BEE72B600263DE1 /* Main.storyboard */; };
8B1FEF9F1EB7BF7200FBDE87 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FD6AE9011BEE72B600263DE1 /* LaunchScreen.storyboard */; };
8B1FEFA01EB7BFC500FBDE87 /* NBGeneratedPhoneNumberMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BB73AA71E7C9C6700B0691B /* NBGeneratedPhoneNumberMetaData.h */; settings = {ATTRIBUTES = (Private, ); }; };
8B1FEFA11EB7BFC500FBDE87 /* NBGeneratedPhoneNumberMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BB73AA71E7C9C6700B0691B /* NBGeneratedPhoneNumberMetaData.h */; settings = {ATTRIBUTES = (Private, ); }; };
8B1FEFA21EB7BFC600FBDE87 /* NBGeneratedPhoneNumberMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BB73AA71E7C9C6700B0691B /* NBGeneratedPhoneNumberMetaData.h */; settings = {ATTRIBUTES = (Private, ); }; };
8B1FEFA31EB7BFC600FBDE87 /* NBGeneratedPhoneNumberMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BB73AA71E7C9C6700B0691B /* NBGeneratedPhoneNumberMetaData.h */; settings = {ATTRIBUTES = (Private, ); }; };
A025047D214C61FD00AFC260 /* NBPhoneNumberUtil+ShortNumberTestHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F5833091FD1FC9500F26ED4 /* NBPhoneNumberUtil+ShortNumberTestHelper.h */; };
A025047E214C61FD00AFC260 /* NBPhoneNumberUtil+ShortNumberTestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 0F58330A1FD1FC9500F26ED4 /* NBPhoneNumberUtil+ShortNumberTestHelper.m */; };
A81D6A2B1BECC44600F68F34 /* NBPhoneNumberDefines.m in Sources */ = {isa = PBXBuildFile; fileRef = A81D6A281BECC43A00F68F34 /* NBPhoneNumberDefines.m */; };
@ -148,18 +150,6 @@
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
14E06D4C27B3DAFA007754F4 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
0F2870911FCF7936006230BF /* NBPhoneNumberUtil+ShortNumber.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NBPhoneNumberUtil+ShortNumber.h"; sourceTree = "<group>"; };
0F2870921FCF7936006230BF /* NBPhoneNumberUtil+ShortNumber.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NBPhoneNumberUtil+ShortNumber.m"; sourceTree = "<group>"; };
@ -176,10 +166,6 @@
1485C5251E06F4890092F541 /* NBPhoneNumberUtilTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NBPhoneNumberUtilTest.m; path = libPhoneNumberTests/NBPhoneNumberUtilTest.m; sourceTree = SOURCE_ROOT; };
1485C52B1E06F4930092F541 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = libPhoneNumberTests/Info.plist; sourceTree = SOURCE_ROOT; };
14B7A2931DE9B65D0051AED7 /* libPhoneNumberiOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = libPhoneNumberiOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
14E06D4E27B3DAFA007754F4 /* createPlistFromHeader */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = createPlistFromHeader; sourceTree = BUILT_PRODUCTS_DIR; };
14E06D5027B3DAFA007754F4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
14E06D5527B3DDDB007754F4 /* MetaDataPlistCreator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MetaDataPlistCreator.h; sourceTree = "<group>"; };
14E06D5627B3DDF0007754F4 /* MetaDataPlistCreator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MetaDataPlistCreator.m; sourceTree = "<group>"; };
187A618A1A25DF04000D8BB6 /* PhoneNumberMetaData.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = PhoneNumberMetaData.json; path = libPhoneNumberTests/generatedJSON/PhoneNumberMetaData.json; sourceTree = SOURCE_ROOT; };
187A618B1A25DF04000D8BB6 /* PhoneNumberMetaDataForTesting.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = PhoneNumberMetaDataForTesting.json; path = libPhoneNumberTests/generatedJSON/PhoneNumberMetaDataForTesting.json; sourceTree = SOURCE_ROOT; };
1F31D52A1DDD46B100257818 /* libPhoneNumberwatchOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = libPhoneNumberwatchOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@ -243,13 +229,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
14E06D4B27B3DAFA007754F4 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
1F31D5261DDD46B100257818 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@ -369,17 +348,6 @@
name = libPhoneNumber.samples;
sourceTree = "<group>";
};
14E06D4F27B3DAFA007754F4 /* MetaDataPlistCreator */ = {
isa = PBXGroup;
children = (
8BB73AA71E7C9C6700B0691B /* NBGeneratedPhoneNumberMetaData.h */,
14E06D5027B3DAFA007754F4 /* main.m */,
14E06D5527B3DDDB007754F4 /* MetaDataPlistCreator.h */,
14E06D5627B3DDF0007754F4 /* MetaDataPlistCreator.m */,
);
path = MetaDataPlistCreator;
sourceTree = "<group>";
};
1F31D52B1DDD46B100257818 /* watchOS */ = {
isa = PBXGroup;
children = (
@ -447,7 +415,6 @@
14B7A2941DE9B65D0051AED7 /* libPhoneNumber.tests */,
14C114F11DE9A9070029FE1C /* libPhoneNumber.samples */,
4D43EF831740825100C24FF3 /* libPhoneNumber-iOS.podspec */,
14E06D4F27B3DAFA007754F4 /* MetaDataPlistCreator */,
FD7A061F167715A0004BBEB6 /* Frameworks */,
FD7A061D167715A0004BBEB6 /* Products */,
);
@ -462,7 +429,6 @@
14B7A2931DE9B65D0051AED7 /* libPhoneNumberiOSTests.xctest */,
7C72507C1E0EBE7D00F916ED /* libPhoneNumbermacOS.framework */,
8B1FEF731EB7BE7C00FBDE87 /* SwiftDemo.app */,
14E06D4E27B3DAFA007754F4 /* createPlistFromHeader */,
);
name = Products;
sourceTree = "<group>";
@ -508,6 +474,7 @@
children = (
FD12C2681A87401B00B53856 /* NBMetadataHelper.h */,
FD12C2691A87401B00B53856 /* NBMetadataHelper.m */,
8BB73AA71E7C9C6700B0691B /* NBGeneratedPhoneNumberMetaData.h */,
FD379E291A8AE5150015C184 /* NBPhoneNumberMetadata.plist */,
);
name = Metadata;
@ -520,6 +487,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
8B1FEFA11EB7BFC500FBDE87 /* NBGeneratedPhoneNumberMetaData.h in Headers */,
1F31D5461DDD478300257818 /* NBPhoneMetaData.h in Headers */,
1F31D5401DDD477300257818 /* NBPhoneNumber.h in Headers */,
1F31D5421DDD477800257818 /* NBNumberFormat.h in Headers */,
@ -539,6 +507,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
8B1FEFA21EB7BFC600FBDE87 /* NBGeneratedPhoneNumberMetaData.h in Headers */,
1F31D5511DDD47BA00257818 /* libPhoneNumbertvOS.h in Headers */,
1F31D5551DDD47EB00257818 /* NBMetadataHelper.h in Headers */,
1F31D5621DDD482C00257818 /* NBPhoneMetaData.h in Headers */,
@ -558,6 +527,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
8B1FEFA01EB7BFC500FBDE87 /* NBGeneratedPhoneNumberMetaData.h in Headers */,
A025047D214C61FD00AFC260 /* NBPhoneNumberUtil+ShortNumberTestHelper.h in Headers */,
0F2870981FCF8F13006230BF /* NBRegExMatcher.h in Headers */,
34ACBBB61B7124AB0064B3BD /* NBPhoneNumberDefines.h in Headers */,
@ -579,6 +549,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
8B1FEFA31EB7BFC600FBDE87 /* NBGeneratedPhoneNumberMetaData.h in Headers */,
7C7250801E0EBE7D00F916ED /* libPhoneNumbermacOS.h in Headers */,
7C72508E1E0EC05900F916ED /* NBMetadataHelper.h in Headers */,
7C7250941E0EC06900F916ED /* NBPhoneMetaData.h in Headers */,
@ -614,23 +585,6 @@
productReference = 14B7A2931DE9B65D0051AED7 /* libPhoneNumberiOSTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
14E06D4D27B3DAFA007754F4 /* MetaDataPlistCreator */ = {
isa = PBXNativeTarget;
buildConfigurationList = 14E06D5427B3DAFA007754F4 /* Build configuration list for PBXNativeTarget "MetaDataPlistCreator" */;
buildPhases = (
14E06D4A27B3DAFA007754F4 /* Sources */,
14E06D4B27B3DAFA007754F4 /* Frameworks */,
14E06D4C27B3DAFA007754F4 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = MetaDataPlistCreator;
productName = MetaDataPlistCreator;
productReference = 14E06D4E27B3DAFA007754F4 /* createPlistFromHeader */;
productType = "com.apple.product-type.tool";
};
1F31D5291DDD46B100257818 /* libPhoneNumberwatchOS */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1F31D5311DDD46B100257818 /* Build configuration list for PBXNativeTarget "libPhoneNumberwatchOS" */;
@ -736,10 +690,6 @@
CreatedOnToolsVersion = 8.1;
ProvisioningStyle = Automatic;
};
14E06D4D27B3DAFA007754F4 = {
CreatedOnToolsVersion = 13.2.1;
ProvisioningStyle = Automatic;
};
1F31D5291DDD46B100257818 = {
CreatedOnToolsVersion = 8.1;
ProvisioningStyle = Automatic;
@ -766,7 +716,6 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
Base,
);
mainGroup = FD7A0611167715A0004BBEB6;
@ -780,7 +729,6 @@
7C72507B1E0EBE7D00F916ED /* libPhoneNumbermacOS */,
14B7A2921DE9B65D0051AED7 /* libPhoneNumberiOSTests */,
8B1FEF721EB7BE7C00FBDE87 /* SwiftDemo */,
14E06D4D27B3DAFA007754F4 /* MetaDataPlistCreator */,
);
};
/* End PBXProject section */
@ -857,15 +805,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
14E06D4A27B3DAFA007754F4 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
14E06D5727B3DDF0007754F4 /* MetaDataPlistCreator.m in Sources */,
14E06D5127B3DAFA007754F4 /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
1F31D5251DDD46B100257818 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@ -1043,75 +982,6 @@
};
name = Release;
};
14E06D5227B3DAFA007754F4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_OPTIMIZATION_PROFILE_FILE = "";
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
INFOPLIST_KEY_WKRunsIndependentlyOfCompanionApp = YES;
INSTALL_PATH = .;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_NAME = createPlistFromHeader;
SDKROOT = macosx;
STRINGS_FILE_OUTPUT_ENCODING = "UTF-8";
TARGETED_DEVICE_FAMILY = "";
VALID_ARCHS = "arm64 x86_64";
};
name = Debug;
};
14E06D5327B3DAFA007754F4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_OPTIMIZATION_PROFILE_FILE = "";
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
INFOPLIST_KEY_WKRunsIndependentlyOfCompanionApp = YES;
INSTALL_PATH = .;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_NAME = createPlistFromHeader;
SDKROOT = macosx;
STRINGS_FILE_OUTPUT_ENCODING = "UTF-8";
TARGETED_DEVICE_FAMILY = "";
VALID_ARCHS = "arm64 x86_64";
};
name = Release;
};
1F31D52F1DDD46B100257818 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
@ -1610,15 +1480,6 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
14E06D5427B3DAFA007754F4 /* Build configuration list for PBXNativeTarget "MetaDataPlistCreator" */ = {
isa = XCConfigurationList;
buildConfigurations = (
14E06D5227B3DAFA007754F4 /* Debug */,
14E06D5327B3DAFA007754F4 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1F31D5311DDD46B100257818 /* Build configuration list for PBXNativeTarget "libPhoneNumberwatchOS" */ = {
isa = XCConfigurationList;
buildConfigurations = (

View File

@ -1,85 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1320"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "14E06D4D27B3DAFA007754F4"
BuildableName = "MetaDataPlistCreator"
BlueprintName = "MetaDataPlistCreator"
ReferencedContainer = "container:libPhoneNumber.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
disableMainThreadChecker = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "YES"
debugDocumentVersioning = "NO"
debugXPCServices = "NO"
debugServiceExtension = "internal"
enableGPUFrameCaptureMode = "3"
enableGPUValidationMode = "1"
allowLocationSimulation = "NO"
viewDebuggingEnabled = "No"
queueDebuggingEnabled = "No"
GPUProfilerEnabled = "No">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "14E06D4D27B3DAFA007754F4"
BuildableName = "MetaDataPlistCreator"
BlueprintName = "MetaDataPlistCreator"
ReferencedContainer = "container:libPhoneNumber.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "14E06D4D27B3DAFA007754F4"
BuildableName = "MetaDataPlistCreator"
BlueprintName = "MetaDataPlistCreator"
ReferencedContainer = "container:libPhoneNumber.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

File diff suppressed because it is too large Load Diff

View File

@ -7,15 +7,9 @@
//
#import "NBMetadataHelper.h"
#import "NBGeneratedPhoneNumberMetaData.h"
#import "NBPhoneMetaData.h"
#import <CocoaLumberjack/CocoaLumberjack.h>
#ifdef DEBUG
static const NSUInteger ddLogLevel = DDLogLevelAll;
#else
static const NSUInteger ddLogLevel = DDLogLevelInfo;
#endif
@interface NBMetadataHelper ()
// Cached metadata
@ -61,22 +55,15 @@ static NSString *StringByTrimming(NSString *aString) {
Ref. site (countrycode.org)
*/
+ (NSDictionary *)phoneNumberDataMap {
static NSDictionary *result;
static NSDictionary *phoneNumberDataDictionary;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@autoreleasepool {
NSString *path = [[NSBundle bundleForClass:NBMetadataHelper.class] pathForResource:@"phoneNumberMap" ofType:@"plist"];
NSData *fileContent = [NSData dataWithContentsOfFile:path];
if (fileContent != nil) {
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:fileContent];
unarchiver.requiresSecureCoding = YES;
NSSet *allowedClasses = [NSSet setWithArray:@[NSArray.class, NSDictionary.class, NSNull.class, NSString.class, NSNumber.class]];
result = (NSDictionary *)[unarchiver decodeObjectOfClasses:allowedClasses forKey:NSKeyedArchiveRootObjectKey];
}
NSAssert(result != nil, @"phoneNumberMap.plist missing or corrupt");
}
phoneNumberDataDictionary =
[self jsonObjectFromZippedDataWithBytes:kPhoneNumberMetaData
compressedLength:kPhoneNumberMetaDataCompressedLength
expandedLength:kPhoneNumberMetaDataExpandedLength];
});
return result;
return phoneNumberDataDictionary;
}
+ (NSDictionary *)CCode2CNMap {
@ -236,4 +223,45 @@ static NSString *StringByTrimming(NSString *aString) {
#endif // SHORT_NUMBER_SUPPORT
/**
* Expand gzipped data into a JSON object.
* @param bytes Array<Bytef> of zipped data.
* @param compressedLength Length of the compressed bytes.
* @param expandedLength Length of the expanded bytes.
* @return JSON dictionary.
*/
+ (NSDictionary *)jsonObjectFromZippedDataWithBytes:(z_const Bytef [])bytes
compressedLength:(NSUInteger)compressedLength
expandedLength:(NSUInteger)expandedLength {
// Data is a gzipped JSON file that is embedded in the binary.
// See GeneratePhoneNumberHeader.sh and PhoneNumberMetaData.h for details.
NSMutableData* gunzippedData = [NSMutableData dataWithLength:expandedLength];
z_stream zStream;
memset(&zStream, 0, sizeof(zStream));
__attribute((unused)) int err = inflateInit2(&zStream, 16);
NSAssert(err == Z_OK, @"Unable to init stream. err = %d", err);
zStream.next_in = bytes;
zStream.avail_in = (uint)compressedLength;
zStream.next_out = (Bytef *)gunzippedData.bytes;
zStream.avail_out = (uint)gunzippedData.length;
err = inflate(&zStream, Z_FINISH);
NSAssert(err == Z_STREAM_END, @"Unable to inflate compressed data. err = %d", err);
err = inflateEnd(&zStream);
NSAssert(err == Z_OK, @"Unable to inflate compressed data. err = %d", err);
NSError *error = nil;
NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:gunzippedData
options:0
error:&error];
NSAssert(error == nil, @"Unable to convert JSON - %@", error);
return jsonObject;
}
@end

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -60,7 +60,7 @@ func loadJS(from url: URL, to context: JSContext) {
let context = JSContext()!
context.exceptionHandler = { _, exception in
fputs("Javascript exception thrown: \(exception!)\n", __stderrp)
exit(1)
// exit(1)
}
// Load required dependencies.
@ -68,11 +68,25 @@ let googleClosure = URL(
string: "http://cdn.rawgit.com/google/closure-library/master/closure/goog/base.js")!
loadJS(from: googleClosure, to: context)
let jQuery = URL(string: "http://code.jquery.com/jquery-1.8.3.min.js")!
loadJS(from: jQuery, to: context)
// Evaluate requires.
let requires = """
goog.require('goog.proto2.Message');
goog.require('goog.dom');
goog.require('goog.json');
goog.require('goog.array');
goog.require('goog.proto2.ObjectSerializer');
goog.require('goog.string.StringBuffer');
goog.require('i18n.phonenumbers.metadata');
"""
context.evaluateScript(requires)
// Load metadata file from GitHub.
let ref = "master"
let phoneMetadata = URL(string: "https://raw.githubusercontent.com/google/libphonenumber/\(ref)/javascript/i18n/phonenumbers/metadata.js")!
let phoneMetadataForTesting = URL(string: "https://raw.githubusercontent.com/google/libphonenumber/\(ref)/javascript/i18n/phonenumbers/metadatafortesting.js")!
let shortNumberMetadata = URL(string: "https://raw.githubusercontent.com/google/libphonenumber/\(ref)/javascript/i18n/phonenumbers/shortnumbermetadata.js")!
let phoneMetadata = URL(string: "https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/metadata.js")!
let phoneMetadataForTesting = URL(string: "https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/metadatafortesting.js")!
let shortNumberMetadata = URL(string: "https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/shortnumbermetadata.js")!
let currentDir = FileManager.default.currentDirectoryPath
let baseURL = URL(fileURLWithPath: currentDir).appendingPathComponent("generatedJSON")