From eebdd769f9f467dd43b85fe8a2bf092fd5c850a7 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 28 Jan 2008 18:51:52 +0000 Subject: [PATCH] Monotone-Parent: 7140a5ceda022b61cef5ae79339b0dd6d915880b Monotone-Revision: 1321ce15584f6fd3efdfbca5f6c254254ef69476 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-01-28T18:51:52 Monotone-Branch: ca.inverse.sogo --- SOPE/NGCards/ChangeLog | 7 ++++ SOPE/NGCards/iCalRecurrenceRule.m | 55 ++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index b66b3e49d..8fd11bd86 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,5 +1,12 @@ 2008-01-28 Wolfgang Sourdeau + * iCalRecurrenceRule.m ([iCalRecurrenceRule + -weekDayFromICalRepresentation:_day]): issue an error whenever the + day cannot be deduced. Accept days notated with a prefix. + ([iCalRecurrenceRule -byDayMask]): don't strip the represented + day, feed it directly to weekDayFromICalRepresentation: since it + will do the correct syntax validation. + * iCalDailyRecurrenceCalculator.m ([iCalDailyRecurrenceCalculator -recurrenceRangesWithinCalendarDateRange:]): make use of << instead of exp2 to compute the mask. diff --git a/SOPE/NGCards/iCalRecurrenceRule.m b/SOPE/NGCards/iCalRecurrenceRule.m index bc4efc4cf..97fb294da 100644 --- a/SOPE/NGCards/iCalRecurrenceRule.m +++ b/SOPE/NGCards/iCalRecurrenceRule.m @@ -302,7 +302,6 @@ for (count = 0; count < max; count++) { day = [days objectAtIndex: count]; - day = [day substringFromIndex: [day length] - 2]; mask |= [self weekDayFromICalRepresentation: day]; } } @@ -331,27 +330,43 @@ - (iCalWeekDay) weekDayFromICalRepresentation: (NSString *) _day { - if ([_day length] > 1) { - /* be tolerant */ - unichar c0, c1; - - c0 = [_day characterAtIndex:0]; - if (c0 == 'm' || c0 == 'M') return iCalWeekDayMonday; - if (c0 == 'w' || c0 == 'W') return iCalWeekDayWednesday; - if (c0 == 'f' || c0 == 'F') return iCalWeekDayFriday; + NSString *day; + /* be tolerant */ + iCalWeekDay foundDay; + unichar chars[2]; - c1 = [_day characterAtIndex:1]; - if (c0 == 't' || c0 == 'T') { - if (c1 == 'u' || c1 == 'U') return iCalWeekDayTuesday; - if (c1 == 'h' || c1 == 'H') return iCalWeekDayThursday; - } - if (c0 == 's' || c0 == 'S') { - if (c1 == 'a' || c1 == 'A') return iCalWeekDaySaturday; - if (c1 == 'u' || c1 == 'U') return iCalWeekDaySunday; - } - } + foundDay = 0; - return -1; + if ([_day length] > 1) + { + [[_day uppercaseString] getCharacters: chars + range: NSMakeRange ([day length] - 2, 2)]; + + switch (chars[0]) + { + case 'M': foundDay = iCalWeekDayMonday; + break; + case 'W': foundDay = iCalWeekDayWednesday; + break; + case 'F': foundDay = iCalWeekDayFriday; + break; + case 'T': + if (chars[1] == 'U') + foundDay = iCalWeekDayTuesday; + else if (chars[1] == 'H') + foundDay = iCalWeekDayThursday; + case 'S': + if (chars[1] == 'A') + foundDay = iCalWeekDaySaturday; + else if (chars[1] == 'H') + foundDay = iCalWeekDaySunday; + } + } + + if (!foundDay) + [self errorWithFormat: @"wrong weekday representation: '%@'", _day]; + + return foundDay; // // TODO: do not raise but rather return an error value? // [NSException raise:NSGenericException // format:@"Incorrect weekDay '%@' specified!", _day];