Base91.xs

filter: Statementstmt 100% 36 / 36 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 36 / 36 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« base91-0.6.0/base91.c ↑ Summary blib/lib/Convert/Base91.pm »
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5  
6 #include "ppport.h"
7  
8 #include <base91-0.6.0/base91.c>
9  
10 typedef struct base91 {
11 struct basE91 b91;
12 SV* output;
13 }* Convert__Base91;
14  
15 2 Convert__Base91 new(pTHX_ SV* class) {
16 Convert__Base91 self;
17 2 Newxc(self, 1, struct base91, struct base91);
18 2 basE91_init(&self->b91);
19 2 self->output = newSVpvs("");
20 2 return self;
21 }
22  
23 5 void encode(pTHX_ Convert__Base91 self, SV* input) {
24 void *o;
25 char* i;
26 size_t len, max_out_len, ret;
27  
28 5 i = SvPVbyte(input, len);
29 5 max_out_len = len + (len / 4) + 1; /* technically ceil(len * 16 / 13) */
30 5 Newx(o, max_out_len, char);
31  
32 5 ret = basE91_encode(&self->b91, i, len, o);
33 5 sv_catpvn_nomg(self->output, o, ret);
34 5 Safefree(o);
35 5 }
36  
37 4 SV* encode_end(pTHX_ Convert__Base91 self) {
38 char o[2];
39 size_t ret;
40 SV* out;
41 4 ret = basE91_encode_end(&self->b91, o);
42 4 sv_catpvn_nomg(self->output, o, ret);
43  
44 4 out = self->output;
45 4 self->output = newSVpvs("");
46 4 return out;
47 }
48  
49 5 void decode(pTHX_ Convert__Base91 self, SV* input) {
50 void *o;
51 char* i;
52 size_t len, max_out_len, ret;
53  
54 5 i = SvPVbyte(input, len);
55 5 Newx(o, len, char);
56  
57 5 ret = basE91_decode(&self->b91, i, len, o);
58 5 sv_catpvn_nomg(self->output, o, ret);
59 5 Safefree(o);
60 5 }
61  
62 5 SV* decode_end(pTHX_ Convert__Base91 self) {
63 char o;
64 size_t ret;
65 SV* out;
66 5 ret = basE91_decode_end(&self->b91, &o);
67 5 sv_catpvn_nomg(self->output, &o, ret);
68  
69 5 out = self->output;
70 5 self->output = newSVpvs("");
71 5 return out;
72 }
73  
74 2 void DESTROY(pTHX_ Convert__Base91 self) {
75 2 sv_2mortal(self->output);
76 2 Safefree(self);
77 2 }
78  
79 MODULE = Convert::Base91 PACKAGE = Convert::Base91
80 PROTOTYPES: ENABLE
81  
82 Convert::Base91 new(SV* class)
83 C_ARGS: aTHX_ class
84  
85 void encode(Convert::Base91 self, SV* input)
86 C_ARGS: aTHX_ self, input
87  
88 SV* encode_end(Convert::Base91 self)
89 C_ARGS: aTHX_ self
90  
91 void decode(Convert::Base91 self, SV* input)
92 C_ARGS: aTHX_ self, input
93  
94 SV* decode_end(Convert::Base91 self)
95 C_ARGS: aTHX_ self
96  
97 void DESTROY(Convert::Base91 self)
98 C_ARGS: aTHX_ self
« base91-0.6.0/base91.c ↑ Summary blib/lib/Convert/Base91.pm »