847
switch (format[formatIdx])
851
if (sourceIdx < sourceLen)
853
if (source[sourceIdx] != '%')
881
while (formatIdx < formatLen && isdigit(format[formatIdx]))
883
formatIdx++; // skip field width
885
if (formatIdx < formatLen)
887
switch (format[formatIdx])
891
if (sourceIdx < sourceLen)
893
if (source[sourceIdx] != '%')
897
@"Expected literal '%%' but got '%c' parsing"
898
@"'%@' using '%@'", source[sourceIdx],
857
@"Expected literal '%%' but got '%c' parsing"
907
@"Expected literal '%%' but got end of string parsing"
858
908
@"'%@' using '%@'", source[sourceIdx],
859
909
description, fmt);
867
@"Expected literal '%%' but got end of string parsing"
868
@"'%@' using '%@'", source[sourceIdx],
874
/* FIXME ... Should look for all values from the locale,
875
* matching for longest values first, rather than (wrongly)
876
* assuming a fixed length of three characters.
878
tmpStr[0] = toupper(source[sourceIdx]);
879
if (sourceIdx < sourceLen)
881
tmpStr[1] = tolower(source[sourceIdx]);
882
if (sourceIdx < sourceLen)
884
tmpStr[2] = tolower(source[sourceIdx]);
885
if (sourceIdx < sourceLen)
892
currDay = [[NSString alloc] initWithCString: tmpStr];
893
dayNames = [locale objectForKey: NSShortWeekDayNameArray];
894
for (tmpIdx = 0; tmpIdx < 7; tmpIdx++)
896
if ([[dayNames objectAtIndex: tmpIdx] isEqual:
905
NSDebugMLog(@"Day of week '%@' not found in locale",
918
/* FIXME ... Should look for all values from the locale,
919
* matching for longest values first, rather than (wrongly)
920
* assuming the name contains only western letters.
922
tmpEnd = sizeof(tmpStr) - 1;
923
if (sourceLen - sourceIdx < tmpEnd)
925
tmpEnd = sourceLen - sourceIdx;
927
for (tmpIdx = 0; tmpIdx < tmpEnd; tmpIdx++)
929
if (isalpha(source[sourceIdx + tmpIdx]))
931
tmpStr[tmpIdx] = source[sourceIdx + tmpIdx];
938
tmpStr[tmpIdx] = '\0';
944
currDay = [[NSString alloc] initWithCString: tmpStr];
945
dayNames = [locale objectForKey: NSWeekDayNameArray];
946
for (tmpIdx = 0; tmpIdx < 7; tmpIdx++)
948
if ([[dayNames objectAtIndex: tmpIdx] isEqual:
957
NSDebugMLog(@"Day of week '%@' not found in locale",
970
/* FIXME ... Should look for all values from the locale,
971
* matching for longest values first, rather than (wrongly)
972
* assuming a fixed length of three characters.
974
tmpStr[0] = toupper(source[sourceIdx]);
975
if (sourceIdx < sourceLen)
977
tmpStr[1] = tolower(source[sourceIdx]);
978
if (sourceIdx < sourceLen)
980
tmpStr[2] = tolower(source[sourceIdx]);
981
if (sourceIdx < sourceLen)
988
currMonth = [[NSString alloc] initWithCString: tmpStr];
989
monthNames = [locale objectForKey: NSShortMonthNameArray];
991
for (tmpIdx = 0; tmpIdx < 12; tmpIdx++)
993
if ([[monthNames objectAtIndex: tmpIdx]
994
isEqual: currMonth] == YES)
1002
NSDebugMLog(@"Month of year '%@' not found in locale",
1015
/* FIXME ... Should look for all values from the locale,
1016
* matching for longest values first, rather than (wrongly)
1017
* assuming the name contains only western letters.
1019
tmpEnd = sizeof(tmpStr) - 1;
1020
if (sourceLen - sourceIdx < tmpEnd)
1022
tmpEnd = sourceLen - sourceIdx;
1024
for (tmpIdx = 0; tmpIdx < tmpEnd; tmpIdx++)
1026
if (isalpha(source[sourceIdx + tmpIdx]))
1028
tmpStr[tmpIdx] = source[sourceIdx + tmpIdx];
1035
tmpStr[tmpIdx] = '\0';
1036
sourceIdx += tmpIdx;
1038
NSString *currMonth;
1039
NSArray *monthNames;
1041
currMonth = [[NSString alloc] initWithCString: tmpStr];
1042
monthNames = [locale objectForKey: NSMonthNameArray];
1044
for (tmpIdx = 0; tmpIdx < 12; tmpIdx++)
1046
if ([[monthNames objectAtIndex: tmpIdx]
1047
isEqual: currMonth] == YES)
1055
NSDebugMLog(@"Month of year '%@' not found in locale",
1067
case 'd': // fall through
1069
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1072
if (error == NO && day < 1)
1075
NSDebugMLog(@"Day of month is zero");
1080
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3, &error);
1081
milliseconds = atoi(tmpStr);
1084
case 'I': // fall through
1085
twelveHrClock = YES;
1087
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1088
hour = atoi(tmpStr);
1093
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3, &error);
1099
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1100
month = atoi(tmpStr);
1102
if (error == NO && month < 1)
1105
NSDebugMLog(@"Month of year is zero");
1110
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1116
/* FIXME ... Should look for all values from the locale,
1117
* matching for longest values first, rather than (wrongly)
1118
* assuming the name is always two uppercase letters.
1120
tmpStr[0] = toupper(source[sourceIdx]);
1121
if (sourceIdx < sourceLen)
1123
tmpStr[1] = toupper(source[sourceIdx]);
1124
if (sourceIdx < sourceLen)
1131
currAMPM = [NSString stringWithUTF8String: tmpStr];
1132
amPMNames = [locale objectForKey: NSAMPMDesignation];
1135
* The time addition is handled below because this
1136
* indicator only modifies the time on a 12hour clock.
1138
if ([[amPMNames objectAtIndex: 1] isEqual:
1147
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1153
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 1, &error);
1154
dayOfWeek = atoi(tmpStr);
1158
case 'W': // Fall through
1159
weekStartsMonday = 1;
1161
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 1, &error);
1162
julianWeeks = atoi(tmpStr);
1172
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1173
year = atoi(tmpStr);
1186
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 4, &error);
1187
year = atoi(tmpStr);
1197
if (source[sourceIdx] == '+')
1201
else if (source[sourceIdx] == '-')
1206
found = getDigits(&source[sourceIdx], tmpStr, 4, &error);
1210
zone = atoi(tmpStr);
1213
zone *= 100; // Convert 2 digits to 4
1215
tz = [NSTimeZone timeZoneForSecondsFromGMT:
1216
sign * ((zone / 100) * 60 + (zone % 100)) * 60];
1222
/* Can we assume a timezone name is always space terminated?
1224
tmpEnd = sizeof(tmpStr) - 1;
1225
if (sourceLen - sourceIdx < tmpEnd)
1227
tmpEnd = sourceLen - sourceIdx;
1229
for (tmpIdx = 0; tmpIdx < tmpEnd; tmpIdx++)
1231
if (!isspace(source[sourceIdx + tmpIdx]))
1233
tmpStr[tmpIdx] = source[sourceIdx + tmpIdx];
1240
tmpStr[tmpIdx] = '\0';
1241
sourceIdx += tmpIdx;
1243
NSString *z = [NSString stringWithUTF8String: tmpStr];
1245
/* Abbreviations aren't one-to-one with time zone names
1246
so just look for the zone named after the abbreviation,
1247
then look up the abbreviation as a last resort */
1248
tz = [NSTimeZone timeZoneWithName: z];
1251
tz = [NSTimeZone timeZoneWithAbbreviation: z];
914
/* FIXME ... Should look for all values from the locale,
915
* matching for longest values first, rather than (wrongly)
916
* assuming a fixed length of three characters.
918
tmpStr[0] = toupper(source[sourceIdx]);
919
if (sourceIdx < sourceLen)
921
tmpStr[1] = tolower(source[sourceIdx]);
922
if (sourceIdx < sourceLen)
924
tmpStr[2] = tolower(source[sourceIdx]);
925
if (sourceIdx < sourceLen)
932
currDay = [[NSString alloc] initWithCString: tmpStr];
933
dayNames = [locale objectForKey: NSShortWeekDayNameArray];
934
for (tmpIdx = 0; tmpIdx < 7; tmpIdx++)
936
if ([[dayNames objectAtIndex: tmpIdx] isEqual:
945
NSDebugMLog(@"Day of week '%@' not found in locale",
958
/* FIXME ... Should look for all values from the locale,
959
* matching for longest values first, rather than (wrongly)
960
* assuming the name contains only western letters.
962
tmpEnd = sizeof(tmpStr) - 1;
963
if (sourceLen - sourceIdx < tmpEnd)
965
tmpEnd = sourceLen - sourceIdx;
967
for (tmpIdx = 0; tmpIdx < tmpEnd; tmpIdx++)
969
if (isalpha(source[sourceIdx + tmpIdx]))
971
tmpStr[tmpIdx] = source[sourceIdx + tmpIdx];
978
tmpStr[tmpIdx] = '\0';
984
currDay = [[NSString alloc] initWithCString: tmpStr];
985
dayNames = [locale objectForKey: NSWeekDayNameArray];
986
for (tmpIdx = 0; tmpIdx < 7; tmpIdx++)
988
if ([[dayNames objectAtIndex: tmpIdx] isEqual:
997
NSDebugMLog(@"Day of week '%@' not found in locale",
1010
/* FIXME ... Should look for all values from the locale,
1011
* matching for longest values first, rather than (wrongly)
1012
* assuming a fixed length of three characters.
1014
tmpStr[0] = toupper(source[sourceIdx]);
1015
if (sourceIdx < sourceLen)
1017
tmpStr[1] = tolower(source[sourceIdx]);
1018
if (sourceIdx < sourceLen)
1020
tmpStr[2] = tolower(source[sourceIdx]);
1021
if (sourceIdx < sourceLen)
1025
NSString *currMonth;
1026
NSArray *monthNames;
1028
currMonth = [[NSString alloc] initWithCString: tmpStr];
1029
monthNames = [locale objectForKey: NSShortMonthNameArray];
1031
for (tmpIdx = 0; tmpIdx < 12; tmpIdx++)
1033
if ([[monthNames objectAtIndex: tmpIdx]
1034
isEqual: currMonth] == YES)
1042
NSDebugMLog(@"Month of year '%@' not found in locale",
1055
/* FIXME ... Should look for all values from the locale,
1056
* matching for longest values first, rather than (wrongly)
1057
* assuming the name contains only western letters.
1059
tmpEnd = sizeof(tmpStr) - 1;
1060
if (sourceLen - sourceIdx < tmpEnd)
1062
tmpEnd = sourceLen - sourceIdx;
1064
for (tmpIdx = 0; tmpIdx < tmpEnd; tmpIdx++)
1066
if (isalpha(source[sourceIdx + tmpIdx]))
1068
tmpStr[tmpIdx] = source[sourceIdx + tmpIdx];
1075
tmpStr[tmpIdx] = '\0';
1076
sourceIdx += tmpIdx;
1078
NSString *currMonth;
1079
NSArray *monthNames;
1081
currMonth = [[NSString alloc] initWithCString: tmpStr];
1082
monthNames = [locale objectForKey: NSMonthNameArray];
1084
for (tmpIdx = 0; tmpIdx < 12; tmpIdx++)
1086
if ([[monthNames objectAtIndex: tmpIdx]
1087
isEqual: currMonth] == YES)
1095
NSDebugMLog(@"Month of year '%@' not found in locale",
1107
case 'd': // fall through
1109
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1112
if (error == NO && day < 1)
1115
NSDebugMLog(@"Day of month is zero");
1120
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3, &error);
1121
milliseconds = atoi(tmpStr);
1125
// GNUstep extension, not available in Cocoa
1126
if (GSPrivateDefaultsFlag(GSMacOSXCompatible))
1129
NSLog(@"Invalid NSCalendar date, "
1130
@"specifier %c not recognized in format %@",
1131
format[formatIdx], fmt);
1133
case 'I': // fall through
1134
twelveHrClock = YES;
1136
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1137
hour = atoi(tmpStr);
1142
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 3, &error);
1148
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1149
month = atoi(tmpStr);
1151
if (error == NO && month < 1)
1154
NSDebugMLog(@"Month of year is zero");
1159
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1165
/* FIXME ... Should look for all values from the locale,
1166
* matching for longest values first, rather than (wrongly)
1167
* assuming the name is always two uppercase letters.
1169
tmpStr[0] = toupper(source[sourceIdx]);
1170
if (sourceIdx < sourceLen)
1172
tmpStr[1] = toupper(source[sourceIdx]);
1173
if (sourceIdx < sourceLen)
1180
currAMPM = [NSString stringWithUTF8String: tmpStr];
1181
amPMNames = [locale objectForKey: NSAMPMDesignation];
1184
* The time addition is handled below because this
1185
* indicator only modifies the time on a 12hour clock.
1187
if ([[amPMNames objectAtIndex: 1] isEqual:
1196
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1202
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 1, &error);
1203
dayOfWeek = atoi(tmpStr);
1207
case 'W': // Fall through
1208
weekStartsMonday = 1;
1210
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 1, &error);
1211
julianWeeks = atoi(tmpStr);
1221
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 2, &error);
1222
year = atoi(tmpStr);
1235
sourceIdx += getDigits(&source[sourceIdx], tmpStr, 4, &error);
1236
year = atoi(tmpStr);
1246
if (source[sourceIdx] == '+')
1250
else if (source[sourceIdx] == '-')
1255
found = getDigits(&source[sourceIdx], tmpStr, 4, &error);
1259
zone = atoi(tmpStr);
1262
zone *= 100; // Convert 2 digits to 4
1264
tz = [NSTimeZone timeZoneForSecondsFromGMT:
1265
sign * ((zone / 100) * 60 + (zone % 100)) * 60];
1271
/* Can we assume a timezone name is always space terminated?
1273
tmpEnd = sizeof(tmpStr) - 1;
1274
if (sourceLen - sourceIdx < tmpEnd)
1276
tmpEnd = sourceLen - sourceIdx;
1278
for (tmpIdx = 0; tmpIdx < tmpEnd; tmpIdx++)
1280
if (!isspace(source[sourceIdx + tmpIdx]))
1282
tmpStr[tmpIdx] = source[sourceIdx + tmpIdx];
1289
tmpStr[tmpIdx] = '\0';
1290
sourceIdx += tmpIdx;
1292
NSString *z = [NSString stringWithUTF8String: tmpStr];
1294
/* Abbreviations aren't one-to-one with time zone names
1295
so just look for the zone named after the abbreviation,
1296
then look up the abbreviation as a last resort */
1297
tz = [NSTimeZone timeZoneWithName: z];
1255
NSDebugMLog(@"Time zone '%@' not found", z);
1300
tz = [NSTimeZone timeZoneWithAbbreviation: z];
1304
NSDebugMLog(@"Time zone '%@' not found", z);
1312
NSLog(@"Invalid NSCalendar date, "
1313
@"specifier %c not recognized in format %@",
1314
format[formatIdx], fmt);
1263
NSLog(@"Invalid NSCalendar date, "
1264
@"specifier %c not recognized in format %@",
1265
format[formatIdx], fmt);