Skip to content

Instantly share code, notes, and snippets.

@emonkak
Created July 4, 2023 07:30
Show Gist options
  • Save emonkak/d6f8334261adb4618c5879621a644dd5 to your computer and use it in GitHub Desktop.
Save emonkak/d6f8334261adb4618c5879621a644dd5 to your computer and use it in GitHub Desktop.
diff --git a/sources/NSStringITerm.m b/sources/NSStringITerm.m
index cd32c4ecf..ff996e611 100644
--- a/sources/NSStringITerm.m
+++ b/sources/NSStringITerm.m
@@ -47,6 +47,7 @@
#import <apr-1/apr_base64.h>
#import <Carbon/Carbon.h>
#import <wctype.h>
+#include <wchar.h>
@implementation NSString (iTerm)
@@ -57,17 +58,7 @@
+ (BOOL)isDoubleWidthCharacter:(int)unicode
ambiguousIsDoubleWidth:(BOOL)ambiguousIsDoubleWidth
unicodeVersion:(NSInteger)version {
- if (unicode <= 0xa0 ||
- (unicode > 0x452 && unicode < 0x1100)) {
- // Quickly cover the common cases.
- return NO;
- }
-
- if ([[NSCharacterSet fullWidthCharacterSetForUnicodeVersion:version] longCharacterIsMember:unicode]) {
- return YES;
- }
- if (ambiguousIsDoubleWidth &&
- [[NSCharacterSet ambiguousWidthCharacterSetForUnicodeVersion:version] longCharacterIsMember:unicode]) {
+ if (wcwidth(unicode) >= 2) {
return YES;
}
return NO;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment