[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [iOS] parser type by reg
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky-chen authored and cxfeng1 committed Jul 26, 2018
1 parent 988b99a commit 72422cb
Showing 1 changed file with 46 additions and 13 deletions.
59 changes: 46 additions & 13 deletions ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -634,27 +634,60 @@ - (NSString *)_pareJSBundleType:(NSString*)instanceIdString jsBundleString:(NSSt
if (!jsBundleString ) {
return bundleType;
}
if ([jsBundleString hasPrefix:@"// { \"framework\": \"Vue\""] || [jsBundleString hasPrefix:@"// { \"framework\": \"vue\""]) {
bundleType = @"Vue";
} else if ([jsBundleString hasPrefix:@"// { \"framework\": \"Rax\""] || [jsBundleString hasPrefix:@"// { \"framework\": \"rax\""] || [jsBundleString hasPrefix:@"// {\"framework\" : \"Rax\"}"] || [jsBundleString hasPrefix:@"// {\"framework\" : \"rax\"}"]) {
bundleType = @"Rax";
}else {
NSRegularExpression * regEx = [NSRegularExpression regularExpressionWithPattern:@"(use)(\\s+)(weex:vue)" options:NSRegularExpressionCaseInsensitive error:NULL];
if ( [self _isParserByRegEx]) {
NSRegularExpression * regEx = [NSRegularExpression regularExpressionWithPattern:@"^\\s*\\/\\/ *(\\{[^}]*\\}) *\\r?\\n" options:NSRegularExpressionCaseInsensitive error:NULL];
NSTextCheckingResult *match = [regEx firstMatchInString:jsBundleString options:0 range:NSMakeRange(0, jsBundleString.length)];
if (match) {
bundleType = [jsBundleString substringWithRange:match.range];
return bundleType;
NSString* bundleTypeStr = [jsBundleString substringWithRange:match.range];
bundleTypeStr = [bundleTypeStr stringByReplacingOccurrencesOfString:@"//" withString:@""];
id vale = [WXUtility objectFromJSON:bundleTypeStr];
bundleType = [vale objectForKey:@"framework"];
}else{
NSRegularExpression * regEx = [NSRegularExpression regularExpressionWithPattern:@"(use)(\\s+)(weex:vue)" options:NSRegularExpressionCaseInsensitive error:NULL];
NSTextCheckingResult *match = [regEx firstMatchInString:jsBundleString options:0 range:NSMakeRange(0, jsBundleString.length)];
if (match) {
bundleType = [jsBundleString substringWithRange:match.range];
return bundleType;
}
regEx = [NSRegularExpression regularExpressionWithPattern:@"(use)(\\s+)(weex:rax)" options:NSRegularExpressionCaseInsensitive error:NULL];
match = [regEx firstMatchInString:jsBundleString options:0 range:NSMakeRange(0, jsBundleString.length)];
if (match) {
bundleType = [jsBundleString substringWithRange:match.range];
}
}
regEx = [NSRegularExpression regularExpressionWithPattern:@"(use)(\\s+)(weex:rax)" options:NSRegularExpressionCaseInsensitive error:NULL];
match = [regEx firstMatchInString:jsBundleString options:0 range:NSMakeRange(0, jsBundleString.length)];
if (match) {
bundleType = [jsBundleString substringWithRange:match.range];
}else{
if ([jsBundleString hasPrefix:@"// { \"framework\": \"Vue\""] || [jsBundleString hasPrefix:@"// { \"framework\": \"vue\""]) {
bundleType = @"Vue";
} else if ([jsBundleString hasPrefix:@"// { \"framework\": \"Rax\""] || [jsBundleString hasPrefix:@"// { \"framework\": \"rax\""] || [jsBundleString hasPrefix:@"// {\"framework\" : \"Rax\"}"] || [jsBundleString hasPrefix:@"// {\"framework\" : \"rax\"}"]) {
bundleType = @"Rax";
}else {
NSRegularExpression * regEx = [NSRegularExpression regularExpressionWithPattern:@"(use)(\\s+)(weex:vue)" options:NSRegularExpressionCaseInsensitive error:NULL];
NSTextCheckingResult *match = [regEx firstMatchInString:jsBundleString options:0 range:NSMakeRange(0, jsBundleString.length)];
if (match) {
bundleType = [jsBundleString substringWithRange:match.range];
return bundleType;
}
regEx = [NSRegularExpression regularExpressionWithPattern:@"(use)(\\s+)(weex:rax)" options:NSRegularExpressionCaseInsensitive error:NULL];
match = [regEx firstMatchInString:jsBundleString options:0 range:NSMakeRange(0, jsBundleString.length)];
if (match) {
bundleType = [jsBundleString substringWithRange:match.range];
}
}
}

return bundleType;
}

- (bool)_isParserByRegEx
{
bool useRegEx = true;
id<WXConfigCenterProtocol> configCenter = [WXSDKEngine handlerForProtocol:@protocol(WXConfigCenterProtocol)];

if ([configCenter respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) {
useRegEx = [[configCenter configForKey:@"iOS_weex_ext_config.parserTypeByRegEx" defaultValue:@(YES) isDefault:NULL] boolValue];
}
return false;
}

- (void)destroyInstance:(NSString *)instance
{
WXAssertBridgeThread();
Expand Down

0 comments on commit 72422cb

Please sign in to comment.