Guest User

Untitled

a guest
Feb 13th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. //
  2. // AggregateWarning.swift
  3. //
  4. // Created by nanashiki on 2018/01/31.
  5. // Copyright Β© 2018εΉ΄ nanashiki. All rights reserved.
  6. //
  7. import Foundation
  8.  
  9. extension String {
  10. func match(_ pattern : String,options:NSRegularExpression.Options = []) -> String?{
  11. return Regexp(pattern,options:options).match(self,at: 1)
  12. }
  13.  
  14. func matches(_ pattern : String,options:NSRegularExpression.Options = []) -> [[String]]?{
  15. return Regexp(pattern,options:options).matches(self)
  16. }
  17. }
  18.  
  19. public struct Regexp{
  20. let pattern : String
  21. var options : NSRegularExpression.Options
  22.  
  23. init(_ pattern:String,options:NSRegularExpression.Options = []) {
  24. self.pattern = pattern
  25. self.options = options
  26. }
  27.  
  28. func matches(_ string : String)->[[String]]?{
  29. do{
  30. let results = try NSRegularExpression(pattern: pattern, options: options).matches(in: string, options: .reportProgress, range: NSMakeRange(0,string.count))
  31. var dats : [[String]] = [];
  32. for result in results {
  33. var datss :[String] = []
  34. for j in 1 ..< result.numberOfRanges {
  35. datss.append((string as NSString).substring(with: result.range(at: j)))
  36. }
  37. dats += [datss]
  38. }
  39. return dats
  40.  
  41. }catch{
  42. return nil
  43. }
  44. }
  45.  
  46. func match(_ string : String,at : Int)->String?{
  47. do{
  48. let dat = try NSRegularExpression(pattern: pattern, options: options).matches(in: string, options: .reportProgress, range: NSMakeRange(0,string.count))
  49.  
  50. if dat.count == 0 {
  51. return nil
  52. }
  53.  
  54. return (string as NSString).substring(with: dat[0].range(at: at))
  55. }catch{
  56. return nil
  57. }
  58. }
  59. }
  60.  
  61. let arguments = CommandLine.arguments
  62. if arguments.count < 2 {
  63. print("Not enough arguments")
  64. exit(-1)
  65. }
  66. let path = arguments[1]
  67. var str = ""
  68. do {
  69. str = try String(contentsOfFile: path)
  70. } catch {
  71. print(error.localizedDescription)
  72. exit(-2)
  73. }
  74. let arr = str.matches("/(.+) warning: (.+)\n") ?? [[]]
  75.  
  76. var deprecatedDic = [String:Int]()
  77. var othersDic = [String:Int]()
  78.  
  79. var dCount = 0
  80. var oCount = 0
  81.  
  82. arr.forEach {
  83. item in
  84. if let deprecated = item[1].match("'(.+)' is deprecated") {
  85. if let count = deprecatedDic[deprecated] {
  86. deprecatedDic[deprecated] = count + 1
  87. } else {
  88. deprecatedDic[deprecated] = 1
  89. }
  90. dCount = dCount + 1
  91. return
  92. }
  93.  
  94. if let deprecated = item[1].match("'(.+)' was deprecated") {
  95. if let count = deprecatedDic[deprecated] {
  96. deprecatedDic[deprecated] = count + 1
  97. } else {
  98. deprecatedDic[deprecated] = 1
  99. }
  100. dCount = dCount + 1
  101. return
  102. }
  103.  
  104. if let count = othersDic[item[1]] {
  105. othersDic[item[1]] = count + 1
  106. } else {
  107. othersDic[item[1]] = 1
  108. }
  109. oCount = oCount + 1
  110. }
  111.  
  112. let deprecatedArr = deprecatedDic.sorted{ $0.value > $1.value }
  113. let othersArr = othersDic.sorted{ $0.value > $1.value }
  114.  
  115. print("| deprecated | count |")
  116. print("| --- | --- |")
  117. deprecatedArr.forEach {
  118. arg in
  119. print("| \(arg.key) | \(String(arg.value)) |")
  120. }
  121. print("")
  122.  
  123. print("| others | count |")
  124. print("| --- | --- |")
  125.  
  126. othersArr.forEach {
  127. arg in
  128. print("| \(arg.key) | \(String(arg.value)) |")
  129. }
  130. print("")
  131.  
  132.  
  133. print("| type | count |")
  134. print("| --- | --- |")
  135. print("| deprecated | \(String(dCount)) |")
  136. print("| others | \(String(oCount)) |")
  137. print("| sum | \(String(arr.count)) |")
  138. print("")
  139.  
  140. exit(0)
Add Comment
Please, Sign In to add comment