forked from quartzjer/js0n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
j0g.3
114 lines (104 loc) · 2.44 KB
/
j0g.3
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
.\"
.\" Copyright (c) 2014 Jeremie Miller <[email protected]>
.\"
.\"
.\" This software is in the pubic domain.
.\"
.\"
.Dd $Mdocdate: August 1, 2014 $
.Dt J0G 3
.Os
.Sh NAME
.Nm j0g ,
.Nm j0g_str ,
.Nm j0g_safe ,
.Nm j0g_test ,
.Nm j0g_val ,
.Nm j0g_val
.Nd utility functions for js0n parsing libary.
.Sh SYNOPSIS
.Fd "#include <js0n.h>"
.Fd "#include <j0g.h>"
.Pp
.Ft char *
.Fn j0g "const char *json" "unsigned short *index" "int ilen"
.Pp
.Ft int
.Fn j0g_val "const char *key" "char *json" "const unsigned short *index"
.Pp
.Ft char *
.Fn j0g_safe "int val" "char *json" "const unsigned short *index"
.Pp
.Ft char *
.Fn j0g_str "const char *key" "char *json" "const unsigned short *index"
.Pp
.Ft int
.Fn j0g_test "const char *key" "char *json" "const unsigned short *index"
.Sh DESCRIPTION
Convenience functions that make it easier to work with
.Nm js0n .
All but
.Fn j0g
operate on a particular key in the json string.
.Bl -tag -width Ds
.It Xo
.Fa char *
.Fn j0g "const char *json" "unsigned short *index" "int ilen"
.Xc
.Pp
A simpler version of
.Fn js0n
that assumes the
.Fa json
argument is a null-terminated string.
.It Xo
.Fa int
.Fn j0g_val "const char *key" "char *json" "const unsigned short *index" ;
.Xc
.Pp
For the given key, return the array element
that holds the starting position of the key's value. For example, if
index[2] holds the offset from the beginning of the json string
to the beginning of the
.Fa key ,
then
.Fn j0g_val
would return a 4 (index[3] holds the length of the key).
.Pp
If the key is not found (or if the key or the json is a null pointer), return 0.
.It Xo
.Fa char *
.Fn j0g_safe "int val" "char *json" "const unsigned short *index" ;
.Xc
.Pp
Modifies
.Fa json
passed in, null-terminating the value (or
key) whose offset is stored in the
.Fa index
array array location
.Fa val .
Also, unescapes newlines and double quotes in-place in
.Fa json.
Returns the null-terminated and unescaped string value.
.Pp
Note that this function does not unescape all escaped characters
in the JSON specification; only
newlines and double-quotes.
.It Xo
.Fa char *
.Fn j0g_str "const char *key" "char *json" "const unsigned short *index" ;
.Xc
.Pp
Return the null-terminated and (partially) unescaped string value
matching the given key.
If no such key, return NULL.
.It Xo
.Fa int
.Fn j0g_test "const char *key" "char *json" "const unsigned short *index" ;
.Xc
.Pp
Return 1 if the value is ``true'' or ``1'', false otherwise
.El
.Sh SEE ALSO
.Xr js0n 3