Upgrade to Devel::PPPort 3.00.
[p5sagit/p5-mst-13.2.git] / ext / Devel / PPPort / parts / inc / SvPV
1 ################################################################################
2 ##
3 ##  $Revision: 7 $
4 ##  $Author: mhx $
5 ##  $Date: 2004/08/13 12:47:16 +0200 $
6 ##
7 ################################################################################
8 ##
9 ##  Version 3.x, Copyright (C) 2004, Marcus Holland-Moritz.
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
20 SvPV_nolen
21 sv_2pv_nolen
22 SvPVbyte
23 sv_2pvbyte
24 sv_pvn
25 sv_pvn_force
26
27 =implementation
28
29 #ifndef SvPV_nolen
30
31 #if { NEED sv_2pv_nolen }
32
33 char *
34 sv_2pv_nolen(pTHX_ register SV *sv)
35 {   
36   STRLEN n_a;
37   return sv_2pv(sv, &n_a);
38 }
39
40 #endif
41
42 /* Hint: sv_2pv_nolen
43  * Use the SvPV_nolen() macro instead of sv_2pv_nolen().
44  */
45
46 /* SvPV_nolen depends on sv_2pv_nolen */
47 #define SvPV_nolen(sv) \
48           ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
49            ? SvPVX(sv) : sv_2pv_nolen(sv))
50
51 #endif
52
53 #ifdef SvPVbyte
54
55 /* Hint: SvPVbyte
56  * Does not work in perl-5.6.1, ppport.h implements a version
57  * borrowed from perl-5.7.3.
58  */
59
60 #if { VERSION < 5.7.0 }
61
62 #if { NEED sv_2pvbyte }
63
64 char *
65 sv_2pvbyte(pTHX_ register SV *sv, STRLEN *lp)
66 {   
67   sv_utf8_downgrade(sv,0);
68   return SvPV(sv,*lp);
69 }
70
71 #endif
72
73 /* Hint: sv_2pvbyte
74  * Use the SvPVbyte() macro instead of sv_2pvbyte().
75  */
76
77 #undef SvPVbyte
78
79 /* SvPVbyte depends on sv_2pvbyte */
80 #define SvPVbyte(sv, lp)                                                \
81         ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)                \
82          ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
83
84 #endif
85
86 #else
87
88 #  define SvPVbyte          SvPV
89 #  define sv_2pvbyte        sv_2pv
90
91 #endif
92
93 /* sv_2pvbyte_nolen depends on sv_2pv_nolen */
94 __UNDEFINED__  sv_2pvbyte_nolen  sv_2pv_nolen
95
96 /* Hint: sv_pvn
97  * Always use the SvPV() macro instead of sv_pvn().
98  */
99 __UNDEFINED__  sv_pvn(sv, len)         SvPV(sv, len)
100
101 /* Hint: sv_pvn
102  * Always use the SvPV_force() macro instead of sv_pvn_force().
103  */
104 __UNDEFINED__  sv_pvn_force(sv, len)   SvPV_force(sv, len)
105
106 =xsinit
107
108 #define NEED_sv_2pv_nolen
109 #define NEED_sv_2pvbyte
110
111 =xsubs
112
113 IV
114 SvPVbyte(sv)
115         SV *sv
116         PREINIT:
117                 STRLEN len;
118                 const char *str;
119         CODE:
120                 str = SvPVbyte(sv, len);
121                 RETVAL = strEQ(str, "mhx") ? len : -1;
122         OUTPUT:
123                 RETVAL
124
125 IV
126 SvPV_nolen(sv)
127         SV *sv
128         PREINIT:
129                 const char *str;
130         CODE:
131                 str = SvPV_nolen(sv);
132                 RETVAL = strEQ(str, "mhx") ? 3 : 0;
133         OUTPUT:
134                 RETVAL
135
136 =tests plan => 2
137
138 ok(&Devel::PPPort::SvPVbyte("mhx"), 3);
139 ok(&Devel::PPPort::SvPVbyte("mhx"), 3);
140