Browse Source

potentially wrong result when compare float with double: #142

ibireme 9 năm trước cách đây
mục cha
commit
4349259cb3

+ 1 - 1
Demo/YYTextDemo/NSString+YYAdd.h

@@ -119,7 +119,7 @@
  */
  */
 - (BOOL)containsEmoji;
 - (BOOL)containsEmoji;
 
 
-- (BOOL)containsEmojiForSystemVersion:(float)systemVersion;
+- (BOOL)containsEmojiForSystemVersion:(double)systemVersion;
 
 
 
 
 #pragma mark - Utilities
 #pragma mark - Utilities

+ 2 - 2
Demo/YYTextDemo/NSString+YYAdd.m

@@ -74,10 +74,10 @@
 }
 }
 
 
 - (BOOL)containsEmoji {
 - (BOOL)containsEmoji {
-    return [self containsEmojiForSystemVersion:[UIDevice currentDevice].systemVersion.floatValue];
+    return [self containsEmojiForSystemVersion:[UIDevice currentDevice].systemVersion.doubleValue];
 }
 }
 
 
-- (BOOL)containsEmojiForSystemVersion:(float)systemVersion {
+- (BOOL)containsEmojiForSystemVersion:(double)systemVersion {
     // If detected, it MUST contains emoji; otherwise it MAY not contains emoji.
     // If detected, it MUST contains emoji; otherwise it MAY not contains emoji.
     static NSMutableCharacterSet *minSet8_3, *minSetOld;
     static NSMutableCharacterSet *minSet8_3, *minSetOld;
     // If detected, it may contains emoji; otherwise it MUST NOT contains emoji.
     // If detected, it may contains emoji; otherwise it MUST NOT contains emoji.

+ 1 - 1
Demo/YYTextDemo/UIView+YYAdd.h

@@ -51,7 +51,7 @@
 @end
 @end
 
 
 
 
-float YYDeviceSystemVersion();
+double YYDeviceSystemVersion();
 
 
 #ifndef kSystemVersion
 #ifndef kSystemVersion
 #define kSystemVersion YYDeviceSystemVersion()
 #define kSystemVersion YYDeviceSystemVersion()

+ 3 - 3
Demo/YYTextDemo/UIView+YYAdd.m

@@ -139,11 +139,11 @@
 @end
 @end
 
 
 
 
-float YYDeviceSystemVersion() {
-    static float version;
+double YYDeviceSystemVersion() {
+    static double version;
     static dispatch_once_t onceToken;
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
     dispatch_once(&onceToken, ^{
-        version = [UIDevice currentDevice].systemVersion.floatValue;
+        version = [UIDevice currentDevice].systemVersion.doubleValue;
     });
     });
     return version;
     return version;
 }
 }

+ 3 - 3
YYText/Component/YYTextKeyboardManager.m

@@ -253,11 +253,11 @@ static int _YYTextKeyboardViewFrameObserverKey;
 
 
 #pragma mark - private
 #pragma mark - private
 
 
-- (CGFloat)_systemVersion {
-    static CGFloat v;
+- (double)_systemVersion {
+    static double v;
     static dispatch_once_t onceToken;
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
     dispatch_once(&onceToken, ^{
-        v = [UIDevice currentDevice].systemVersion.floatValue;
+        v = [UIDevice currentDevice].systemVersion.doubleValue;
     });
     });
     return v;
     return v;
 }
 }

+ 2 - 2
YYText/Component/YYTextLayout.m

@@ -384,8 +384,8 @@ dispatch_semaphore_signal(_lock);
     static BOOL needFixJoinedEmojiBug = NO;
     static BOOL needFixJoinedEmojiBug = NO;
     static dispatch_once_t onceToken;
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
     dispatch_once(&onceToken, ^{
-        CGFloat systemVersionFloat = [UIDevice currentDevice].systemVersion.floatValue;
-        if (8.3 <= systemVersionFloat && systemVersionFloat < 9) {
+        double systemVersionDouble = [UIDevice currentDevice].systemVersion.doubleValue;
+        if (8.3 <= systemVersionDouble && systemVersionDouble < 9) {
             needFixJoinedEmojiBug = YES;
             needFixJoinedEmojiBug = YES;
         }
         }
     });
     });

+ 3 - 3
YYText/String/YYTextAttribute.m

@@ -16,11 +16,11 @@
 #import "YYTextArchiver.h"
 #import "YYTextArchiver.h"
 
 
 
 
-static float _YYDeviceSystemVersion() {
-    static float version;
+static double _YYDeviceSystemVersion() {
+    static double version;
     static dispatch_once_t onceToken;
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
     dispatch_once(&onceToken, ^{
-        version = [UIDevice currentDevice].systemVersion.floatValue;
+        version = [UIDevice currentDevice].systemVersion.doubleValue;
     });
     });
     return version;
     return version;
 }
 }

+ 3 - 3
YYText/Utility/NSAttributedString+YYText.m

@@ -22,11 +22,11 @@
 @implementation NSAttributedString_YYText @end
 @implementation NSAttributedString_YYText @end
 
 
 
 
-static float _YYDeviceSystemVersion() {
-    static float version;
+static double _YYDeviceSystemVersion() {
+    static double version;
     static dispatch_once_t onceToken;
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
     dispatch_once(&onceToken, ^{
-        version = [UIDevice currentDevice].systemVersion.floatValue;
+        version = [UIDevice currentDevice].systemVersion.doubleValue;
     });
     });
     return version;
     return version;
 }
 }

+ 3 - 3
YYText/YYTextView.m

@@ -24,11 +24,11 @@
 #import "UIView+YYText.h"
 #import "UIView+YYText.h"
 
 
 
 
-static float _YYDeviceSystemVersion() {
-    static float version;
+static double _YYDeviceSystemVersion() {
+    static double version;
     static dispatch_once_t onceToken;
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
     dispatch_once(&onceToken, ^{
-        version = [UIDevice currentDevice].systemVersion.floatValue;
+        version = [UIDevice currentDevice].systemVersion.doubleValue;
     });
     });
     return version;
     return version;
 }
 }