Skip to content
Open
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
23 changes: 21 additions & 2 deletions Reader/TextSearch/SearchManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ -(void)searchForTerm:(NSString*)term page:(NSUInteger)page {
});
}

-(BOOL)isSearchTermValid:(NSString*)term {
BOOL result = YES;

// Can run mutiple validations on the search term below

// Validate against searching single or multiple blank spaces
NSCharacterSet * notWhiteSpaceSet = [[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet];
NSRange rangeOfNonWhitespaceChars = [self.searchTerm rangeOfCharacterFromSet:notWhiteSpaceSet];
result = rangeOfNonWhitespaceChars.location != NSNotFound;

return result;
}

-(void)startSearch {

if(self.running) {
Expand All @@ -239,8 +252,14 @@ -(void)startSearch {
NSNotification * notification = [NSNotification notificationWithName:kNotificationSearchDidStart object:self userInfo:info];
[[NSNotificationCenter defaultCenter] postNotification:notification];

// Start the search
[self searchForTerm:self.searchTerm page:self.currentPage];
// Validate search term before searching
if([self isSearchTermValid: self.searchTerm]) {
// Start the search
[self searchForTerm:self.searchTerm page:self.currentPage];
} else {
[self stopSearch];
return;
}
}

#pragma mark - Lifecycle
Expand Down