Commit | Line | Data |
c1a049cb |
1 | ################################################################################ |
2 | ## |
3 | ## $Revision: 4 $ |
4 | ## $Author: mhx $ |
5 | ## $Date: 2008/01/04 13:10:54 +0100 $ |
6 | ## |
7 | ################################################################################ |
8 | ## |
9 | ## Version 3.x, Copyright (C) 2004-2008, 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 | __UNDEFINED__ |
21 | newSVpvn_flags |
22 | |
23 | =implementation |
24 | |
25 | __UNDEFINED__ newSVpvn(data,len) ((data) \ |
26 | ? ((len) ? newSVpv((data), (len)) : newSVpv("", 0)) \ |
27 | : newSV(0)) |
28 | |
29 | __UNDEFINED__ newSVpvn_utf8(s, len, u) newSVpvn_flags((s), (len), (u) ? SVf_UTF8 : 0) |
30 | |
31 | __UNDEFINED__ SVf_UTF8 0 |
32 | |
33 | #ifndef newSVpvn_flags |
34 | |
35 | #if { NEED newSVpvn_flags } |
36 | |
37 | SV * |
38 | newSVpvn_flags(pTHX_ const char *s, STRLEN len, U32 flags) |
39 | { |
40 | SV *sv = newSVpvn(s, len); |
41 | SvFLAGS(sv) |= (flags & SVf_UTF8); |
42 | return (flags & SVs_TEMP) ? sv_2mortal(sv) : sv; |
43 | } |
44 | |
45 | #endif |
46 | |
47 | #endif |
48 | |
49 | =xsinit |
50 | |
51 | #define NEED_newSVpvn_flags |
52 | |
53 | =xsubs |
54 | |
55 | void |
56 | newSVpvn() |
57 | PPCODE: |
58 | mXPUSHs(newSVpvn("test", 4)); |
59 | mXPUSHs(newSVpvn("test", 2)); |
60 | mXPUSHs(newSVpvn("test", 0)); |
61 | mXPUSHs(newSVpvn(NULL, 2)); |
62 | mXPUSHs(newSVpvn(NULL, 0)); |
63 | XSRETURN(5); |
64 | |
65 | void |
66 | newSVpvn_flags() |
67 | PPCODE: |
68 | XPUSHs(newSVpvn_flags("test", 4, SVs_TEMP)); |
69 | XPUSHs(newSVpvn_flags("test", 2, SVs_TEMP)); |
70 | XPUSHs(newSVpvn_flags("test", 0, SVs_TEMP)); |
71 | XPUSHs(newSVpvn_flags(NULL, 2, SVs_TEMP)); |
72 | XPUSHs(newSVpvn_flags(NULL, 0, SVs_TEMP)); |
73 | XSRETURN(5); |
74 | |
75 | void |
76 | newSVpvn_utf8() |
77 | PPCODE: |
78 | XPUSHs(newSVpvn_flags("test", 4, SVs_TEMP|SVf_UTF8)); |
79 | XSRETURN(1); |
80 | |
81 | =tests plan => 15 |
82 | |
83 | my @s = &Devel::PPPort::newSVpvn(); |
84 | ok(@s == 5); |
85 | ok($s[0], "test"); |
86 | ok($s[1], "te"); |
87 | ok($s[2], ""); |
88 | ok(!defined($s[3])); |
89 | ok(!defined($s[4])); |
90 | |
91 | @s = &Devel::PPPort::newSVpvn_flags(); |
92 | ok(@s == 5); |
93 | ok($s[0], "test"); |
94 | ok($s[1], "te"); |
95 | ok($s[2], ""); |
96 | ok(!defined($s[3])); |
97 | ok(!defined($s[4])); |
98 | |
99 | @s = &Devel::PPPort::newSVpvn_utf8(); |
100 | ok(@s == 1); |
101 | ok($s[0], "test"); |
102 | |
103 | if ($] >= 5.008001) { |
104 | require utf8; |
105 | ok(utf8::is_utf8($s[0])); |
106 | } |
107 | else { |
108 | skip("skip: no is_utf8()", 0); |
109 | } |