-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateUtil.xs
152 lines (121 loc) · 2.66 KB
/
GenerateUtil.xs
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "GenerateFunctions.h"
#define B_INPLACE 1
#define B_LFTOBR 2
#define B_SPTONBSP 4
#define B_LEAVEKNOWN 8
#define B_ESCAPEVAL 1
#define B_ADDNEWLINE 2
#define B_CLOSETAG 4
MODULE = HTML::GenerateUtil PACKAGE = HTML::GenerateUtil
SV *
escape_html(str, ...)
SV * str
PREINIT:
int mode = 0;
INIT:
int b_inplace, b_lftobr, b_sptonbsp, b_leaveknown;
SV * newstr;
/* Check it's a string */
SvGETMAGIC(str);
if (!SvOK(str)) {
XSRETURN_UNDEF;
}
CODE:
if (items > 1)
mode = (int)SvIV(ST(1));
/* Get flags */
b_inplace = mode & B_INPLACE;
b_lftobr = mode & B_LFTOBR;
b_sptonbsp = mode & B_SPTONBSP;
b_leaveknown = mode & B_LEAVEKNOWN;
/* Call helper function */
newstr = GF_escape_html(str, b_inplace, b_lftobr, b_sptonbsp, b_leaveknown);
if (!newstr)
XSRETURN_UNDEF;
/* Increment reference count because RETVAL = does implicit sv_2mortal later */
if (b_inplace)
SvREFCNT_inc(newstr);
RETVAL = newstr;
OUTPUT:
RETVAL
SV *
generate_attributes(attr)
SV * attr
INIT:
SV * attrstr;
HV * attrhv;
if (!SvOK(attr) || !SvROK(attr) || SvTYPE(SvRV(attr)) != SVt_PVHV) {
XSRETURN_UNDEF;
}
attrhv = (HV *)SvRV(attr);
CODE:
attrstr = GF_generate_attributes(attrhv);
RETVAL = attrstr;
OUTPUT:
RETVAL
SV *
generate_tag(tag, attr, val, mode)
SV * tag
SV * attr
SV * val
int mode
INIT:
SV * tagstr;
HV * attrhv = 0;
int b_escapeval, b_addnewline, b_closetag;
if (!SvOK(tag)) {
XSRETURN_UNDEF;
}
if (SvOK(attr) && (!SvROK(attr) || (SvROK(attr) && SvTYPE(SvRV(attr)) != SVt_PVHV))) {
XSRETURN_UNDEF;
}
if (!SvOK(val)) {
val = 0;
}
attrhv = SvOK(attr) ? (HV *)SvRV(attr) : 0;
/* Get flags */
b_escapeval = mode & B_ESCAPEVAL;
b_addnewline = mode & B_ADDNEWLINE;
b_closetag = mode & B_CLOSETAG;
CODE:
tagstr = GF_generate_tag(tag, attrhv, val, b_escapeval, b_addnewline, b_closetag);
RETVAL = tagstr;
OUTPUT:
RETVAL
SV *
escape_uri_internal(str, escstr, mode)
SV * str
SV * escstr
int mode
INIT:
int b_inplace;
SV * newstr;
/* Check it's a string */
SvGETMAGIC(str);
if (!SvOK(str) || !SvOK(escstr)) {
XSRETURN_UNDEF;
}
/* Get flags */
b_inplace = mode & B_INPLACE;
CODE:
/* Call helper function */
newstr = GF_escape_uri(str, escstr, b_inplace);
if (!newstr)
XSRETURN_UNDEF;
/* Increment reference count because RETVAL = does implicit sv_2mortal later */
if (b_inplace)
SvREFCNT_inc(newstr);
RETVAL = newstr;
OUTPUT:
RETVAL
void
set_paranoia(paranoia)
int paranoia
INIT:
/* Call helper function */
GF_set_paranoia(paranoia);
XSRETURN_UNDEF;