line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# [[[ HEADER ]]] |
2
|
|
|
|
|
|
|
package RPerl::DataType::String; |
3
|
7
|
|
|
7
|
|
1855
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
156
|
|
4
|
7
|
|
|
7
|
|
31
|
use warnings; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
150
|
|
5
|
7
|
|
|
7
|
|
30
|
use RPerl::AfterSubclass; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
932
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.013_000; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# [[[ OO INHERITANCE ]]] |
9
|
7
|
|
|
7
|
|
41
|
use parent qw(RPerl::DataType::Scalar); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
33
|
|
10
|
7
|
|
|
7
|
|
377
|
use RPerl::DataType::Scalar; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
173
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# [[[ CRITICS ]]] |
13
|
|
|
|
|
|
|
## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils |
14
|
|
|
|
|
|
|
## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# [[[ SUB-TYPES ]]] |
17
|
|
|
|
|
|
|
# a string is 0 or more letters, digits, or other ASCII (Unicode???) symbols |
18
|
|
|
|
|
|
|
package # hide from PAUSE indexing |
19
|
|
|
|
|
|
|
string; |
20
|
7
|
|
|
7
|
|
34
|
use strict; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
149
|
|
21
|
7
|
|
|
7
|
|
32
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
185
|
|
22
|
7
|
|
|
7
|
|
39
|
use parent qw(RPerl::DataType::String); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
23
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# [[[ PRE-DECLARED TYPES ]]] |
25
|
|
|
|
|
|
|
package # hide from PAUSE indexing |
26
|
|
|
|
|
|
|
boolean; |
27
|
|
|
|
|
|
|
package # hide from PAUSE indexing |
28
|
|
|
|
|
|
|
unsigned_integer; |
29
|
|
|
|
|
|
|
package # hide from PAUSE indexing |
30
|
|
|
|
|
|
|
integer; |
31
|
|
|
|
|
|
|
package # hide from PAUSE indexing |
32
|
|
|
|
|
|
|
number; |
33
|
|
|
|
|
|
|
package # hide from PAUSE indexing |
34
|
|
|
|
|
|
|
character; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE ]]] |
37
|
|
|
|
|
|
|
package RPerl::DataType::String; |
38
|
7
|
|
|
7
|
|
462
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
110
|
|
39
|
7
|
|
|
7
|
|
25
|
use warnings; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
158
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# [[[ INCLUDES ]]] |
42
|
7
|
|
|
7
|
|
28
|
use POSIX qw(floor); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
39
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# DEV NOTE: do not put inside INIT{} block, because it will be "too late to run INIT block" in some cases, such as inside Catalyst |
45
|
|
|
|
|
|
|
# DEV NOTE, CORRELATION #rp040: fix recursive dependencies of String.pm & HelperFunctions_cpp.pm, as triggered by ingy's Inline::create_config_file() system() call |
46
|
|
|
|
|
|
|
# NEED REMOVE: this code no longer appears to be necessary? |
47
|
|
|
|
|
|
|
#if (not ((exists $ARGV[0]) and (defined $ARGV[0]) and ((substr $ARGV[0], -7, 7) eq '_Inline'))) { |
48
|
|
|
|
|
|
|
#if (0) { |
49
|
|
|
|
|
|
|
# use RPerl::HelperFunctions_cpp; # main::RPerl_SvPOKp |
50
|
|
|
|
|
|
|
# RPerl::HelperFunctions_cpp::cpp_load(); |
51
|
|
|
|
|
|
|
#} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# [[[ EXPORTS ]]] |
54
|
7
|
|
|
7
|
|
490
|
use RPerl::Exporter 'import'; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
35
|
|
55
|
|
|
|
|
|
|
our @EXPORT = qw(string_CHECK string_CHECKTRACE string_to_boolean string_to_unsigned_integer string_to_integer string_to_number string_to_character string_to_string); |
56
|
|
|
|
|
|
|
our @EXPORT_OK = qw(string__typetest0 string__typetest1); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# [[[ TYPE CHECKING ]]] |
59
|
|
|
|
|
|
|
sub string_CHECK { |
60
|
0
|
|
|
0
|
|
0
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
61
|
0
|
|
|
|
|
0
|
( my $possible_string ) = @ARG; |
62
|
0
|
0
|
|
|
|
0
|
if ( not( defined $possible_string ) ) { |
63
|
|
|
|
|
|
|
# croak( "\nERROR EPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but undefined/null value found,\ncroaking" ); |
64
|
0
|
|
|
|
|
0
|
die( "\nERROR EPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but undefined/null value found,\ndying\n" ); |
65
|
|
|
|
|
|
|
} |
66
|
0
|
0
|
|
|
|
0
|
if ( not( main::RPerl_SvPOKp($possible_string) ) ) { |
67
|
|
|
|
|
|
|
# croak( "\nERROR EPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but non-string value found,\ncroaking" ); |
68
|
0
|
|
|
|
|
0
|
die( "\nERROR EPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but non-string value found,\ndying\n" ); |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
0
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# DEV NOTE: avoid error for those packages which do NOT 'use RPerl', but instead do 'use RPerl::AfterSubclass' and 'use RPerl::Config' and 'use rperltypesconv' etc. |
74
|
|
|
|
|
|
|
# "Undefined subroutine &RPerl::DataType::String::string_CHECKTRACE called at lib/RPerl/DataType/String.pm line XYZ [ in string_to_integer() below ] |
75
|
|
|
|
|
|
|
sub string_CHECKTRACE { |
76
|
39
|
|
|
39
|
|
55
|
{ my void $RETURN_TYPE }; |
|
39
|
|
|
|
|
54
|
|
77
|
39
|
|
|
|
|
77
|
( my $possible_string, my $variable_name, my $subroutine_name ) = @ARG; |
78
|
39
|
100
|
|
|
|
84
|
if ( not( defined $possible_string ) ) { |
79
|
|
|
|
|
|
|
# croak( "\nERROR EPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" ); |
80
|
4
|
|
|
|
|
34
|
die( "\nERROR EPV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ndying\n" ); |
81
|
|
|
|
|
|
|
} |
82
|
35
|
100
|
|
|
|
97
|
if ( not( main::RPerl_SvPOKp($possible_string) ) ) { |
83
|
|
|
|
|
|
|
# croak( "\nERROR EPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but non-string value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" ); |
84
|
10
|
|
|
|
|
70
|
die( "\nERROR EPV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nstring value expected but non-string value found,\nin variable $variable_name from subroutine $subroutine_name,\ndying\n" ); |
85
|
|
|
|
|
|
|
} |
86
|
25
|
|
|
|
|
43
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# [[[ BOOLEANIFY ]]] |
90
|
|
|
|
|
|
|
sub string_to_boolean { |
91
|
0
|
|
|
0
|
|
0
|
{ my boolean $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
92
|
0
|
|
|
|
|
0
|
(my string $input_string) = @ARG; |
93
|
|
|
|
|
|
|
# string_CHECK($input_string); |
94
|
0
|
|
|
|
|
0
|
string_CHECKTRACE( $input_string, '$input_string', 'string_to_boolean()' ); |
95
|
0
|
|
|
|
|
0
|
$input_string =~ s/_//gxms; # remove underscores to allow them in $input_string, fixes "Argument isn't numeric in multiplication (*)" |
96
|
0
|
0
|
|
|
|
0
|
if (($input_string * 1) == 0) { return 0; } |
|
0
|
|
|
|
|
0
|
|
97
|
0
|
|
|
|
|
0
|
else { return 1; } |
98
|
0
|
|
|
|
|
0
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# [[[ UNSIGNED INTEGERIFY ]]] |
102
|
|
|
|
|
|
|
sub string_to_unsigned_integer { |
103
|
0
|
|
|
0
|
|
0
|
{ my integer $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
104
|
0
|
|
|
|
|
0
|
(my string $input_string) = @ARG; |
105
|
|
|
|
|
|
|
# string_CHECK($input_string); |
106
|
0
|
|
|
|
|
0
|
string_CHECKTRACE( $input_string, '$input_string', 'string_to_unsigned_integer()' ); |
107
|
0
|
|
|
|
|
0
|
$input_string =~ s/_//gxms; # remove underscores to allow them in $input_string, fixes "Argument isn't numeric in multiplication (*)" |
108
|
0
|
|
|
|
|
0
|
return (floor abs ($input_string * 1)) * 1; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# [[[ INTEGERIFY ]]] |
112
|
|
|
|
|
|
|
sub string_to_integer { |
113
|
0
|
|
|
0
|
|
0
|
{ my integer $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
114
|
0
|
|
|
|
|
0
|
(my string $input_string) = @ARG; |
115
|
|
|
|
|
|
|
# string_CHECK($input_string); |
116
|
0
|
|
|
|
|
0
|
string_CHECKTRACE( $input_string, '$input_string', 'string_to_integer()' ); |
117
|
|
|
|
|
|
|
# DEV NOTE: must use double-casting via '* 1' below to avoid following errors |
118
|
|
|
|
|
|
|
# ERROR EIV01, TYPE-CHECKING MISMATCH, CPPOPS_PERLTYPES & CPPOPS_CPPTYPES: |
119
|
|
|
|
|
|
|
# integer value expected but non-integer value found, |
120
|
|
|
|
|
|
|
# in variable input_sv from subroutine XS_unpack_integer(), |
121
|
0
|
|
|
|
|
0
|
$input_string =~ s/_//gxms; # remove underscores to allow them in $input_string, fixes "Argument isn't numeric in multiplication (*)" |
122
|
|
|
|
|
|
|
# return floor ($input_string * 1); |
123
|
0
|
|
|
|
|
0
|
return (floor ($input_string * 1)) * 1; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# [[[ NUMBERIFY ]]] |
127
|
|
|
|
|
|
|
sub string_to_number { |
128
|
0
|
|
|
0
|
|
0
|
{ my number $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
129
|
0
|
|
|
|
|
0
|
(my string $input_string) = @ARG; |
130
|
|
|
|
|
|
|
# string_CHECK($input_string); |
131
|
0
|
|
|
|
|
0
|
string_CHECKTRACE( $input_string, '$input_string', 'string_to_number()' ); |
132
|
0
|
|
|
|
|
0
|
$input_string =~ s/_//gxms; # remove underscores to allow them in $input_string, fixes "Argument isn't numeric in multiplication (*)" |
133
|
0
|
|
|
|
|
0
|
return $input_string * 1.0; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# [[[ CHARACTERIFY ]]] |
137
|
|
|
|
|
|
|
sub string_to_character { |
138
|
0
|
|
|
0
|
|
0
|
{ my character $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
139
|
0
|
|
|
|
|
0
|
(my string $input_string) = @ARG; |
140
|
|
|
|
|
|
|
# string_CHECK($input_string); |
141
|
0
|
|
|
|
|
0
|
string_CHECKTRACE( $input_string, '$input_string', 'string_to_character()' ); |
142
|
0
|
0
|
|
|
|
0
|
if ($input_string eq q{}) { return q{}; } |
|
0
|
|
|
|
|
0
|
|
143
|
0
|
|
|
|
|
0
|
else { return substr $input_string, 0, 1; } |
144
|
0
|
|
|
|
|
0
|
return; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# [[[ STRINGIFY ]]] |
148
|
|
|
|
|
|
|
sub string_to_string { |
149
|
29
|
|
|
29
|
|
12885
|
{ my string $RETURN_TYPE }; |
|
29
|
|
|
|
|
51
|
|
150
|
29
|
|
|
|
|
55
|
( my string $input_string ) = @ARG; |
151
|
|
|
|
|
|
|
# string_CHECK($input_string); |
152
|
29
|
|
|
|
|
719
|
string_CHECKTRACE( $input_string, '$input_string', 'string_to_string()' ); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# RPerl::diag("in PERLOPS_PERLTYPES string_to_string(), received \$input_string =\n$input_string\n\n"); |
155
|
22
|
|
|
|
|
65
|
$input_string =~ s/\\/\\\\/gxms; # escape all back-slash \ characters with another back-slash \ character |
156
|
22
|
|
|
|
|
60
|
$input_string =~ s/\'/\\\'/gxms; # escape all single-quote ' characters with a back-slash \ character |
157
|
22
|
|
|
|
|
53
|
$input_string = "'$input_string'"; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# RPerl::diag("in PERLOPS_PERLTYPES string_to_string(), bottom of subroutine, returning possibly-modified \$input_string =\n$input_string\n\n"); |
160
|
22
|
|
|
|
|
100
|
return ($input_string); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# [[[ TYPE TESTING ]]] |
164
|
|
|
|
|
|
|
sub string__typetest0 { |
165
|
1
|
|
|
1
|
|
4
|
{ my string $RETURN_TYPE }; |
|
1
|
|
|
|
|
3
|
|
166
|
1
|
|
|
|
|
4
|
my string $retval = 'Spice PERLOPS_PERLTYPES'; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# RPerl::diag("in PERLOPS_PERLTYPES string__typetest0(), have \$retval = '$retval'\n"); |
169
|
1
|
|
|
|
|
8
|
return ($retval); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
sub string__typetest1 { |
172
|
10
|
|
|
10
|
|
15
|
{ my string $RETURN_TYPE }; |
|
10
|
|
|
|
|
12
|
|
173
|
10
|
|
|
|
|
57
|
( my string $lucky_string ) = @ARG; |
174
|
|
|
|
|
|
|
# string_CHECK($lucky_string); |
175
|
10
|
|
|
|
|
253
|
string_CHECKTRACE( $lucky_string, '$lucky_string', |
176
|
|
|
|
|
|
|
'string__typetest1()' ); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# RPerl::diag("in PERLOPS_PERLTYPES string__typetest1(), received \$lucky_string = '$lucky_string'\n"); |
179
|
3
|
|
|
|
|
53
|
return ( string_to_string($lucky_string) . ' PERLOPS_PERLTYPES' ); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; # end of class |