ObjFW  Diff

Differences From Artifact [635c1d9aeb]:

To Artifact [63b54ee0d2]:


19
20
21
22
23
24
25
26
27
28
29
30

31
32
33


34
35
36


37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
58
59

60
61
62

63
64
65
66
67

68
69
70
71
72
73
74

75
76
77

78
79
80
81
82
83
84
19
20
21
22
23
24
25

26
27
28
29
30
31


32
33
34


35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56
57
58

59
60
61

62
63
64
65
66

67
68
69
70
71
72


73
74
75

76
77
78
79
80
81
82
83







-




+

-
-
+
+

-
-
+
+












-
+









-
+


-
+




-
+





-
-
+


-
+







#include <string.h>

#include <time.h>

const char*
of_strptime(const char *buffer, const char *format, struct tm *tm)
{
	size_t i, j, bufferLength, formatLength;
	enum {
		SEARCH_CONVERSION_SPECIFIER,
		IN_CONVERSION_SPECIFIER
	} state = SEARCH_CONVERSION_SPECIFIER;
	size_t i, j, buffer_len, format_len;

	bufferLength = strlen(buffer);
	formatLength = strlen(format);
	buffer_len = strlen(buffer);
	format_len = strlen(format);

	for (i = j = 0; i < formatLength; i++) {
		if (j >= bufferLength)
	for (i = j = 0; i < format_len; i++) {
		if (j >= buffer_len)
			return NULL;

		switch (state) {
		case SEARCH_CONVERSION_SPECIFIER:
			if (format[i] == '%')
				state = IN_CONVERSION_SPECIFIER;
			else if (format[i] != buffer[j++])
				return NULL;

			break;

		case IN_CONVERSION_SPECIFIER:;
			int k, maxLength, number = 0;
			int k, max_len, number = 0;

			switch (format[i]) {
			case 'd':
			case 'e':
			case 'H':
			case 'm':
			case 'M':
			case 'S':
			case 'y':
				maxLength = 2;
				max_len = 2;
				break;
			case 'Y':
				maxLength = 4;
				max_len = 4;
				break;
			case '%':
			case 'n':
			case 't':
				maxLength = 0;
				max_len = 0;
				break;
			default:
				return NULL;
			}

			if (maxLength > 0 &&
			    (buffer[j] < '0' || buffer[j] > '9'))
			if (max_len > 0 && (buffer[j] < '0' || buffer[j] > '9'))
				return NULL;

			for (k = 0; k < maxLength && j < bufferLength &&
			for (k = 0; k < max_len && j < buffer_len &&
			    buffer[j] >= '0' && buffer[j] <= '9'; k++, j++) {
				number *= 10;
				number += buffer[j] - '0';
			}

			switch (format[i]) {
			case 'd':