-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboolean.c
More file actions
72 lines (58 loc) · 1.03 KB
/
boolean.c
File metadata and controls
72 lines (58 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
#include <stdlib.h>
#include <string.h>
#include "boolean.h"
JsonValue *match_boolean(char *json, int *index, int size)
{
JsonValue *result = create_json_value();
result->start = *index;
result->end = *index;
result->error->code = "";
int ok = 0;
// remaining size should be 4 or 5
if (size >= *index + 5)
{
ok = 1;
for (int i = 0; i < 5; i++)
{
if (json[*index + i] != FALSE[i])
{
ok = 0;
break;
}
result->end++;
}
if (ok)
{
result->type = JSON_FALSE;
}
}
if (result->type != JSON_FALSE && size >= *index + 4)
{
ok = 1;
result->end = *index;
for (int i = 0; i < 4; i++)
{
if (json[*index + i] != TRUE[i])
{
ok = 0;
break;
}
result->end++;
}
if (ok)
{
result->type = JSON_TRUE;
}
}
if (ok)
{
free_json_error(result->error);
result->error = NULL;
result->end--;
}
else
{
result->error->code = "boolean-invalid-value";
}
return result;
};