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)
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
{
const char *str = [[string lowercaseString] UTF8String];
NSString *str = [string lowercaseString];
// Search for s01e10.
for (unsigned i = 0; str[i]; i++) {
if (str[i] == 's' &&
isDigit(str[i+1]) &&
isDigit(str[i+2]) &&
str[i+3] == 'e' &&
isDigit(str[i+4]) &&
isDigit(str[i+5]))
for (int i = 0; i < (int)[str length] - 5; i++) {
if (c(str, i) == 's' &&
isDigit(c(str, i+1)) &&
isDigit(c(str, i+2)) &&
c(str, i+3) == 'e' &&
isDigit(c(str, i+4)) &&
isDigit(c(str, i+5)))
{
return YES;
}
......@@ -62,21 +69,20 @@ static inline NSNumber *numberFromTwoChars(char high, char low)
{
if (!string)
return nil;
NSString *lowercaseString = [string lowercaseString];
const char *str = [string UTF8String];
NSString *str = [string lowercaseString];
// Search for s01e10.
for (unsigned i = 0; str[i]; i++) {
if (str[i] == 's' &&
isDigit(str[i+1]) &&
isDigit(str[i+2]) &&
str[i+3] == 'e' &&
isDigit(str[i+4]) &&
isDigit(str[i+5]))
for (int i = 0; i < (int)[str length] - 5; i++) {
if (c(str, i) == 's' &&
isDigit(c(str, i+1)) &&
isDigit(c(str, i+2)) &&
c(str, i+3) == 'e' &&
isDigit(c(str, i+4)) &&
isDigit(c(str, i+5)))
{
NSNumber *season = numberFromTwoChars(str[i+1], str[i+2]);
NSNumber *episode = numberFromTwoChars(str[i+4], str[i+5]);
NSString *tvShowName = i > 0 ? [lowercaseString substringToIndex:i-1] : nil;
NSNumber *season = numberFromTwoChars(c(str,i+1), c(str,i+2));
NSNumber *episode = numberFromTwoChars(c(str,i+4), c(str,i+5));
NSString *tvShowName = i > 0 ? [str substringToIndex:i-1] : nil;
tvShowName = tvShowName ? [[MLTitleDecrapifier decrapify:tvShowName] capitalizedString] : 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