-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use nslibphonenumber * remove instrumented tests * update iOS deps
- Loading branch information
Showing
5 changed files
with
32 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ xcuserdata/ | |
Pods/ | ||
*.jks | ||
*yarn.lock | ||
*.podspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 9 additions & 8 deletions
17
library/src/iosMain/kotlin/com/chrisjenx/yakcov/RegexExt.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
package com.chrisjenx.yakcov | ||
|
||
import cocoapods.libPhoneNumber_iOS.NBPhoneNumberUtil | ||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import platform.Foundation.NSDataDetector | ||
import platform.Foundation.NSMakeRange | ||
import platform.Foundation.NSTextCheckingTypePhoneNumber | ||
import platform.Foundation.matchesInString | ||
|
||
|
||
/** | ||
* Check if is phone number to best ability of each platform. | ||
*/ | ||
@OptIn(ExperimentalForeignApi::class) | ||
actual fun String?.isPhoneNumber(defaultRegion: String?): Boolean { | ||
if (this.isNullOrBlank()) return false | ||
val detector = NSDataDetector(types = NSTextCheckingTypePhoneNumber, error = null) | ||
val range = NSMakeRange(0.toULong(), this.length.toULong()) | ||
val matches = detector.matchesInString(this, options = 0.toULong(), range = range) | ||
return matches.isNotEmpty() | ||
try { | ||
val phoneUtil = NBPhoneNumberUtil.sharedInstance() ?: return false | ||
val phoneNumber = phoneUtil.parse(this, defaultRegion, null) | ||
return phoneUtil.isValidNumberForRegion(phoneNumber, defaultRegion) | ||
} catch (e: Throwable) { | ||
return false | ||
} | ||
} |