cocoapods-privacy 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba881a65811e8640597663d499127914a78678976913fcb8352e873a1760dbda
4
- data.tar.gz: 4fb771e904d423d13f4a188451ace0b4adca4f0683d3d0ce2230c56aa2948fda
3
+ metadata.gz: e8c5e00e8a3993c8a37fb069dd5368c1f1bfe5a6b03797c8731785c4ad785683
4
+ data.tar.gz: 0aa6ad38e3325f17d55274d3677d80f9ee6cddf29222e3ca56463291229aa167
5
5
  SHA512:
6
- metadata.gz: b714abed735826938d267bb5c8a16e28a01ae9a470cebb4725627adc6aeb8ad3b0b078b858cff7c16e3e33c0545e7d2303bb8a6855614bc7c6aacfcfc7cc457d
7
- data.tar.gz: d1fc4f2e8ea3846969a6854cab16bf5eaf7468bbb085ab7e2ddcb566b6ac1eb4f320fbc42de60aad392804a9131b6183f5075ad1f35ec6f4acdbf47557a46060
6
+ metadata.gz: 91368971e928be9c4661b0c0924f2bf77e418ef275d4aaca91daf67ce4cb510306cc9833ecf434d5e3cf72ff965dd1d2be08d72f6ba6362e2a3e20a4260e2cf3
7
+ data.tar.gz: ffc0431386fe1e142678ea8874b84f7a3580c3061d58d6ceb0bc799d9154c0c310899d09c50284e5fea26e224150685c2f063be98da1d259e08f24056968e215
@@ -185,7 +185,6 @@ module Confuse
185
185
  # # 将注解内容按逗号分割功能,并去重
186
186
  commands = match.first.split(',').map(&:strip)
187
187
  commands.map do |commandInfo|
188
- puts commandInfo
189
188
  commandKeyAndValue = commandInfo.split(':')
190
189
  commandKey = commandKeyAndValue.first
191
190
  commandValue = commandKeyAndValue.last
@@ -193,22 +192,24 @@ module Confuse
193
192
  swift_extension = commandValue
194
193
  end
195
194
  end
196
-
197
- # new_parts = encrypted_api(apis)
198
-
199
- # apis.each_with_index do |seg, index|
200
- # apis_define_map[seg.strip] = new_parts[index]
201
- # end
202
-
203
- # puts "__attribute__ = #{match}"
204
195
  end
205
196
 
206
197
  # 查找并处理注解:__attribute__((annotate("xxx")))
207
- # @regex = /^[+-]\s*\(\s*([^$]+)\s*\**\s*\)\s*(.+)/
208
- line_scrub.scan(/(^[-+]\s*\(.*?\)\s*(\w+)\s*([\w\s]+))\s*__attribute__\(\(annotate\(/) do |match|
198
+ # ^ 匹配行首 + (BOOL)
199
+ # [-+] 匹配 + - 符号(ObjC 方法声明开头) +
200
+ # \s* 匹配 0 个或多个空白字符 空格
201
+ # \([\w\s\*]+\) 匹配一对圆括号里的类型声明,含字母、空格、* 指针符 (BOOL) / (NSString *)
202
+ # \s* 匹配 0 个或多个空白字符 空格
203
+ # (\w+) 捕获组 1:匹配方法名(只匹配到冒号前) uxxx_BB_Confuse_BBMUserCenter
204
+ # \s* 匹配 0 个或多个空白字符 空格
205
+ # (.*?) 捕获组 2:匹配“方法声明后到 __attribute__ 前的所有内容”,但用非贪婪方式,遇到 __attribute__ 就停 :(NSString *)name tip:(BOOL)ret
206
+ # \s*__attribute__\(\(annotate\( 匹配固定字符串 __att
207
+ regular = ConfuseUtils.oc_func_regular(line_scrub,false)
208
+ if regular
209
+ regular = /#{regular}\s*__attribute__\(\(annotate\(/
210
+ line_scrub.scan(regular) do |match|
209
211
  apis = [match.second]
210
212
  new_parts = encrypted_api(apis)
211
-
212
213
  funcStr = match.first.sub(';','').sub(/__attribute__\(\(annotate\(["][^"]*["]\)\)\).*/, '')
213
214
  swift_method_declaration,params = ObjCMethodAPIConverter.convert(funcStr)
214
215
  if !swift_extension.empty? && swift_method_declaration && !swift_method_declaration.empty?
@@ -219,6 +220,7 @@ module Confuse
219
220
  apis.each_with_index do |seg, index|
220
221
  apis_define_map[seg.strip] = new_parts[index]
221
222
  end
223
+ end
222
224
  end
223
225
 
224
226
  ###----- 处理swift 类 ------
@@ -281,10 +283,17 @@ module Confuse
281
283
  if line_scrub.strip.start_with?(confuse_func_pre_literal)
282
284
  #BBConfuseMixObjc("#selector(abcdefg(in:sencName:))"); asdasagwtrqwetr
283
285
 
284
-
285
286
  #selector(.*?)\)
286
287
  #解析带参数的
287
- # line_scrub.gsub!(/#{confuse_func_pre_literal}\(#selector\((.*?)\)\)\);(?:.*?@objc\((\S+)\))?(?:.*?@objc\s*)?/) do |match|
288
+ # | 部分 | 作用 | 举例 |
289
+ # |:-------------------------|:------------------------------------------------|:---------------------------------|
290
+ # | `#{confuse_func_pre_literal}\(` | 匹配你之前定义好的前缀字串(比如 `confuseMethod(`)和一个 `(` | `confuseMethod(` |
291
+ # | `(?:#selector\((.*?)\)\))?` | **非捕获组**,匹配 `#selector(XXX)`,括号内的 `XXX` 放进 `捕获组1` | `#selector(someMethod)` |
292
+ # | `(?:"([^"]*:[^"]*)")?` | **可选**,匹配 `:"xxx:xxx"` 格式的字符串,放进 `捕获组2` | `"abc:def"` |
293
+ # | `\);` | 匹配 `);` |
294
+ # | `(?:.*?@objc\((\S+)\))?` | **非捕获组**,可选,匹配 `@objc(XXX)`,把 `XXX` 放进 `捕获组3` | `@objc(mySelector)` |
295
+ # | `(?:.*?@objc\s*)?` | **非捕获组**,可选,匹配剩下一个 `@objc` 没括号的情况 | `@objc` |
296
+
288
297
  line_scrub.gsub!(/#{confuse_func_pre_literal}\((?:#selector\((.*?)\)\))?(?:"([^"]*:[^"]*)")?\);(?:.*?@objc\((\S+)\))?(?:.*?@objc\s*)?/) do |match|
289
298
  modified = true
290
299
  selector_match = $1
@@ -302,9 +311,15 @@ module Confuse
302
311
  end
303
312
 
304
313
  #解析不带参数的
305
- # line_scrub.gsub!(/#{confuse_func_pre_literal}\(#selector\(([^\(]+)\)\);(?:.*?@objc\((\S+)\))?(?:.*?@objc\s*)?/) do |match|
314
+ # | 部分 | 作用 | 举例 |
315
+ # |:-------------------------------|:--------------------------------------------------|:--------------------------|
316
+ # | `#{confuse_func_pre_literal}\(` | 匹配你的宏/方法名前缀 + `(`,比如 `confuseMethod(` | `confuseMethod(` |
317
+ # | `(?:#selector\(([^\(]+)\))?` | **非捕获组**,可选。匹配 `#selector(...)` 里的内容,放进 `捕获组1`,这里用 `([^\(]+)` 匹配**非左括号字符**,直到遇到 `)` | `#selector(doSomething)` → `doSomething` |
318
+ # | `(?:"([^":]+)")?` | **可选**,匹配 `"xxx"`,但里面不能有 `:` 或 `"`,放进 `捕获组2`。注意这版里不再要求冒号存在,单纯匹配一段字符串 | `"helloWorld"` |
319
+ # | `\);` | 匹配 `);` 结尾 |
320
+ # | `(?:.*?@objc\((\S+)\))?` | **非捕获组**,可选。匹配 `@objc(XXX)`,把 `XXX` 放进 `捕获组3`。`(\S+)` 匹配非空白连续字符 | `@objc(doSomethingElse)` |
321
+ # | `(?:.*?@objc\s*)?` | **非捕获组**,可选。匹配剩下没括号的 `@objc` | `@objc` |
306
322
  line_scrub.gsub!(/#{confuse_func_pre_literal}\((?:#selector\(([^\(]+)\))?(?:"([^":]+)")?\);(?:.*?@objc\((\S+)\))?(?:.*?@objc\s*)?/) do |match|
307
- # line_scrub.gsub!(/#{confuse_func_pre_literal}\((#selector\((.*?)\)|"([^"]+)")\);(?:.*?@objc\((\S+)\))?(?:.*?@objc\s*)?/) do |match|
308
323
  modified = true
309
324
  selector_match = $1
310
325
  str_match = $2
@@ -18,7 +18,6 @@ module ConfuseUtils
18
18
  # xcode工程地址
19
19
  def self.project_path
20
20
  matching_files = Dir[File.join(Pathname.pwd, '*.xcodeproj')].uniq
21
- puts "matching_files = #{matching_files}"
22
21
  matching_files.first
23
22
  end
24
23
 
@@ -104,4 +103,64 @@ module ConfuseUtils
104
103
  "#{spaces}#{str}"
105
104
  end
106
105
 
106
+ def self.oc_func_regular(str,isCapture = false)
107
+ if str =~ /^[-+]\s*\(.*?\)/ #为函数
108
+ num = match_nesting_parentheses_first(str)
109
+ if isBlockReturn(str) === true #block 返回参数函数
110
+ if num > 1
111
+ regular = oc_block_regular(num - 1,isCapture)
112
+ regular = /(^[-+]#{regular}(\w+)\s*(.+))/
113
+ return regular
114
+ end
115
+ else
116
+ regular = oc_normal_regular(num - 1,isCapture)
117
+ regular = /(^[-+]#{regular}(\w+)\s*(.+))/
118
+ return regular
119
+ end
120
+ end
121
+ return nil
122
+ end
123
+
124
+ def self.match_nesting_parentheses_first(str)
125
+ stack = []
126
+ count = 0
127
+
128
+ str.each_char.with_index do |char, idx|
129
+ if char == '('
130
+ stack.push(idx) # 记录左括号的位置
131
+ elsif char == ')'
132
+ count += 1
133
+ stack.pop # 弹出左括号位置
134
+ if stack.empty?
135
+ return count
136
+ end
137
+ end
138
+ end
139
+ 0 # 如果没有匹配到指定数量的括号对,返回 nil
140
+ end
141
+
142
+ def self.isBlockReturn(str)
143
+ if str =~ /^[-+]\s*\(([^)]*\^.+?)\)/ #block 返回参数函数
144
+ return true
145
+ else
146
+ return false
147
+ end
148
+ end
149
+
150
+ def self.oc_block_regular(num,isCapture = false)
151
+ if isCapture == false
152
+ "\\s*\\((?:[^\\)]+\\)){#{num}}.*?\\)\\s*"
153
+ else
154
+ "\\s*\\(((?:[^\\)]+\\)){#{num}}.*?)\\)\\s*"
155
+ end
156
+ end
157
+
158
+ def self.oc_normal_regular(num,isCapture = false)
159
+ if isCapture == false
160
+ "\\s*\\(.*?\\)\\s*"
161
+ else
162
+ "\\s*\\((.*?)\\)\\s*"
163
+ end
164
+ end
165
+
107
166
  end
@@ -3,7 +3,9 @@ module Confuse
3
3
  class ObjCMethodAPIConverter
4
4
  # Regular expression to match Objective-C method declarations
5
5
  # def initialize
6
- @regex = /^[+-]\s*\(\s*([\w\s*]+)\s*\**\s*\)\s*(.+)/
6
+
7
+ # @blockRegex = /#{ConfuseUtils.oc_block_regular}/
8
+ # @regex = /#{ConfuseUtils.noneBlock}/
7
9
  @param_regex = /(\w+):\s*\(([^:]+)\)(\w+)/x
8
10
  # end
9
11
 
@@ -16,15 +18,17 @@ module Confuse
16
18
  is_static = objc_method_declaration.start_with?("+")
17
19
  preFuncDes = is_static ? "static " : ""
18
20
 
19
-
21
+ regular = ConfuseUtils.oc_func_regular(objc_method_declaration,true)
20
22
  # Match the method declaration using the regex
21
- matches = objc_method_declaration.match(@regex)
23
+ matches = objc_method_declaration.match(regular)
22
24
  return nil,nil unless matches
23
25
 
24
26
  # Extract components from the matched regex groups
25
- return_type = matches[1] || "Void"
26
- param_section = matches[2] || ""
27
- method_name = matches[2]
27
+ return_type = matches[2] || "Void"
28
+ method_name = matches[3]
29
+ param_section = (matches[3] + (matches[4] || "")) || ""
30
+ # puts "matches = #{matches}"
31
+ # puts "objc_method_declaration = #{objc_method_declaration}"
28
32
  # puts "return_type = #{return_type}"
29
33
  # puts "param_section = #{param_section}"
30
34
  # puts "method_name = #{method_name}"
@@ -35,7 +39,6 @@ module Confuse
35
39
  # Extract parameters from the method declaration
36
40
  params = extract_parameters(param_section)
37
41
  method_name = extract_methodName(param_section,method_name)
38
- # puts "params = #{params}"
39
42
 
40
43
  # Construct the Swift method declaration
41
44
  swift_method_declaration = "#{preFuncDes}public func #{method_name}(#{params.join(', ')})"
@@ -153,7 +156,7 @@ module Confuse
153
156
  break
154
157
  end
155
158
  end
156
- method_name
159
+ method_name.strip
157
160
  end
158
161
 
159
162
 
@@ -163,7 +166,6 @@ module Confuse
163
166
  # puts convert_block_to_closure('NSString *(^)(NSInteger)') # 输出: (Int) -> String?
164
167
  # puts convert_block_to_closure('void (^)(NSInteger, BOOL)') # 输出: (Int, Bool) -> Void
165
168
  def self.convert_block_to_closure(block_signature)
166
-
167
169
  # 正则表达式解释:
168
170
  # ^([\w\s\*]+)\s*\(\^\)\s*(?:\((.*?)\))?\s*$
169
171
  # 1. ([\w\s\*]+): 捕获返回值类型(如 void、NSInteger、NSString * 等)。
@@ -1,3 +1,3 @@
1
1
  module CocoapodsPrivacy
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-privacy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - youhui