-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdeHTMLxs.xs
148 lines (113 loc) · 3.24 KB
/
deHTMLxs.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
/* $Id: deHTMLxs.xs,v 1.6 2006/02/16 19:16:00 rsoderberg Exp $ */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* try to be compatible with older perls */
/* SvPV_nolen() macro first defined in 5.005_55 */
/* this is slow, not threadsafe, but works */
#include "patchlevel.h"
#if (PATCHLEVEL == 4) || ((PATCHLEVEL == 5) && (SUBVERSION < 55))
static STRLEN nolen_na;
# define SvPV_nolen(sv) SvPV ((sv), nolen_na)
#endif
#include "deHTMLxs.h"
typedef struct mystate {
int is_xs;
} *Razor2__Preproc__deHTMLxs;
MODULE = Razor2::Preproc::deHTMLxs PACKAGE = Razor2::Preproc::deHTMLxs
PROTOTYPES: ENABLE
Razor2::Preproc::deHTMLxs
new(class)
SV * class
CODE:
{
Newz(0, RETVAL, 1, struct mystate);
RETVAL->is_xs = 1; /* placeholder, not used now */
}
OUTPUT:
RETVAL
int
is_xs(self)
Razor2::Preproc::deHTMLxs self;
CODE:
RETVAL = 1;
OUTPUT:
RETVAL
char *
testxs(self, str)
Razor2::Preproc::deHTMLxs self;
char * str;
CODE:
RETVAL = str + 1;
OUTPUT:
RETVAL
SV *
isit(self, scalarref)
Razor2::Preproc::deHTMLxs self;
SV * scalarref;
CODE:
{
/* 2002/11/21 Anne Bennett: use the right type def: */
STRLEN size;
char * raw;
SV * text;
const char mynull = 0;
if (SvROK(scalarref)) {
text = SvRV(scalarref);
/* normally perl has '\0' on end, but not guaranteed */
sv_catpv(text,&mynull);
raw = SvPV(text,size);
/* bool CM_PREPROC_is_html(const char *); */
if (CM_PREPROC_is_html(raw)) {
RETVAL = newSVpv ("1", 0);
} else {
RETVAL = newSVpv ("", 0);
}
} else {
RETVAL = newSVpv ("", 0);
}
}
OUTPUT:
RETVAL
SV *
doit(self, scalarref)
Razor2::Preproc::deHTMLxs self;
SV * scalarref
CODE:
{
char * cleaned, * raw, * res;
/* 2002/11/21 Anne Bennett: use the right type def: */
STRLEN size;
SV * text;
SV * newtext;
SV * newref;
if (SvROK(scalarref)) {
text = SvRV(scalarref);
raw = SvPV(text,size);
*(raw + size - 1) = '\0';
if ( (cleaned = malloc(size+1)) &&
(res = CM_PREPROC_html_strip(raw, cleaned)) /* html_strip will memset cleaned to 0 */
) {
/*
* hook it up so scalarref will dereference to new scalar
*/
newtext = newSVpv (res, 0);
/* newtext is new scalar containing cleaned html.
* we want scalarref to point to that instead of its old dude, text. */
/* sv_setsv (SV* dest, SV* src) */
sv_setsv(text, newtext);
SvREFCNT_inc(scalarref);
RETVAL = scalarref;
free(cleaned);
} else {
if (cleaned) {
free(cleaned);
}
RETVAL = newSVpv ("", 0);
}
} else {
RETVAL = newSVpv ("", 0);
}
}
OUTPUT:
RETVAL