candle 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/VERSION +1 -0
- data/bin/candle +21 -0
- data/lib/candle.rb +68 -0
- data/lib/candle/command.rb +27 -0
- data/lib/candle/generators/actions.rb +183 -0
- data/lib/candle/generators/blank.rb +127 -0
- data/lib/candle/generators/cli.rb +55 -0
- data/lib/candle/generators/help.rb +47 -0
- data/lib/candle/generators/jam.rb +80 -0
- data/lib/candle/generators/lua/scripts/AppDelegate.lua +36 -0
- data/lib/candle/generators/lua/scripts/tests/init.lua +6 -0
- data/lib/candle/generators/lua/scripts/tests/someTest.lua +12 -0
- data/lib/candle/generators/lua/wax/ProtocolLoader.h +12 -0
- data/lib/candle/generators/lua/wax/bin/hammer +157 -0
- data/lib/candle/generators/lua/wax/bin/update-xibs +131 -0
- data/lib/candle/generators/lua/wax/bin/waxsim +0 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/compile-stdlib.sh +14 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/copy-scripts.sh +58 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/luac.lua +80 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.m +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.m +251 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.h +14 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.m +240 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.h +54 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.m +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.h +9 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.m +273 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/Rakefile +10 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.c +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.h +11 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl-1.0.9.tar.gz +0 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl.c +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.c +65 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.c +119 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.h +73 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_bytestack.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.c +188 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.c +322 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.c +737 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.h +133 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.c +448 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.c +1087 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.h +16 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.c +652 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.h +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lbaselib.c +653 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.c +839 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.h +76 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldblib.c +397 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.c +638 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.h +33 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.c +518 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.h +57 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldump.c +164 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.c +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.h +34 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.c +711 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.h +110 -0
- data/lib/candle/generators/lua/wax/lib/lua/linit.c +38 -0
- data/lib/candle/generators/lua/wax/lib/lua/liolib.c +553 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.c +461 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.h +81 -0
- data/lib/candle/generators/lua/wax/lib/lua/llimits.h +128 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmathlib.c +263 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.c +86 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.h +49 -0
- data/lib/candle/generators/lua/wax/lib/lua/loadlib.c +666 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.h +381 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.c +102 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.h +268 -0
- data/lib/candle/generators/lua/wax/lib/lua/loslib.c +243 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.c +1339 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.h +169 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.c +111 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.h +31 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstrlib.c +869 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.c +588 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.h +40 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltablib.c +287 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.c +75 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.h +54 -0
- data/lib/candle/generators/lua/wax/lib/lua/lua.h +388 -0
- data/lib/candle/generators/lua/wax/lib/lua/luaconf.h +753 -0
- data/lib/candle/generators/lua/wax/lib/lua/lualib.h +53 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.c +227 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.c +763 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.c +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.h +67 -0
- data/lib/candle/generators/lua/wax/lib/lua/print.c +227 -0
- data/lib/candle/generators/lua/wax/lib/project.rake +159 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/enums.lua +396 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/http.lua +43 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/init.lua +4 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/number.lua +21 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/string.lua +97 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/table.lua +165 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/WaxServer.lua +49 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/autoload.lua +10 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/base64.lua +64 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/bit.lua +274 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/cache.lua +73 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/callback.lua +22 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/frame.lua +76 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/init.lua +78 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/pickView.lua +54 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/time.lua +102 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/init.lua +18 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/init.lua +2 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luamock.lua +84 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luaspec.lua +377 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/repl.lua +9 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/structs.lua +11 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/waxClass.lua +42 -0
- data/lib/candle/generators/lua/wax/lib/wax.h +16 -0
- data/lib/candle/generators/lua/wax/lib/wax.m +260 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.h +18 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.m +190 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.h +20 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.m +56 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.h +102 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.m +870 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.h +34 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.m +810 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.h +47 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.m +252 -0
- data/lib/candle/generators/lua/wax/lib/wax_stdlib.h +3 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.h +26 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.m +335 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.pbxproj +836 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/WaxApplication.xcscheme +86 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default-568h@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/ProtocolLoader.h +12 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Info.plist.tt +38 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Prefix.pch.tt +14 -0
- data/lib/candle/generators/templates/blank/WaxApplication/en.lproj/InfoPlist.strings +2 -0
- data/lib/candle/generators/templates/blank/WaxApplication/main.m.tt +20 -0
- data/lib/candle/tasks.rb +22 -0
- data/lib/candle/utility.rb +30 -0
- data/lib/candle/version.rb +9 -0
- data/lib/candle/view.rb +48 -0
- metadata +582 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2009, Lloyd Hilaiel.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are
|
6
|
+
* met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived
|
18
|
+
* from this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
24
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
28
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
/*
|
34
|
+
* A header only implementation of a simple stack of bytes, used in YAJL
|
35
|
+
* to maintain parse state.
|
36
|
+
*/
|
37
|
+
|
38
|
+
#ifndef __YAJL_BYTESTACK_H__
|
39
|
+
#define __YAJL_BYTESTACK_H__
|
40
|
+
|
41
|
+
#include "api/yajl_common.h"
|
42
|
+
|
43
|
+
#define YAJL_BS_INC 128
|
44
|
+
|
45
|
+
typedef struct yajl_bytestack_t
|
46
|
+
{
|
47
|
+
unsigned char * stack;
|
48
|
+
unsigned int size;
|
49
|
+
unsigned int used;
|
50
|
+
yajl_alloc_funcs * yaf;
|
51
|
+
} yajl_bytestack;
|
52
|
+
|
53
|
+
/* initialize a bytestack */
|
54
|
+
#define yajl_bs_init(obs, _yaf) { \
|
55
|
+
(obs).stack = NULL; \
|
56
|
+
(obs).size = 0; \
|
57
|
+
(obs).used = 0; \
|
58
|
+
(obs).yaf = (_yaf); \
|
59
|
+
} \
|
60
|
+
|
61
|
+
|
62
|
+
/* initialize a bytestack */
|
63
|
+
#define yajl_bs_free(obs) \
|
64
|
+
if ((obs).stack) (obs).yaf->free((obs).yaf->ctx, (obs).stack);
|
65
|
+
|
66
|
+
#define yajl_bs_current(obs) \
|
67
|
+
(assert((obs).used > 0), (obs).stack[(obs).used - 1])
|
68
|
+
|
69
|
+
#define yajl_bs_push(obs, byte) { \
|
70
|
+
if (((obs).size - (obs).used) == 0) { \
|
71
|
+
(obs).size += YAJL_BS_INC; \
|
72
|
+
(obs).stack = (obs).yaf->realloc((obs).yaf->ctx,\
|
73
|
+
(void *) (obs).stack, (obs).size);\
|
74
|
+
} \
|
75
|
+
(obs).stack[((obs).used)++] = (byte); \
|
76
|
+
}
|
77
|
+
|
78
|
+
/* removes the top item of the stack, returns nothing */
|
79
|
+
#define yajl_bs_pop(obs) { ((obs).used)--; }
|
80
|
+
|
81
|
+
#define yajl_bs_set(obs, byte) \
|
82
|
+
(obs).stack[((obs).used) - 1] = (byte);
|
83
|
+
|
84
|
+
|
85
|
+
#endif
|
@@ -0,0 +1,85 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are
|
6
|
+
* met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived
|
18
|
+
* from this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
24
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
28
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
#ifndef __YAJL_COMMON_H__
|
34
|
+
#define __YAJL_COMMON_H__
|
35
|
+
|
36
|
+
#ifdef __cplusplus
|
37
|
+
extern "C" {
|
38
|
+
#endif
|
39
|
+
|
40
|
+
#define YAJL_MAX_DEPTH 128
|
41
|
+
|
42
|
+
/* msft dll export gunk. To build a DLL on windows, you
|
43
|
+
* must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared
|
44
|
+
* DLL, you must define YAJL_SHARED and WIN32 */
|
45
|
+
#if defined(WIN32) && defined(YAJL_SHARED)
|
46
|
+
# ifdef YAJL_BUILD
|
47
|
+
# define YAJL_API __declspec(dllexport)
|
48
|
+
# else
|
49
|
+
# define YAJL_API __declspec(dllimport)
|
50
|
+
# endif
|
51
|
+
#else
|
52
|
+
# define YAJL_API
|
53
|
+
#endif
|
54
|
+
|
55
|
+
/** pointer to a malloc function, supporting client overriding memory
|
56
|
+
* allocation routines */
|
57
|
+
typedef void * (*yajl_malloc_func)(void *ctx, unsigned int sz);
|
58
|
+
|
59
|
+
/** pointer to a free function, supporting client overriding memory
|
60
|
+
* allocation routines */
|
61
|
+
typedef void (*yajl_free_func)(void *ctx, void * ptr);
|
62
|
+
|
63
|
+
/** pointer to a realloc function which can resize an allocation. */
|
64
|
+
typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, unsigned int sz);
|
65
|
+
|
66
|
+
/** A structure which can be passed to yajl_*_alloc routines to allow the
|
67
|
+
* client to specify memory allocation functions to be used. */
|
68
|
+
typedef struct
|
69
|
+
{
|
70
|
+
/** pointer to a function that can allocate uninitialized memory */
|
71
|
+
yajl_malloc_func malloc;
|
72
|
+
/** pointer to a function that can resize memory allocations */
|
73
|
+
yajl_realloc_func realloc;
|
74
|
+
/** pointer to a function that can free memory allocated using
|
75
|
+
* reallocFunction or mallocFunction */
|
76
|
+
yajl_free_func free;
|
77
|
+
/** a context pointer that will be passed to above allocation routines */
|
78
|
+
void * ctx;
|
79
|
+
} yajl_alloc_funcs;
|
80
|
+
|
81
|
+
#ifdef __cplusplus
|
82
|
+
}
|
83
|
+
#endif
|
84
|
+
|
85
|
+
#endif
|
@@ -0,0 +1,188 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are
|
6
|
+
* met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived
|
18
|
+
* from this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
24
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
28
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
#include "yajl_encode.h"
|
34
|
+
|
35
|
+
#include <assert.h>
|
36
|
+
#include <stdlib.h>
|
37
|
+
#include <string.h>
|
38
|
+
#include <stdio.h>
|
39
|
+
|
40
|
+
static void CharToHex(unsigned char c, char * hexBuf)
|
41
|
+
{
|
42
|
+
const char * hexchar = "0123456789ABCDEF";
|
43
|
+
hexBuf[0] = hexchar[c >> 4];
|
44
|
+
hexBuf[1] = hexchar[c & 0x0F];
|
45
|
+
}
|
46
|
+
|
47
|
+
void
|
48
|
+
yajl_string_encode(yajl_buf buf, const unsigned char * str,
|
49
|
+
unsigned int len)
|
50
|
+
{
|
51
|
+
yajl_string_encode2((const yajl_print_t) &yajl_buf_append, buf, str, len);
|
52
|
+
}
|
53
|
+
|
54
|
+
void
|
55
|
+
yajl_string_encode2(const yajl_print_t print,
|
56
|
+
void * ctx,
|
57
|
+
const unsigned char * str,
|
58
|
+
unsigned int len)
|
59
|
+
{
|
60
|
+
unsigned int beg = 0;
|
61
|
+
unsigned int end = 0;
|
62
|
+
char hexBuf[7];
|
63
|
+
hexBuf[0] = '\\'; hexBuf[1] = 'u'; hexBuf[2] = '0'; hexBuf[3] = '0';
|
64
|
+
hexBuf[6] = 0;
|
65
|
+
|
66
|
+
while (end < len) {
|
67
|
+
const char * escaped = NULL;
|
68
|
+
switch (str[end]) {
|
69
|
+
case '\r': escaped = "\\r"; break;
|
70
|
+
case '\n': escaped = "\\n"; break;
|
71
|
+
case '\\': escaped = "\\\\"; break;
|
72
|
+
/* case '/': escaped = "\\/"; break; */
|
73
|
+
case '"': escaped = "\\\""; break;
|
74
|
+
case '\f': escaped = "\\f"; break;
|
75
|
+
case '\b': escaped = "\\b"; break;
|
76
|
+
case '\t': escaped = "\\t"; break;
|
77
|
+
default:
|
78
|
+
if ((unsigned char) str[end] < 32) {
|
79
|
+
CharToHex(str[end], hexBuf + 4);
|
80
|
+
escaped = hexBuf;
|
81
|
+
}
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
if (escaped != NULL) {
|
85
|
+
print(ctx, (const char *) (str + beg), end - beg);
|
86
|
+
print(ctx, escaped, strlen(escaped));
|
87
|
+
beg = ++end;
|
88
|
+
} else {
|
89
|
+
++end;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
print(ctx, (const char *) (str + beg), end - beg);
|
93
|
+
}
|
94
|
+
|
95
|
+
static void hexToDigit(unsigned int * val, const unsigned char * hex)
|
96
|
+
{
|
97
|
+
unsigned int i;
|
98
|
+
for (i=0;i<4;i++) {
|
99
|
+
unsigned char c = hex[i];
|
100
|
+
if (c >= 'A') c = (c & ~0x20) - 7;
|
101
|
+
c -= '0';
|
102
|
+
assert(!(c & 0xF0));
|
103
|
+
*val = (*val << 4) | c;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
static void Utf32toUtf8(unsigned int codepoint, char * utf8Buf)
|
108
|
+
{
|
109
|
+
if (codepoint < 0x80) {
|
110
|
+
utf8Buf[0] = (char) codepoint;
|
111
|
+
utf8Buf[1] = 0;
|
112
|
+
} else if (codepoint < 0x0800) {
|
113
|
+
utf8Buf[0] = (char) ((codepoint >> 6) | 0xC0);
|
114
|
+
utf8Buf[1] = (char) ((codepoint & 0x3F) | 0x80);
|
115
|
+
utf8Buf[2] = 0;
|
116
|
+
} else if (codepoint < 0x10000) {
|
117
|
+
utf8Buf[0] = (char) ((codepoint >> 12) | 0xE0);
|
118
|
+
utf8Buf[1] = (char) (((codepoint >> 6) & 0x3F) | 0x80);
|
119
|
+
utf8Buf[2] = (char) ((codepoint & 0x3F) | 0x80);
|
120
|
+
utf8Buf[3] = 0;
|
121
|
+
} else if (codepoint < 0x200000) {
|
122
|
+
utf8Buf[0] =(char)((codepoint >> 18) | 0xF0);
|
123
|
+
utf8Buf[1] =(char)(((codepoint >> 12) & 0x3F) | 0x80);
|
124
|
+
utf8Buf[2] =(char)(((codepoint >> 6) & 0x3F) | 0x80);
|
125
|
+
utf8Buf[3] =(char)((codepoint & 0x3F) | 0x80);
|
126
|
+
utf8Buf[4] = 0;
|
127
|
+
} else {
|
128
|
+
utf8Buf[0] = '?';
|
129
|
+
utf8Buf[1] = 0;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
void yajl_string_decode(yajl_buf buf, const unsigned char * str,
|
134
|
+
unsigned int len)
|
135
|
+
{
|
136
|
+
unsigned int beg = 0;
|
137
|
+
unsigned int end = 0;
|
138
|
+
|
139
|
+
while (end < len) {
|
140
|
+
if (str[end] == '\\') {
|
141
|
+
char utf8Buf[5];
|
142
|
+
const char * unescaped = "?";
|
143
|
+
yajl_buf_append(buf, str + beg, end - beg);
|
144
|
+
switch (str[++end]) {
|
145
|
+
case 'r': unescaped = "\r"; break;
|
146
|
+
case 'n': unescaped = "\n"; break;
|
147
|
+
case '\\': unescaped = "\\"; break;
|
148
|
+
case '/': unescaped = "/"; break;
|
149
|
+
case '"': unescaped = "\""; break;
|
150
|
+
case 'f': unescaped = "\f"; break;
|
151
|
+
case 'b': unescaped = "\b"; break;
|
152
|
+
case 't': unescaped = "\t"; break;
|
153
|
+
case 'u': {
|
154
|
+
unsigned int codepoint = 0;
|
155
|
+
hexToDigit(&codepoint, str + ++end);
|
156
|
+
end+=3;
|
157
|
+
/* check if this is a surrogate */
|
158
|
+
if ((codepoint & 0xFC00) == 0xD800) {
|
159
|
+
end++;
|
160
|
+
if (str[end] == '\\' && str[end + 1] == 'u') {
|
161
|
+
unsigned int surrogate = 0;
|
162
|
+
hexToDigit(&surrogate, str + end + 2);
|
163
|
+
codepoint =
|
164
|
+
(((codepoint & 0x3F) << 10) |
|
165
|
+
((((codepoint >> 6) & 0xF) + 1) << 16) |
|
166
|
+
(surrogate & 0x3FF));
|
167
|
+
end += 5;
|
168
|
+
} else {
|
169
|
+
unescaped = "?";
|
170
|
+
break;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
Utf32toUtf8(codepoint, utf8Buf);
|
175
|
+
unescaped = utf8Buf;
|
176
|
+
break;
|
177
|
+
}
|
178
|
+
default:
|
179
|
+
assert("this should never happen" == NULL);
|
180
|
+
}
|
181
|
+
yajl_buf_append(buf, unescaped, strlen(unescaped));
|
182
|
+
beg = ++end;
|
183
|
+
} else {
|
184
|
+
end++;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
yajl_buf_append(buf, str + beg, end - beg);
|
188
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are
|
6
|
+
* met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived
|
18
|
+
* from this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
24
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
28
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
#ifndef __YAJL_ENCODE_H__
|
34
|
+
#define __YAJL_ENCODE_H__
|
35
|
+
|
36
|
+
#include "yajl_buf.h"
|
37
|
+
#include "api/yajl_gen.h"
|
38
|
+
|
39
|
+
void yajl_string_encode2(const yajl_print_t printer,
|
40
|
+
void * ctx,
|
41
|
+
const unsigned char * str,
|
42
|
+
unsigned int length);
|
43
|
+
|
44
|
+
void yajl_string_encode(yajl_buf buf, const unsigned char * str,
|
45
|
+
unsigned int length);
|
46
|
+
|
47
|
+
void yajl_string_decode(yajl_buf buf, const unsigned char * str,
|
48
|
+
unsigned int length);
|
49
|
+
|
50
|
+
#endif
|
@@ -0,0 +1,322 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are
|
6
|
+
* met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived
|
18
|
+
* from this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
24
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
28
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
#include "api/yajl_gen.h"
|
34
|
+
#include "yajl_buf.h"
|
35
|
+
#include "yajl_encode.h"
|
36
|
+
|
37
|
+
#include <stdlib.h>
|
38
|
+
#include <string.h>
|
39
|
+
#include <stdio.h>
|
40
|
+
#include <math.h>
|
41
|
+
|
42
|
+
typedef enum {
|
43
|
+
yajl_gen_start,
|
44
|
+
yajl_gen_map_start,
|
45
|
+
yajl_gen_map_key,
|
46
|
+
yajl_gen_map_val,
|
47
|
+
yajl_gen_array_start,
|
48
|
+
yajl_gen_in_array,
|
49
|
+
yajl_gen_complete,
|
50
|
+
yajl_gen_error
|
51
|
+
} yajl_gen_state;
|
52
|
+
|
53
|
+
struct yajl_gen_t
|
54
|
+
{
|
55
|
+
unsigned int depth;
|
56
|
+
unsigned int pretty;
|
57
|
+
const char * indentString;
|
58
|
+
yajl_gen_state state[YAJL_MAX_DEPTH];
|
59
|
+
yajl_print_t print;
|
60
|
+
void * ctx; /* yajl_buf */
|
61
|
+
/* memory allocation routines */
|
62
|
+
yajl_alloc_funcs alloc;
|
63
|
+
};
|
64
|
+
|
65
|
+
yajl_gen
|
66
|
+
yajl_gen_alloc(const yajl_gen_config * config,
|
67
|
+
const yajl_alloc_funcs * afs)
|
68
|
+
{
|
69
|
+
return yajl_gen_alloc2(NULL, config, afs, NULL);
|
70
|
+
}
|
71
|
+
|
72
|
+
yajl_gen
|
73
|
+
yajl_gen_alloc2(const yajl_print_t callback,
|
74
|
+
const yajl_gen_config * config,
|
75
|
+
const yajl_alloc_funcs * afs,
|
76
|
+
void * ctx)
|
77
|
+
{
|
78
|
+
yajl_gen g = NULL;
|
79
|
+
yajl_alloc_funcs afsBuffer;
|
80
|
+
|
81
|
+
/* first order of business is to set up memory allocation routines */
|
82
|
+
if (afs != NULL) {
|
83
|
+
if (afs->malloc == NULL || afs->realloc == NULL || afs->free == NULL)
|
84
|
+
{
|
85
|
+
return NULL;
|
86
|
+
}
|
87
|
+
} else {
|
88
|
+
yajl_set_default_alloc_funcs(&afsBuffer);
|
89
|
+
afs = &afsBuffer;
|
90
|
+
}
|
91
|
+
|
92
|
+
g = (yajl_gen) YA_MALLOC(afs, sizeof(struct yajl_gen_t));
|
93
|
+
memset((void *) g, 0, sizeof(struct yajl_gen_t));
|
94
|
+
/* copy in pointers to allocation routines */
|
95
|
+
memcpy((void *) &(g->alloc), (void *) afs, sizeof(yajl_alloc_funcs));
|
96
|
+
|
97
|
+
if (config) {
|
98
|
+
g->pretty = config->beautify;
|
99
|
+
g->indentString = config->indentString ? config->indentString : " ";
|
100
|
+
}
|
101
|
+
|
102
|
+
if (callback) {
|
103
|
+
g->print = callback;
|
104
|
+
g->ctx = ctx;
|
105
|
+
} else {
|
106
|
+
g->print = (yajl_print_t)&yajl_buf_append;
|
107
|
+
g->ctx = yajl_buf_alloc(&(g->alloc));
|
108
|
+
}
|
109
|
+
|
110
|
+
return g;
|
111
|
+
}
|
112
|
+
|
113
|
+
void
|
114
|
+
yajl_gen_free(yajl_gen g)
|
115
|
+
{
|
116
|
+
if (g->print == (yajl_print_t)&yajl_buf_append) yajl_buf_free((yajl_buf)g->ctx);
|
117
|
+
YA_FREE(&(g->alloc), g);
|
118
|
+
}
|
119
|
+
|
120
|
+
#define INSERT_SEP \
|
121
|
+
if (g->state[g->depth] == yajl_gen_map_key || \
|
122
|
+
g->state[g->depth] == yajl_gen_in_array) { \
|
123
|
+
g->print(g->ctx, ",", 1); \
|
124
|
+
if (g->pretty) g->print(g->ctx, "\n", 1); \
|
125
|
+
} else if (g->state[g->depth] == yajl_gen_map_val) { \
|
126
|
+
g->print(g->ctx, ":", 1); \
|
127
|
+
if (g->pretty) g->print(g->ctx, " ", 1); \
|
128
|
+
}
|
129
|
+
|
130
|
+
#define INSERT_WHITESPACE \
|
131
|
+
if (g->pretty) { \
|
132
|
+
if (g->state[g->depth] != yajl_gen_map_val) { \
|
133
|
+
unsigned int _i; \
|
134
|
+
for (_i=0;_i<g->depth;_i++) \
|
135
|
+
g->print(g->ctx, g->indentString, \
|
136
|
+
strlen(g->indentString)); \
|
137
|
+
} \
|
138
|
+
}
|
139
|
+
|
140
|
+
#define ENSURE_NOT_KEY \
|
141
|
+
if (g->state[g->depth] == yajl_gen_map_key) { \
|
142
|
+
return yajl_gen_keys_must_be_strings; \
|
143
|
+
} \
|
144
|
+
|
145
|
+
/* check that we're not complete, or in error state. in a valid state
|
146
|
+
* to be generating */
|
147
|
+
#define ENSURE_VALID_STATE \
|
148
|
+
if (g->state[g->depth] == yajl_gen_error) { \
|
149
|
+
return yajl_gen_in_error_state;\
|
150
|
+
} else if (g->state[g->depth] == yajl_gen_complete) { \
|
151
|
+
return yajl_gen_generation_complete; \
|
152
|
+
}
|
153
|
+
|
154
|
+
#define INCREMENT_DEPTH \
|
155
|
+
if (++(g->depth) >= YAJL_MAX_DEPTH) return yajl_max_depth_exceeded;
|
156
|
+
|
157
|
+
#define APPENDED_ATOM \
|
158
|
+
switch (g->state[g->depth]) { \
|
159
|
+
case yajl_gen_start: \
|
160
|
+
g->state[g->depth] = yajl_gen_complete; \
|
161
|
+
break; \
|
162
|
+
case yajl_gen_map_start: \
|
163
|
+
case yajl_gen_map_key: \
|
164
|
+
g->state[g->depth] = yajl_gen_map_val; \
|
165
|
+
break; \
|
166
|
+
case yajl_gen_array_start: \
|
167
|
+
g->state[g->depth] = yajl_gen_in_array; \
|
168
|
+
break; \
|
169
|
+
case yajl_gen_map_val: \
|
170
|
+
g->state[g->depth] = yajl_gen_map_key; \
|
171
|
+
break; \
|
172
|
+
default: \
|
173
|
+
break; \
|
174
|
+
} \
|
175
|
+
|
176
|
+
#define FINAL_NEWLINE \
|
177
|
+
if (g->pretty && g->state[g->depth] == yajl_gen_complete) \
|
178
|
+
g->print(g->ctx, "\n", 1);
|
179
|
+
|
180
|
+
yajl_gen_status
|
181
|
+
yajl_gen_integer(yajl_gen g, long int number)
|
182
|
+
{
|
183
|
+
char i[32];
|
184
|
+
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
185
|
+
sprintf(i, "%ld", number);
|
186
|
+
g->print(g->ctx, i, strlen(i));
|
187
|
+
APPENDED_ATOM;
|
188
|
+
FINAL_NEWLINE;
|
189
|
+
return yajl_gen_status_ok;
|
190
|
+
}
|
191
|
+
|
192
|
+
#ifdef WIN32
|
193
|
+
#include <float.h>
|
194
|
+
#define isnan _isnan
|
195
|
+
#define isinf !_finite
|
196
|
+
#endif
|
197
|
+
|
198
|
+
yajl_gen_status
|
199
|
+
yajl_gen_double(yajl_gen g, double number)
|
200
|
+
{
|
201
|
+
char i[32];
|
202
|
+
ENSURE_VALID_STATE; ENSURE_NOT_KEY;
|
203
|
+
if (isnan(number) || isinf(number)) return yajl_gen_invalid_number;
|
204
|
+
INSERT_SEP; INSERT_WHITESPACE;
|
205
|
+
sprintf(i, "%g", number);
|
206
|
+
g->print(g->ctx, i, strlen(i));
|
207
|
+
APPENDED_ATOM;
|
208
|
+
FINAL_NEWLINE;
|
209
|
+
return yajl_gen_status_ok;
|
210
|
+
}
|
211
|
+
|
212
|
+
yajl_gen_status
|
213
|
+
yajl_gen_number(yajl_gen g, const char * s, unsigned int l)
|
214
|
+
{
|
215
|
+
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
216
|
+
g->print(g->ctx, s, l);
|
217
|
+
APPENDED_ATOM;
|
218
|
+
FINAL_NEWLINE;
|
219
|
+
return yajl_gen_status_ok;
|
220
|
+
}
|
221
|
+
|
222
|
+
yajl_gen_status
|
223
|
+
yajl_gen_string(yajl_gen g, const unsigned char * str,
|
224
|
+
unsigned int len)
|
225
|
+
{
|
226
|
+
ENSURE_VALID_STATE; INSERT_SEP; INSERT_WHITESPACE;
|
227
|
+
g->print(g->ctx, "\"", 1);
|
228
|
+
yajl_string_encode2(g->print, g->ctx, str, len);
|
229
|
+
g->print(g->ctx, "\"", 1);
|
230
|
+
APPENDED_ATOM;
|
231
|
+
FINAL_NEWLINE;
|
232
|
+
return yajl_gen_status_ok;
|
233
|
+
}
|
234
|
+
|
235
|
+
yajl_gen_status
|
236
|
+
yajl_gen_null(yajl_gen g)
|
237
|
+
{
|
238
|
+
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
239
|
+
g->print(g->ctx, "null", strlen("null"));
|
240
|
+
APPENDED_ATOM;
|
241
|
+
FINAL_NEWLINE;
|
242
|
+
return yajl_gen_status_ok;
|
243
|
+
}
|
244
|
+
|
245
|
+
yajl_gen_status
|
246
|
+
yajl_gen_bool(yajl_gen g, int boolean)
|
247
|
+
{
|
248
|
+
const char * val = boolean ? "true" : "false";
|
249
|
+
|
250
|
+
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
251
|
+
g->print(g->ctx, val, strlen(val));
|
252
|
+
APPENDED_ATOM;
|
253
|
+
FINAL_NEWLINE;
|
254
|
+
return yajl_gen_status_ok;
|
255
|
+
}
|
256
|
+
|
257
|
+
yajl_gen_status
|
258
|
+
yajl_gen_map_open(yajl_gen g)
|
259
|
+
{
|
260
|
+
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
261
|
+
INCREMENT_DEPTH;
|
262
|
+
|
263
|
+
g->state[g->depth] = yajl_gen_map_start;
|
264
|
+
g->print(g->ctx, "{", 1);
|
265
|
+
if (g->pretty) g->print(g->ctx, "\n", 1);
|
266
|
+
FINAL_NEWLINE;
|
267
|
+
return yajl_gen_status_ok;
|
268
|
+
}
|
269
|
+
|
270
|
+
yajl_gen_status
|
271
|
+
yajl_gen_map_close(yajl_gen g)
|
272
|
+
{
|
273
|
+
ENSURE_VALID_STATE;
|
274
|
+
(g->depth)--;
|
275
|
+
if (g->pretty) g->print(g->ctx, "\n", 1);
|
276
|
+
APPENDED_ATOM;
|
277
|
+
INSERT_WHITESPACE;
|
278
|
+
g->print(g->ctx, "}", 1);
|
279
|
+
FINAL_NEWLINE;
|
280
|
+
return yajl_gen_status_ok;
|
281
|
+
}
|
282
|
+
|
283
|
+
yajl_gen_status
|
284
|
+
yajl_gen_array_open(yajl_gen g)
|
285
|
+
{
|
286
|
+
ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
|
287
|
+
INCREMENT_DEPTH;
|
288
|
+
g->state[g->depth] = yajl_gen_array_start;
|
289
|
+
g->print(g->ctx, "[", 1);
|
290
|
+
if (g->pretty) g->print(g->ctx, "\n", 1);
|
291
|
+
FINAL_NEWLINE;
|
292
|
+
return yajl_gen_status_ok;
|
293
|
+
}
|
294
|
+
|
295
|
+
yajl_gen_status
|
296
|
+
yajl_gen_array_close(yajl_gen g)
|
297
|
+
{
|
298
|
+
ENSURE_VALID_STATE;
|
299
|
+
if (g->pretty) g->print(g->ctx, "\n", 1);
|
300
|
+
(g->depth)--;
|
301
|
+
APPENDED_ATOM;
|
302
|
+
INSERT_WHITESPACE;
|
303
|
+
g->print(g->ctx, "]", 1);
|
304
|
+
FINAL_NEWLINE;
|
305
|
+
return yajl_gen_status_ok;
|
306
|
+
}
|
307
|
+
|
308
|
+
yajl_gen_status
|
309
|
+
yajl_gen_get_buf(yajl_gen g, const unsigned char ** buf,
|
310
|
+
unsigned int * len)
|
311
|
+
{
|
312
|
+
if (g->print != (yajl_print_t)&yajl_buf_append) return yajl_gen_no_buf;
|
313
|
+
*buf = yajl_buf_data((yajl_buf)g->ctx);
|
314
|
+
*len = yajl_buf_len((yajl_buf)g->ctx);
|
315
|
+
return yajl_gen_status_ok;
|
316
|
+
}
|
317
|
+
|
318
|
+
void
|
319
|
+
yajl_gen_clear(yajl_gen g)
|
320
|
+
{
|
321
|
+
if (g->print == (yajl_print_t)&yajl_buf_append) yajl_buf_clear((yajl_buf)g->ctx);
|
322
|
+
}
|