@@ -160,21 +160,21 @@ + (void)qmuisafety_NSString {
160
160
161
161
// index 越界
162
162
{
163
- BOOL isValidddatedIndex = index <= selfObject.length ;
164
- if (!isValidddatedIndex ) {
163
+ BOOL isValidatedIndex = index <= selfObject.length ;
164
+ if (!isValidatedIndex ) {
165
165
NSString *logString = [NSString stringWithFormat: @" %@ 传入了一个超过字符串长度的 index: %@ ,原字符串为: %@ (%@ )" , NSStringFromSelector (originCMD), @(index), selfObject, @(selfObject.length)];
166
166
NSAssert (NO , logString);
167
167
QMUILogWarn (@" QMUIStringSafety" , @" %@ " , logString);
168
- return nil ;// 系统 substringFromIndex: 返回值的标志是 nonnull,但返回 nil 比返回 @"" 更安全
168
+ return @" " ;// 系统 substringFromIndex: 返回值的标志是 nonnull
169
169
}
170
170
}
171
171
172
172
// 保护从 emoji 等 ComposedCharacterSequence 中间裁剪的场景
173
173
{
174
174
if (index < selfObject.length ) {
175
175
NSRange range = [selfObject rangeOfComposedCharacterSequenceAtIndex: index];
176
- BOOL isValidddatedIndex = range.location == index || NSMaxRange (range) == index;
177
- if (!isValidddatedIndex ) {
176
+ BOOL isValidatedIndex = range.location == index || NSMaxRange (range) == index;
177
+ if (!isValidatedIndex ) {
178
178
NSString *logString = [NSString stringWithFormat: @" 试图在 ComposedCharacterSequence 中间用 %@ 裁剪字符串,可能导致乱码、crash。原字符串为“%@ ”(%@ ),index 为 %@ ,命中的 ComposedCharacterSequence range 为 %@ " , NSStringFromSelector (originCMD), selfObject, @(selfObject.length), @(index), NSStringFromRange (range)];
179
179
NSAssert (NO , logString);
180
180
QMUILogWarn (@" QMUIStringSafety" , @" %@ " , logString);
@@ -197,21 +197,21 @@ + (void)qmuisafety_NSString {
197
197
198
198
// index 越界
199
199
{
200
- BOOL isValidddatedIndex = index <= selfObject.length ;
201
- if (!isValidddatedIndex ) {
200
+ BOOL isValidatedIndex = index <= selfObject.length ;
201
+ if (!isValidatedIndex ) {
202
202
NSString *logString = [NSString stringWithFormat: @" %@ 传入了一个超过字符串长度的 index: %@ ,原字符串为: %@ (%@ )" , NSStringFromSelector (originCMD), @(index), selfObject, @(selfObject.length)];
203
203
NSAssert (NO , logString);
204
204
QMUILogWarn (@" QMUIStringSafety" , @" %@ " , logString);
205
- return nil ;// 系统 substringToIndex: 返回值的标志是 nonnull,但返回 nil 比返回 @"" 更安全
205
+ return @" " ;// 系统 substringToIndex: 返回值的标志是 nonnull,但返回 nil 比返回 @"" 更安全
206
206
}
207
207
}
208
208
209
209
// 保护从 emoji 等 ComposedCharacterSequence 中间裁剪的场景
210
210
{
211
211
if (index < selfObject.length ) {
212
212
NSRange range = [selfObject rangeOfComposedCharacterSequenceAtIndex: index];
213
- BOOL isValidddatedIndex = range.location == index;
214
- if (!isValidddatedIndex ) {
213
+ BOOL isValidatedIndex = range.location == index;
214
+ if (!isValidatedIndex ) {
215
215
NSString *logString = [NSString stringWithFormat: @" 试图在 ComposedCharacterSequence 中间用 %@ 裁剪字符串,可能导致乱码、crash。原字符串为“%@ ”(%@ ),index 为 %@ ,命中的 ComposedCharacterSequence range 为 %@ " , NSStringFromSelector (originCMD), selfObject, @(selfObject.length), @(index), NSStringFromRange (range)];
216
216
NSAssert (NO , logString);
217
217
QMUILogWarn (@" QMUIStringSafety" , @" %@ " , logString);
@@ -240,7 +240,7 @@ + (void)qmuisafety_NSString {
240
240
NSString *logString = [NSString stringWithFormat: @" %@ 传入了一个超过字符串长度的 range: %@ ,原字符串为: %@ (%@ )" , NSStringFromSelector (originCMD), NSStringFromRange (range), selfObject, @(selfObject.length)];
241
241
NSAssert (NO , logString);
242
242
QMUILogWarn (@" QMUIStringSafety" , @" %@ " , logString);
243
- return nil ;// 系统 substringWithRange: 返回值的标志是 nonnull,但返回 nil 比返回 @"" 更安全
243
+ return @" " ;// 系统 substringWithRange: 返回值的标志是 nonnull
244
244
}
245
245
}
246
246
0 commit comments