[ 
https://issues.apache.org/jira/browse/WEEX-540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16574683#comment-16574683
 ] 

ASF GitHub Bot commented on WEEX-540:
-------------------------------------

lucky-chen closed pull request #1376: [WEEX-540][iOS] parser type by reg
URL: https://github.com/apache/incubator-weex/pull/1376
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m 
b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
index cbc7354682..cb4903ace0 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
@@ -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();


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> [iOS]parse bundleType by RegularExpression
> ------------------------------------------
>
>                 Key: WEEX-540
>                 URL: https://issues.apache.org/jira/browse/WEEX-540
>             Project: Weex
>          Issue Type: Bug
>            Reporter: peihan
>            Assignee: Adam Feng
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to