Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Sources/DictionaryKit/TTTDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
// THE SOFTWARE.

#import "TTTDictionary.h"
#include <CoreFoundation/CFArray.h>
#include <CoreFoundation/CFBase.h>

#import <CoreServices/CoreServices.h>

Expand Down Expand Up @@ -180,6 +182,24 @@ - (NSArray *)entriesForSearchTerm:(NSString *)term {
return [NSArray arrayWithArray:mutableEntries];
}

- (BOOL)containsSearchTerm:(nonnull NSString *)term {
CFRange termRange = DCSGetTermRangeInString(self.dictionary, (__bridge CFStringRef)term, 0);
if (termRange.location == kCFNotFound) {
return NO;
}

term = [term substringWithRange:NSMakeRange(termRange.location, termRange.length)];

CFArrayRef records = DCSCopyRecordsForSearchString(self.dictionary, (__bridge CFStringRef)term, NULL, NULL);
BOOL hasRecords = records && CFArrayGetCount(records) > 0;

if (records) {
CFRelease(records);
}

return hasRecords;
}

#pragma mark - NSObject

- (BOOL)isEqual:(id)object {
Expand Down
1 change: 1 addition & 0 deletions Sources/DictionaryKit/include/TTTDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
+ (nonnull NSSet<TTTDictionary *> *)availableDictionaries;
+ (nullable instancetype)dictionaryNamed:(nonnull NSString *)name;
- (nonnull NSArray<TTTDictionaryEntry *> *)entriesForSearchTerm:(nonnull NSString *)term;
- (BOOL)containsSearchTerm:(nonnull NSString *)term NS_SWIFT_NAME(contains(searchTerm:));

@end

Expand Down