mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Temp
This commit is contained in:
parent
a75bd17b6c
commit
f57d6b6168
8323 changed files with 4359 additions and 56254 deletions
|
|
@ -4,13 +4,6 @@ static_library(
|
|||
name = "PhoneNumberFormat",
|
||||
srcs = glob([
|
||||
"Sources/**/*.swift",
|
||||
"Sources/**/*.m",
|
||||
]),
|
||||
headers = glob([
|
||||
"Sources/**/*.h",
|
||||
]),
|
||||
exported_headers = glob([
|
||||
"Sources/**/*.h",
|
||||
]),
|
||||
deps = [
|
||||
"//submodules/libphonenumber:libphonenumber",
|
||||
|
|
|
|||
15
submodules/PhoneNumberFormat/BUILD
Normal file
15
submodules/PhoneNumberFormat/BUILD
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
|
||||
|
||||
swift_library(
|
||||
name = "PhoneNumberFormat",
|
||||
module_name = "PhoneNumberFormat",
|
||||
srcs = glob([
|
||||
"Sources/**/*.swift",
|
||||
]),
|
||||
deps = [
|
||||
"//submodules/libphonenumber:libphonenumber",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
)
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface FormatPhoneNumber : NSObject
|
||||
|
||||
+ (NSString *)cleanInternationalPhone:(NSString *)phone forceInternational:(bool)forceInternational;
|
||||
+ (NSString *)formatPhoneNumber:(NSString *)number;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
#import "FormatPhoneNumber.h"
|
||||
|
||||
#import <libphonenumber/libphonenumber.h>
|
||||
|
||||
static NBPhoneNumberUtil *getNBPhoneNumberUtil() {
|
||||
static NBPhoneNumberUtil *value;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
value = [[NBPhoneNumberUtil alloc] init];
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
@implementation FormatPhoneNumber
|
||||
|
||||
+ (NSString *)cleanInternationalPhone:(NSString *)phone forceInternational:(bool)forceInternational {
|
||||
if (phone.length == 0) {
|
||||
return @"";
|
||||
}
|
||||
|
||||
char buf[phone.length];
|
||||
int bufPtr = 0;
|
||||
|
||||
bool hadPlus = false;
|
||||
int length = (int)phone.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
unichar c = [phone characterAtIndex:i];
|
||||
if ((c >= '0' && c <= '9') || (c == '+' && !hadPlus)) {
|
||||
buf[bufPtr++] = (char)c;
|
||||
if (c == '+') {
|
||||
hadPlus = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSString *result = [[NSString alloc] initWithBytes:buf length:bufPtr encoding:NSUTF8StringEncoding];
|
||||
if (forceInternational && bufPtr != 0 && buf[0] != '+') {
|
||||
result = [[NSString alloc] initWithFormat:@"+%@", result];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+ (NSString *)formatPhoneNumber:(NSString *)number {
|
||||
NBPhoneNumber *parsed = [getNBPhoneNumberUtil() parse:[@"+" stringByAppendingString:number] defaultRegion:nil error:nil];
|
||||
if (parsed == nil) {
|
||||
return number;
|
||||
}
|
||||
NSString *result = [getNBPhoneNumberUtil() format:parsed numberFormat:NBEPhoneNumberFormatINTERNATIONAL error:nil];
|
||||
if (result == nil) {
|
||||
return number;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
Loading…
Add table
Add a link
Reference in a new issue