From 1eaa5ab2949572d822646d6e0b718b173a74d7e6 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Sun, 25 Feb 2024 00:52:04 +0800 Subject: [PATCH] fix: check isEnglishWord method is wrong --- Easydict/Feature/Service/Apple/EZAppleService.m | 2 +- .../EZCategory/NSString/NSString+EZUtils.h | 1 + .../EZCategory/NSString/NSString+EZUtils.m | 15 +++++---------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Easydict/Feature/Service/Apple/EZAppleService.m b/Easydict/Feature/Service/Apple/EZAppleService.m index e2a681b15..cfad04389 100644 --- a/Easydict/Feature/Service/Apple/EZAppleService.m +++ b/Easydict/Feature/Service/Apple/EZAppleService.m @@ -752,7 +752,7 @@ - (EZLanguage)getMostConfidentLanguage:(NSDictionary *)d } } } - NSLog(@"Spell check failed, use Most Confident Language: %@", ezLanguage); + NSLog(@"No spell checking, use Most Confident Language: %@", ezLanguage); return ezLanguage; } diff --git a/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZUtils.h b/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZUtils.h index cea96945c..90f3965ab 100644 --- a/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZUtils.h +++ b/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZUtils.h @@ -58,6 +58,7 @@ static NSArray *const EZDashCharacterList = @[ @"—", @"-", @"–" ]; - (BOOL)isEnglishWordWithLanguage:(EZLanguage)language; +/// Just use regex to check English word, ^[a-zA-Z]+$ - (BOOL)isEnglishWord; - (BOOL)isEnglishWordWithMaxWordLength:(NSUInteger)maxWordLength; diff --git a/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZUtils.m b/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZUtils.m index 5a119c5df..9494781fe 100644 --- a/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZUtils.m +++ b/Easydict/Feature/Utility/EZCategory/NSString/NSString+EZUtils.m @@ -246,16 +246,11 @@ - (BOOL)isEnglishWordWithMaxWordLength:(NSUInteger)maxWordLength { } - (BOOL)isEnglishPhrase { - if (self.length > EZEnglishWordMaxLength) { - return NO; - } - - NSInteger wordCount = [self wordCount]; - if (wordCount <= 2) { - return YES; - } - - return NO; + // hello word + NSString *text = [self stringByReplacingOccurrencesOfString:@" " withString:@""]; + BOOL isEnglishPhraseLength = [text isEnglishWordWithMaxWordLength:EZEnglishWordMaxLength * 2]; + BOOL isPhraseWordCount = [self wordCount] <= 2; + return isEnglishPhraseLength && isPhraseWordCount; } - (BOOL)isWord {