Config-UCL
view release on metacpan or search on metacpan
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "const-c.inc"
#include <ucl.h>
bool implicit_unicode;
int ucl_string_flags;
static ucl_object_t *
_iterate_perl (pTHX_ SV* obj) {
if ( SvTYPE(obj) == SVt_NULL ) {
return ucl_object_new();
}
else if (
sv_isobject(obj) && (
sv_isa(obj, "JSON::PP::Boolean")
SV *
_ucl_type (pTHX_ ucl_object_t const *obj)
{
switch (obj->type) {
case UCL_INT:
return newSViv((long long)ucl_object_toint (obj));
case UCL_FLOAT:
return newSVnv(ucl_object_todouble (obj));
case UCL_STRING: {
SV *sv = newSVpv(ucl_object_tostring (obj), 0);
if (implicit_unicode) {
SvUTF8_on(sv);
}
return sv;
}
case UCL_BOOLEAN: {
SV* rv = newSV_type(SVt_IV);
sv_setref_iv(rv, "JSON::PP::Boolean", ucl_object_toboolean(obj) ? 1 : 0);
return rv;
}
case UCL_TIME:
}
if (obj->type == UCL_OBJECT) {
const ucl_object_t *cur;
ucl_object_iter_t it_obj = NULL;
val = sv_2mortal((SV*)newHV());
while ((cur = ucl_object_iterate (obj, &it_obj, true))) {
SV *key = newSVpv(ucl_object_key(cur),0);
if (implicit_unicode)
SvUTF8_on(key);
hv_store_ent((HV*)val, sv_2mortal(key), _iterate_ucl(aTHX_ cur), 0);
}
val = newRV(val);
} else if (obj->type == UCL_ARRAY) {
const ucl_object_t *cur;
ucl_object_iter_t it_obj = NULL;
val = sv_2mortal((SV*)newAV());
return ret;
}
MODULE = Config::UCL PACKAGE = Config::UCL
INCLUDE: const-xs.inc
PROTOTYPES: ENABLED
SV *
_ucl_dump(SV *sv, bool _implicit_unicode, ucl_emitter_t emitter)
CODE:
implicit_unicode = _implicit_unicode;
ucl_object_t *root = NULL;
root = _iterate_perl(aTHX_ sv);
if (root) {
RETVAL = newSVpv((char *)ucl_object_emit(root, emitter), 0);
if (implicit_unicode)
SvUTF8_on(RETVAL);
ucl_object_unref(root);
}
OUTPUT:
RETVAL
bool
ucl_validate(SV *schema_sv, SV *data_sv)
CODE:
ucl_object_t *data, *schema;
bool
ucl_parser_add_file_full (struct ucl_parser *parser, const char *filename, unsigned priority, enum ucl_duplicate_strategy strat, enum ucl_parse_type parse_type);
void
DESTROY(struct ucl_parser *parser)
CODE:
ucl_parser_free(parser);
SV *
ucl_load(struct ucl_parser *parser, bool _implicit_unicode, int _ucl_string_flags)
CODE:
implicit_unicode = _implicit_unicode;
ucl_string_flags = _ucl_string_flags;
RETVAL = _load_ucl(aTHX_ parser);
OUTPUT:
RETVAL
libucl-0.8.1/python/tests/test_dump.py view on Meta::CPAN
def test_int_array(self):
data = { "a" : [1,2,3,4] }
valid = "a [\n 1,\n 2,\n 3,\n 4,\n]\n"
self.assertEqual(ucl.dump(data), valid)
def test_str(self):
data = { "a" : "b" }
valid = "a = \"b\";\n"
self.assertEqual(ucl.dump(data), valid)
@unittest.skipIf(sys.version_info[0] > 2, "Python3 uses unicode only")
def test_unicode(self):
data = { unicode("a") : unicode("b") }
valid = unicode("a = \"b\";\n")
self.assertEqual(ucl.dump(data), valid)
def test_float(self):
data = { "a" : 1.1 }
valid = "a = 1.100000;\n"
self.assertEqual(ucl.dump(data), valid)
def test_boolean(self):
data = { "a" : True, "b" : False }
valid = [
libucl-0.8.1/src/ucl_emitter_utils.c view on Meta::CPAN
case '\f':
func->ucl_emitter_append_len ("\\f", 2, func->ud);
break;
case '\\':
func->ucl_emitter_append_len ("\\\\", 2, func->ud);
break;
case '"':
func->ucl_emitter_append_len ("\\\"", 2, func->ud);
break;
default:
/* Emit unicode unknown character */
func->ucl_emitter_append_len ("\\uFFFD", 5, func->ud);
break;
}
len = 0;
c = ++p;
}
else {
p ++;
len ++;
}
parse_fullexpr||5.013008|
parse_fullstmt||5.013005|
parse_gv_stash_name|||
parse_ident|||
parse_label||5.013007|
parse_listexpr||5.013008|
parse_lparen_question_flags|||
parse_stmtseq||5.013006|
parse_subsignature|||
parse_termexpr||5.013008|
parse_unicode_opts|||
parser_dup|||
parser_free_nexttoke_ops|||
parser_free|||
path_is_searchable|||n
peep|||
pending_ident|||
perl_alloc_using|||n
perl_alloc|||n
perl_clone_using|||n
perl_clone|||n
#endif
#ifndef PERL_PV_PRETTY_DUMP
# define PERL_PV_PRETTY_DUMP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE
#endif
#ifndef PERL_PV_PRETTY_REGPROP
# define PERL_PV_PRETTY_REGPROP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_LTGT|PERL_PV_ESCAPE_RE
#endif
/* Hint: pv_escape
* Note that unicode functionality is only backported to
* those perl versions that support it. For older perl
* versions, the implementation will fall back to bytes.
*/
#ifndef pv_escape
#if defined(NEED_pv_escape)
static char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags);
static
#else
extern char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags);
t/20-dump.t view on Meta::CPAN
dies_ok { eval "ucl_dump()"; die $@ if $@ };
is ucl_dump(undef), 'null';
is ucl_dump({ a => undef }), "a = null;\n";
is ucl_dump({ a => 1 }) , "a = 1;\n";
is ucl_dump({ a => { b => 1 } }), "a {\n b = 1;\n}\n";
is ucl_dump({ a => [1,2,3,4] }), "a [\n 1,\n 2,\n 3,\n 4,\n]\n";
is ucl_dump({ a => "b" }), "a = \"b\";\n";
# @unittest.skipIf(sys.version_info[0] > 2, "Python3 uses unicode only")
# def test_unicode(self):
# data = { unicode("a") : unicode("b") }
# valid = unicode("a = \"b\";\n")
# self.assertEqual(ucl.dump(data), valid)
is ucl_dump({ a => 1.1 }), "a = 1.100000;\n";
assertIn ucl_dump({ a => true, b => false }), "a = true;\nb = false;\n", "b = false;\na = true;\n";
is ucl_dump({}), "";
assertIn ucl_dump({ a => 1, b => "bleh;" }, { ucl_emitter => UCL_EMIT_JSON } ),
qq#{\n "a": 1,\n "b": "bleh;"\n}#, qq#{\n "b": "bleh;",\n "a": 1\n}#;
{
my $out = ucl_dump({ key => "val" });
( run in 0.616 second using v1.01-cache-2.11-cpan-88abd93f124 )