@@ -50,28 +50,28 @@ func test(s: String) {
50
50
// --- constructing a String.Index from integer ---
51
51
52
52
let ix1 = String . Index ( encodedOffset: s. count) // GOOD
53
- let ix2 = String . Index ( encodedOffset: ns. length) // BAD: NSString length used in String.Index
54
- let ix3 = String . Index ( encodedOffset: s. utf8. count) // BAD: String.utf8 length used in String.Index
55
- let ix4 = String . Index ( encodedOffset: s. utf16. count) // BAD: String.utf16 length used in String.Index
56
- let ix5 = String . Index ( encodedOffset: s. unicodeScalars. count) // BAD: string.unicodeScalars length used in String.Index
53
+ let ix2 = String . Index ( encodedOffset: ns. length) // BAD: NSString length used in String.Index [NOT DETECTED]
54
+ let ix3 = String . Index ( encodedOffset: s. utf8. count) // BAD: String.utf8 length used in String.Index [NOT DETECTED]
55
+ let ix4 = String . Index ( encodedOffset: s. utf16. count) // BAD: String.utf16 length used in String.Index [NOT DETECTED]
56
+ let ix5 = String . Index ( encodedOffset: s. unicodeScalars. count) // BAD: string.unicodeScalars length used in String.Index [NOT DETECTED]
57
57
print ( " String.Index ' \( ix1. encodedOffset) ' / ' \( ix2. encodedOffset) ' ' \( ix3. encodedOffset) ' ' \( ix4. encodedOffset) ' ' \( ix5. encodedOffset) ' " )
58
58
59
59
let ix6 = s. index ( s. startIndex, offsetBy: s. count / 2 ) // GOOD
60
- let ix7 = s. index ( s. startIndex, offsetBy: ns. length / 2 ) // BAD: NSString length used in String.Index
60
+ let ix7 = s. index ( s. startIndex, offsetBy: ns. length / 2 ) // BAD: NSString length used in String.Index [NOT DETECTED]
61
61
print ( " index ' \( ix6. encodedOffset) ' / ' \( ix7. encodedOffset) ' " )
62
62
63
63
var ix8 = s. startIndex
64
64
s. formIndex ( & ix8, offsetBy: s. count / 2 ) // GOOD
65
65
var ix9 = s. startIndex
66
- s. formIndex ( & ix9, offsetBy: ns. length / 2 ) // BAD: NSString length used in String.Index
66
+ s. formIndex ( & ix9, offsetBy: ns. length / 2 ) // BAD: NSString length used in String.Index [NOT DETECTED]
67
67
print ( " formIndex ' \( ix8. encodedOffset) ' / ' \( ix9. encodedOffset) ' " )
68
68
69
69
// --- constructing an NSRange from integers ---
70
70
71
71
let range1 = NSMakeRange ( 0 , ns. length) // GOOD
72
72
let range2 = NSMakeRange ( 0 , s. count) // BAD: String length used in NSMakeRange
73
- let range3 = NSMakeRange ( 0 , s. reversed ( ) . count) // BAD: String length used in NSMakeRange
74
- let range4 = NSMakeRange ( 0 , s. distance ( from: s. startIndex, to: s. endIndex) ) // BAD: String length used in NSMakeRange
73
+ let range3 = NSMakeRange ( 0 , s. reversed ( ) . count) // BAD: String length used in NSMakeRange [NOT DETECTED]
74
+ let range4 = NSMakeRange ( 0 , s. distance ( from: s. startIndex, to: s. endIndex) ) // BAD: String length used in NSMakeRange [NOT DETECTED]
75
75
print ( " NSMakeRange ' \( range1. description) ' / ' \( range2. description) ' ' \( range3. description) ' ' \( range4. description) ' " )
76
76
77
77
let range5 = NSRange ( location: 0 , length: ns. length) // GOOD
@@ -81,43 +81,43 @@ func test(s: String) {
81
81
// --- String operations using an integer directly ---
82
82
83
83
let str1 = s. dropFirst ( s. count - 1 ) // GOOD
84
- let str2 = s. dropFirst ( ns. length - 1 ) // BAD: NSString length used in String
84
+ let str2 = s. dropFirst ( ns. length - 1 ) // BAD: NSString length used in String [NOT DETECTED]
85
85
print ( " dropFirst ' \( str1) ' / ' \( str2) ' " )
86
86
87
87
let str3 = s. dropLast ( s. count - 1 ) // GOOD
88
- let str4 = s. dropLast ( ns. length - 1 ) // BAD: NSString length used in String
88
+ let str4 = s. dropLast ( ns. length - 1 ) // BAD: NSString length used in String [NOT DETECTED]
89
89
print ( " dropLast ' \( str3) ' / ' \( str4) ' " )
90
90
91
91
let str5 = s. prefix ( s. count - 1 ) // GOOD
92
- let str6 = s. prefix ( ns. length - 1 ) // BAD: NSString length used in String
92
+ let str6 = s. prefix ( ns. length - 1 ) // BAD: NSString length used in String [NOT DETECTED]
93
93
print ( " prefix ' \( str5) ' / ' \( str6) ' " )
94
94
95
95
let str7 = s. suffix ( s. count - 1 ) // GOOD
96
- let str8 = s. suffix ( ns. length - 1 ) // BAD: NSString length used in String
96
+ let str8 = s. suffix ( ns. length - 1 ) // BAD: NSString length used in String [NOT DETECTED]
97
97
print ( " suffix ' \( str7) ' / ' \( str8) ' " )
98
98
99
99
let nstr1 = ns. character ( at: ns. length - 1 ) // GOOD
100
100
let nmstr1 = nms. character ( at: nms. length - 1 ) // GOOD
101
- let nstr2 = ns. character ( at: s. count - 1 ) // BAD: String length used in NSString
102
- let nmstr2 = nms. character ( at: s. count - 1 ) // BAD: String length used in NString
101
+ let nstr2 = ns. character ( at: s. count - 1 ) // BAD: String length used in NSString [NOT DETECTED]
102
+ let nmstr2 = nms. character ( at: s. count - 1 ) // BAD: String length used in NString [NOT DETECTED]
103
103
print ( " character ' \( nstr1) ' ' \( nmstr1) ' / ' \( nstr2) ' ' \( nmstr2) ' " )
104
104
105
105
let nstr3 = ns. substring ( from: ns. length - 1 ) // GOOD
106
106
let nmstr3 = nms. substring ( from: nms. length - 1 ) // GOOD
107
- let nstr4 = ns. substring ( from: s. count - 1 ) // BAD: String length used in NSString
108
- let nmstr4 = nms. substring ( from: s. count - 1 ) // BAD: String length used in NString
107
+ let nstr4 = ns. substring ( from: s. count - 1 ) // BAD: String length used in NSString [NOT DETECTED]
108
+ let nmstr4 = nms. substring ( from: s. count - 1 ) // BAD: String length used in NString [NOT DETECTED]
109
109
print ( " substring from ' \( nstr3) ' ' \( nmstr3) ' / ' \( nstr4) ' ' \( nmstr4) ' " )
110
110
111
111
let nstr5 = ns. substring ( to: ns. length - 1 ) // GOOD
112
112
let nmstr5 = nms. substring ( to: nms. length - 1 ) // GOOD
113
- let nstr6 = ns. substring ( to: s. count - 1 ) // BAD: String length used in NSString
114
- let nmstr6 = nms. substring ( to: s. count - 1 ) // BAD: String length used in NString
113
+ let nstr6 = ns. substring ( to: s. count - 1 ) // BAD: String length used in NSString [NOT DETECTED]
114
+ let nmstr6 = nms. substring ( to: s. count - 1 ) // BAD: String length used in NString [NOT DETECTED]
115
115
print ( " substring to ' \( nstr5) ' ' \( nmstr5) ' / ' \( nstr6) ' ' \( nmstr6) ' " )
116
116
117
117
let nmstr7 = NSMutableString ( string: s)
118
118
nmstr7. insert ( " * " , at: nms. length - 1 ) // GOOD
119
119
let nmstr8 = NSMutableString ( string: s)
120
- nmstr8. insert ( " * " , at: s. count - 1 ) // BAD: String length used in NSString
120
+ nmstr8. insert ( " * " , at: s. count - 1 ) // BAD: String length used in NSString [NOT DETECTED]
121
121
print ( " insert ' \( nmstr7) ' / ' \( nmstr8) ' " )
122
122
}
123
123
0 commit comments