Commit 71f0ca86 authored by Pierre's avatar Pierre

UTF8String doesn't map to a char * directly.

Fix crasher 4.
parent d773cda8
...@@ -29,18 +29,25 @@ static inline BOOL isDigit(char c) ...@@ -29,18 +29,25 @@ static inline BOOL isDigit(char c)
return c >= '0' && c <= '9'; return c >= '0' && c <= '9';
} }
// Shortcut to ease reading
static inline unichar c(NSString *string, unsigned index)
{
return [string characterAtIndex:index];
}
+ (BOOL)isTVShowEpisodeTitle:(NSString *)string + (BOOL)isTVShowEpisodeTitle:(NSString *)string
{ {
const char *str = [[string lowercaseString] UTF8String]; NSString *str = [string lowercaseString];
// Search for s01e10. // Search for s01e10.
for (unsigned i = 0; str[i]; i++) { for (int i = 0; i < (int)[str length] - 5; i++) {
if (str[i] == 's' && if (c(str, i) == 's' &&
isDigit(str[i+1]) && isDigit(c(str, i+1)) &&
isDigit(str[i+2]) && isDigit(c(str, i+2)) &&
str[i+3] == 'e' && c(str, i+3) == 'e' &&
isDigit(str[i+4]) && isDigit(c(str, i+4)) &&
isDigit(str[i+5])) isDigit(c(str, i+5)))
{ {
return YES; return YES;
} }
...@@ -62,21 +69,20 @@ static inline NSNumber *numberFromTwoChars(char high, char low) ...@@ -62,21 +69,20 @@ static inline NSNumber *numberFromTwoChars(char high, char low)
{ {
if (!string) if (!string)
return nil; return nil;
NSString *lowercaseString = [string lowercaseString]; NSString *str = [string lowercaseString];
const char *str = [string UTF8String];
// Search for s01e10. // Search for s01e10.
for (unsigned i = 0; str[i]; i++) { for (int i = 0; i < (int)[str length] - 5; i++) {
if (str[i] == 's' && if (c(str, i) == 's' &&
isDigit(str[i+1]) && isDigit(c(str, i+1)) &&
isDigit(str[i+2]) && isDigit(c(str, i+2)) &&
str[i+3] == 'e' && c(str, i+3) == 'e' &&
isDigit(str[i+4]) && isDigit(c(str, i+4)) &&
isDigit(str[i+5])) isDigit(c(str, i+5)))
{ {
NSNumber *season = numberFromTwoChars(str[i+1], str[i+2]); NSNumber *season = numberFromTwoChars(c(str,i+1), c(str,i+2));
NSNumber *episode = numberFromTwoChars(str[i+4], str[i+5]); NSNumber *episode = numberFromTwoChars(c(str,i+4), c(str,i+5));
NSString *tvShowName = i > 0 ? [lowercaseString substringToIndex:i-1] : nil; NSString *tvShowName = i > 0 ? [str substringToIndex:i-1] : nil;
tvShowName = tvShowName ? [[MLTitleDecrapifier decrapify:tvShowName] capitalizedString] : nil; tvShowName = tvShowName ? [[MLTitleDecrapifier decrapify:tvShowName] capitalizedString] : nil;
return [NSDictionary dictionaryWithObjectsAndKeys:season, @"season", episode, @"episode", tvShowName, @"tvShowName", nil]; return [NSDictionary dictionaryWithObjectsAndKeys:season, @"season", episode, @"episode", tvShowName, @"tvShowName", nil];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment