Some escapes were mentioned twice, although they're not qr//-specific
[p5sagit/p5-mst-13.2.git] / ext / Devel / PPPort / parts / inc / SvPV
CommitLineData
adfe19db 1################################################################################
2##
af36fda7 3## $Revision: 17 $
adfe19db 4## $Author: mhx $
af36fda7 5## $Date: 2007/08/13 22:59:33 +0200 $
adfe19db 6##
7################################################################################
8##
d2dacc4f 9## Version 3.x, Copyright (C) 2004-2007, Marcus Holland-Moritz.
adfe19db 10## Version 2.x, Copyright (C) 2001, Paul Marquess.
11## Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
12##
13## This program is free software; you can redistribute it and/or
14## modify it under the same terms as Perl itself.
15##
16################################################################################
17
18=provides
19
679ad62d 20__UNDEFINED__
adfe19db 21SvPVbyte
22sv_2pvbyte
679ad62d 23sv_2pv_flags
24sv_pvn_force_flags
adfe19db 25
679ad62d 26=dontwarn
adfe19db 27
679ad62d 28NEED_sv_2pv_flags
af36fda7 29NEED_sv_2pv_flags_GLOBAL
adfe19db 30
679ad62d 31=implementation
adfe19db 32
679ad62d 33/* Backwards compatibility stuff... :-( */
34#if !defined(NEED_sv_2pv_flags) && defined(NEED_sv_2pv_nolen)
35# define NEED_sv_2pv_flags
36#endif
37#if !defined(NEED_sv_2pv_flags_GLOBAL) && defined(NEED_sv_2pv_nolen_GLOBAL)
38# define NEED_sv_2pv_flags_GLOBAL
adfe19db 39#endif
40
41/* Hint: sv_2pv_nolen
679ad62d 42 * Use the SvPV_nolen() or SvPV_nolen_const() macros instead of sv_2pv_nolen().
adfe19db 43 */
44
679ad62d 45__UNDEFINED__ sv_2pv_nolen(sv) SvPV_nolen(sv)
adfe19db 46
47#ifdef SvPVbyte
48
49/* Hint: SvPVbyte
50 * Does not work in perl-5.6.1, ppport.h implements a version
51 * borrowed from perl-5.7.3.
52 */
53
54#if { VERSION < 5.7.0 }
55
56#if { NEED sv_2pvbyte }
57
58char *
59sv_2pvbyte(pTHX_ register SV *sv, STRLEN *lp)
4a582685 60{
adfe19db 61 sv_utf8_downgrade(sv,0);
62 return SvPV(sv,*lp);
63}
64
65#endif
66
67/* Hint: sv_2pvbyte
68 * Use the SvPVbyte() macro instead of sv_2pvbyte().
69 */
70
71#undef SvPVbyte
72
adfe19db 73#define SvPVbyte(sv, lp) \
74 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
75 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
76
77#endif
78
79#else
80
81# define SvPVbyte SvPV
82# define sv_2pvbyte sv_2pv
83
84#endif
85
679ad62d 86__UNDEFINED__ sv_2pvbyte_nolen(sv) sv_2pv_nolen(sv)
adfe19db 87
88/* Hint: sv_pvn
89 * Always use the SvPV() macro instead of sv_pvn().
90 */
adfe19db 91
04fc8b94 92/* Hint: sv_pvn_force
adfe19db 93 * Always use the SvPV_force() macro instead of sv_pvn_force().
94 */
adfe19db 95
679ad62d 96/* If these are undefined, they're not handled by the core anyway */
97__UNDEFINED__ SV_IMMEDIATE_UNREF 0
98__UNDEFINED__ SV_GMAGIC 0
99__UNDEFINED__ SV_COW_DROP_PV 0
100__UNDEFINED__ SV_UTF8_NO_ENCODING 0
101__UNDEFINED__ SV_NOSTEAL 0
102__UNDEFINED__ SV_CONST_RETURN 0
103__UNDEFINED__ SV_MUTABLE_RETURN 0
104__UNDEFINED__ SV_SMAGIC 0
105__UNDEFINED__ SV_HAS_TRAILING_NUL 0
106__UNDEFINED__ SV_COW_SHARED_HASH_KEYS 0
107
108#if { VERSION < 5.7.2 }
109
110#if { NEED sv_2pv_flags }
111
112char *
113sv_2pv_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags)
114{
115 STRLEN n_a = (STRLEN) flags;
116 return sv_2pv(sv, lp ? lp : &n_a);
117}
118
119#endif
120
121#if { NEED sv_pvn_force_flags }
122
123char *
124sv_pvn_force_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags)
125{
126 STRLEN n_a = (STRLEN) flags;
127 return sv_pvn_force(sv, lp ? lp : &n_a);
128}
129
130#endif
131
132#endif
133
134__UNDEFINED__ SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC)
135__UNDEFINED__ SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC)
136
137__UNDEFINED__ SvPV_flags(sv, lp, flags) \
138 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
139 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags))
140
141__UNDEFINED__ SvPV_flags_const(sv, lp, flags) \
142 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
143 ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \
144 (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN))
145
146__UNDEFINED__ SvPV_flags_const_nolen(sv, flags) \
147 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
148 ? SvPVX_const(sv) : \
149 (const char*) sv_2pv_flags(sv, 0, flags|SV_CONST_RETURN))
150
151__UNDEFINED__ SvPV_flags_mutable(sv, lp, flags) \
152 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
153 ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \
154 sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN))
155
156__UNDEFINED__ SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)
157__UNDEFINED__ SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC)
158__UNDEFINED__ SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC)
159__UNDEFINED__ SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
160__UNDEFINED__ SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0)
161
162__UNDEFINED__ SvPV_force_flags(sv, lp, flags) \
163 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
164 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))
165
166__UNDEFINED__ SvPV_force_flags_nolen(sv, flags) \
167 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
168 ? SvPVX(sv) : sv_pvn_force_flags(sv, 0, flags))
169
170__UNDEFINED__ SvPV_force_flags_mutable(sv, lp, flags) \
171 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
172 ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \
173 : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN))
174
175__UNDEFINED__ SvPV_nolen(sv) \
176 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
177 ? SvPVX(sv) : sv_2pv_flags(sv, 0, SV_GMAGIC))
178
179__UNDEFINED__ SvPV_nolen_const(sv) \
180 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
181 ? SvPVX_const(sv) : sv_2pv_flags(sv, 0, SV_GMAGIC|SV_CONST_RETURN))
182
183__UNDEFINED__ SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)
184__UNDEFINED__ SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0)
185__UNDEFINED__ SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0)
186
adfe19db 187=xsinit
188
679ad62d 189#define NEED_sv_2pv_flags
190#define NEED_sv_pvn_force_flags
adfe19db 191#define NEED_sv_2pvbyte
192
193=xsubs
194
195IV
196SvPVbyte(sv)
197 SV *sv
198 PREINIT:
679ad62d 199 char *str;
adfe19db 200 STRLEN len;
adfe19db 201 CODE:
202 str = SvPVbyte(sv, len);
0d0f8426 203 RETVAL = strEQ(str, "mhx") ? (IV) len : (IV) -1;
adfe19db 204 OUTPUT:
205 RETVAL
206
207IV
208SvPV_nolen(sv)
209 SV *sv
210 PREINIT:
679ad62d 211 char *str;
adfe19db 212 CODE:
213 str = SvPV_nolen(sv);
9132e1a3 214 RETVAL = strEQ(str, "mhx") ? 42 : 0;
adfe19db 215 OUTPUT:
216 RETVAL
217
679ad62d 218IV
219SvPV_const(sv)
220 SV *sv
221 PREINIT:
222 const char *str;
223 STRLEN len;
224 CODE:
225 str = SvPV_const(sv, len);
226 RETVAL = len + (strEQ(str, "mhx") ? 40 : 0);
227 OUTPUT:
228 RETVAL
229
230IV
231SvPV_mutable(sv)
232 SV *sv
233 PREINIT:
234 char *str;
235 STRLEN len;
236 CODE:
237 str = SvPV_mutable(sv, len);
238 RETVAL = len + (strEQ(str, "mhx") ? 41 : 0);
239 OUTPUT:
240 RETVAL
241
242IV
243SvPV_flags(sv)
244 SV *sv
245 PREINIT:
246 char *str;
247 STRLEN len;
248 CODE:
249 str = SvPV_flags(sv, len, SV_GMAGIC);
250 RETVAL = len + (strEQ(str, "mhx") ? 42 : 0);
251 OUTPUT:
252 RETVAL
253
254IV
255SvPV_flags_const(sv)
256 SV *sv
257 PREINIT:
258 const char *str;
259 STRLEN len;
260 CODE:
261 str = SvPV_flags_const(sv, len, SV_GMAGIC);
262 RETVAL = len + (strEQ(str, "mhx") ? 43 : 0);
263 OUTPUT:
264 RETVAL
265
266IV
267SvPV_flags_const_nolen(sv)
268 SV *sv
269 PREINIT:
270 const char *str;
271 CODE:
272 str = SvPV_flags_const_nolen(sv, SV_GMAGIC);
273 RETVAL = strEQ(str, "mhx") ? 47 : 0;
274 OUTPUT:
275 RETVAL
276
277IV
278SvPV_flags_mutable(sv)
279 SV *sv
280 PREINIT:
281 char *str;
282 STRLEN len;
283 CODE:
284 str = SvPV_flags_mutable(sv, len, SV_GMAGIC);
285 RETVAL = len + (strEQ(str, "mhx") ? 45 : 0);
286 OUTPUT:
287 RETVAL
288
289IV
290SvPV_force(sv)
291 SV *sv
292 PREINIT:
293 char *str;
294 STRLEN len;
295 CODE:
296 str = SvPV_force(sv, len);
297 RETVAL = len + (strEQ(str, "mhx") ? 46 : 0);
298 OUTPUT:
299 RETVAL
300
301IV
302SvPV_force_nolen(sv)
303 SV *sv
304 PREINIT:
305 char *str;
306 CODE:
307 str = SvPV_force_nolen(sv);
308 RETVAL = strEQ(str, "mhx") ? 50 : 0;
309 OUTPUT:
310 RETVAL
311
312IV
313SvPV_force_mutable(sv)
314 SV *sv
315 PREINIT:
316 char *str;
317 STRLEN len;
318 CODE:
319 str = SvPV_force_mutable(sv, len);
320 RETVAL = len + (strEQ(str, "mhx") ? 48 : 0);
321 OUTPUT:
322 RETVAL
323
324IV
325SvPV_force_nomg(sv)
326 SV *sv
327 PREINIT:
328 char *str;
329 STRLEN len;
330 CODE:
331 str = SvPV_force_nomg(sv, len);
332 RETVAL = len + (strEQ(str, "mhx") ? 49 : 0);
333 OUTPUT:
334 RETVAL
335
336IV
337SvPV_force_nomg_nolen(sv)
338 SV *sv
339 PREINIT:
340 char *str;
341 CODE:
342 str = SvPV_force_nomg_nolen(sv);
343 RETVAL = strEQ(str, "mhx") ? 53 : 0;
344 OUTPUT:
345 RETVAL
346
347IV
348SvPV_force_flags(sv)
349 SV *sv
350 PREINIT:
351 char *str;
352 STRLEN len;
353 CODE:
354 str = SvPV_force_flags(sv, len, SV_GMAGIC);
355 RETVAL = len + (strEQ(str, "mhx") ? 51 : 0);
356 OUTPUT:
357 RETVAL
358
359IV
360SvPV_force_flags_nolen(sv)
361 SV *sv
362 PREINIT:
363 char *str;
364 CODE:
365 str = SvPV_force_flags_nolen(sv, SV_GMAGIC);
366 RETVAL = strEQ(str, "mhx") ? 55 : 0;
367 OUTPUT:
368 RETVAL
369
370IV
371SvPV_force_flags_mutable(sv)
372 SV *sv
373 PREINIT:
374 char *str;
375 STRLEN len;
376 CODE:
377 str = SvPV_force_flags_mutable(sv, len, SV_GMAGIC);
378 RETVAL = len + (strEQ(str, "mhx") ? 53 : 0);
379 OUTPUT:
380 RETVAL
381
382IV
383SvPV_nolen_const(sv)
384 SV *sv
385 PREINIT:
386 const char *str;
387 CODE:
388 str = SvPV_nolen_const(sv);
389 RETVAL = strEQ(str, "mhx") ? 57 : 0;
390 OUTPUT:
391 RETVAL
392
393IV
394SvPV_nomg(sv)
395 SV *sv
396 PREINIT:
397 char *str;
398 STRLEN len;
399 CODE:
400 str = SvPV_nomg(sv, len);
401 RETVAL = len + (strEQ(str, "mhx") ? 55 : 0);
402 OUTPUT:
403 RETVAL
404
405IV
406SvPV_nomg_const(sv)
407 SV *sv
408 PREINIT:
409 const char *str;
410 STRLEN len;
411 CODE:
412 str = SvPV_nomg_const(sv, len);
413 RETVAL = len + (strEQ(str, "mhx") ? 56 : 0);
414 OUTPUT:
415 RETVAL
416
417IV
418SvPV_nomg_const_nolen(sv)
419 SV *sv
420 PREINIT:
421 const char *str;
422 CODE:
423 str = SvPV_nomg_const_nolen(sv);
424 RETVAL = strEQ(str, "mhx") ? 60 : 0;
425 OUTPUT:
426 RETVAL
427
428
429=tests plan => 20
430
431my $mhx = "mhx";
432
433ok(&Devel::PPPort::SvPVbyte($mhx), 3);
434
435my $i = 42;
436
437ok(&Devel::PPPort::SvPV_nolen($mhx), $i++);
438ok(&Devel::PPPort::SvPV_const($mhx), $i++);
439ok(&Devel::PPPort::SvPV_mutable($mhx), $i++);
440ok(&Devel::PPPort::SvPV_flags($mhx), $i++);
441ok(&Devel::PPPort::SvPV_flags_const($mhx), $i++);
442
443ok(&Devel::PPPort::SvPV_flags_const_nolen($mhx), $i++);
444ok(&Devel::PPPort::SvPV_flags_mutable($mhx), $i++);
445ok(&Devel::PPPort::SvPV_force($mhx), $i++);
446ok(&Devel::PPPort::SvPV_force_nolen($mhx), $i++);
447ok(&Devel::PPPort::SvPV_force_mutable($mhx), $i++);
448
449ok(&Devel::PPPort::SvPV_force_nomg($mhx), $i++);
450ok(&Devel::PPPort::SvPV_force_nomg_nolen($mhx), $i++);
451ok(&Devel::PPPort::SvPV_force_flags($mhx), $i++);
452ok(&Devel::PPPort::SvPV_force_flags_nolen($mhx), $i++);
453ok(&Devel::PPPort::SvPV_force_flags_mutable($mhx), $i++);
adfe19db 454
679ad62d 455ok(&Devel::PPPort::SvPV_nolen_const($mhx), $i++);
456ok(&Devel::PPPort::SvPV_nomg($mhx), $i++);
457ok(&Devel::PPPort::SvPV_nomg_const($mhx), $i++);
458ok(&Devel::PPPort::SvPV_nomg_const_nolen($mhx), $i++);
adfe19db 459