-
Notifications
You must be signed in to change notification settings - Fork 0
/
ucio.cpp
70 lines (61 loc) · 1.57 KB
/
ucio.cpp
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
/*
* UniversalContainer library.
* Copyright Jason Denton, 2008,2010.
* Made available under the new BSD license, as described in LICENSE
*
* Send comments and bug reports to jason.denton@gmail.com
* http://www.greatpanic.com/code.html
*/
#include <stdio.h>
#include <iostream>
#include "ucontainer.h"
#include "ucio.h"
#include "buffer.h"
#include "string_util.h"
/*
Routines for doing io with universal containers. Mostly, there are
wrappers on the serialization and deserialization routines. For. web based
routines, see uc_web.cpp and uc_curl.cpp
*/
namespace JAD {
void print(UniversalContainer& uc)
{
Buffer* buf = uc_encode_ini(uc);
buf->put('\n');
write_from_buffer(buf,stdout);
delete buf;
}
void print_json(UniversalContainer& uc, int indent)
{
Buffer* buf = new Buffer;
uc_encode_pretty_json(uc,buf,0,indent);
write_from_buffer(buf,stdout);
delete buf;
}
UniversalContainer load_ini_file(const char* filename)
{
UniversalContainer uc;
Buffer* buf = read_to_buffer(filename);
if (!buf) return uc;
uc = uc_decode_ini(buf);
delete buf;
return uc;
}
bool write_ini_file(const char* filename, UniversalContainer& uc)
{
Buffer* buf = uc_encode_ini(uc);
if (!buf) return false;
bool result = write_from_buffer(buf,filename);
delete buf;
return result;
}
UniversalContainer uc_from_json_file(const char* fname)
{
UniversalContainer uc;
Buffer* buf = read_to_buffer(fname);
if (!buf) return uc;
uc = uc_decode_json(buf);
delete buf;
return uc;
}
}