Skip to content

Commit

Permalink
Merge pull request #164 from dpopov/master
Browse files Browse the repository at this point in the history
Upgrade to 4.0
  • Loading branch information
marmelroy authored Sep 19, 2017
2 parents ca80b76 + 4fb3da2 commit c672cf0
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 19 deletions.
26 changes: 23 additions & 3 deletions PhoneNumberKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Roy Marmelstein";
TargetAttributes = {
342418631BB6E5A000EE70E7 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
3424186D1BB6E5A000EE70E7 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
C6DF6C4A1D1B09CF00259F4B = {
CreatedOnToolsVersion = 7.3.1;
Expand Down Expand Up @@ -556,14 +556,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -609,14 +615,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -666,6 +678,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -687,6 +701,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -697,6 +713,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.PhoneNumberKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -708,6 +726,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.PhoneNumberKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -36,6 +37,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -36,6 +37,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -36,6 +37,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
6 changes: 3 additions & 3 deletions PhoneNumberKit/NSRegularExpression+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import Foundation
extension String {
func nsRange(from range: Range<String.Index>) -> NSRange {
let utf16view = self.utf16
let from = range.lowerBound.samePosition(in: utf16view)
let to = range.upperBound.samePosition(in: utf16view)
return NSMakeRange(utf16view.distance(from: utf16view.startIndex, to: from),
let from = range.lowerBound.samePosition(in: utf16view) ?? self.startIndex
let to = range.upperBound.samePosition(in: utf16view) ?? self.endIndex
return NSMakeRange(utf16view.distance(from: utf16view.startIndex, to: from),
utf16view.distance(from: from, to: to))
}

Expand Down
12 changes: 6 additions & 6 deletions PhoneNumberKit/PartialFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public final class PartialFormatter {
finalNumber.append(nationalNumber)
}
if finalNumber.characters.last == PhoneNumberConstants.separatorBeforeNationalNumber.characters.first {
finalNumber = finalNumber.substring(to: finalNumber.index(before: finalNumber.endIndex))
finalNumber = String(finalNumber[..<finalNumber.index(before: finalNumber.endIndex)])
}

return finalNumber
Expand Down Expand Up @@ -187,8 +187,8 @@ public final class PartialFormatter {
if let m = matches?.first {
let startCallingCode = m.characters.count
let index = rawNumber.characters.index(rawNumber.startIndex, offsetBy: startCallingCode)
processedNumber = rawNumber.substring(from: index)
prefixBeforeNationalNumber = rawNumber.substring(to: index)
processedNumber = String(rawNumber[index...])
prefixBeforeNationalNumber = String(rawNumber[..<index])
}
}
}
Expand Down Expand Up @@ -219,8 +219,8 @@ public final class PartialFormatter {
}
}
let index = rawNumber.characters.index(rawNumber.startIndex, offsetBy: startOfNationalNumber)
processedNumber = rawNumber.substring(from: index)
prefixBeforeNationalNumber.append(rawNumber.substring(to: index))
processedNumber = String(rawNumber[index...])
prefixBeforeNationalNumber.append(String(rawNumber[..<index]))
return processedNumber
}

Expand Down Expand Up @@ -374,7 +374,7 @@ public final class PartialFormatter {
}
if rebuiltIndex < rawNumber.characters.count {
let nationalCharacterIndex = rawNumber.characters.index(rawNumber.startIndex, offsetBy: rebuiltIndex)
let remainingNationalNumber: String = rawNumber.substring(from: nationalCharacterIndex)
let remainingNationalNumber: String = String(rawNumber[nationalCharacterIndex...])
rebuiltString.append(remainingNationalNumber)
}
rebuiltString = rebuiltString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
Expand Down
2 changes: 1 addition & 1 deletion PhoneNumberKit/PhoneNumberKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public final class PhoneNumberKit: NSObject {
///
/// - returns: optional array of ISO 639 compliant region codes.
public func countries(withCode countryCode: UInt64) -> [String]? {
let results = metadataManager.filterTerritories(byCode: countryCode)?.map{$0.codeID}.flatMap{$0}
let results = metadataManager.filterTerritories(byCode: countryCode)?.map{$0.codeID}
return results
}

Expand Down
4 changes: 2 additions & 2 deletions PhoneNumberKit/PhoneNumberParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ final class PhoneNumberParser {
let firstMatchString = number.substring(with: firstMatch.range)
let numOfGroups = firstMatch.numberOfRanges - 1
var transformedNumber: String = String()
let firstRange = firstMatch.rangeAt(numOfGroups)
let firstRange = firstMatch.range(at: numOfGroups)
let firstMatchStringWithGroup = (firstRange.location != NSNotFound && firstRange.location < number.characters.count) ? number.substring(with: firstRange): String()
let firstMatchStringWithGroupHasValue = regex.hasValue(firstMatchStringWithGroup)
if let transformRule = metadata.nationalPrefixTransformRule , firstMatchStringWithGroupHasValue == true {
transformedNumber = regex.replaceFirstStringByRegex(prefixPattern, string: number, templateString: transformRule)
}
else {
let index = number.index(number.startIndex, offsetBy: firstMatchString.characters.count)
transformedNumber = number.substring(from: index)
transformedNumber = String(number[index...])
}
if (regex.hasValue(nationalNumberRule) && regex.matchesEntirely(nationalNumberRule, string: number) && regex.matchesEntirely(nationalNumberRule, string: transformedNumber) == false){
return
Expand Down

0 comments on commit c672cf0

Please sign in to comment.