line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pugs::Runtime::StrPos; |
2
|
|
|
|
|
|
|
# Documentation in the __END__ |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#use 5.006; ??? |
5
|
22
|
|
|
22
|
|
121
|
use strict; |
|
22
|
|
|
|
|
40
|
|
|
22
|
|
|
|
|
810
|
|
6
|
22
|
|
|
22
|
|
111
|
use warnings; |
|
22
|
|
|
|
|
44
|
|
|
22
|
|
|
|
|
532
|
|
7
|
22
|
|
|
22
|
|
25007
|
use utf8; |
|
22
|
|
|
|
|
236
|
|
|
22
|
|
|
|
|
125
|
|
8
|
22
|
|
|
22
|
|
730
|
use Data::Dumper; |
|
22
|
|
|
|
|
42
|
|
|
22
|
|
|
|
|
4672
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use overload ( |
11
|
|
|
|
|
|
|
'bool' => \&bool, |
12
|
|
|
|
|
|
|
'0+' => \&graphs, |
13
|
|
|
|
|
|
|
'++' => sub { |
14
|
0
|
|
|
0
|
|
0
|
$_[0]->{codes} = ($_[0]->add_graphs( 1 ))->{codes}; |
15
|
|
|
|
|
|
|
}, |
16
|
|
|
|
|
|
|
'+=' => sub { |
17
|
0
|
|
|
0
|
|
0
|
$_[0]->{codes} += $_[1]; |
18
|
|
|
|
|
|
|
}, |
19
|
|
|
|
|
|
|
'+' => sub { |
20
|
0
|
|
|
0
|
|
0
|
($_[0]->add_graphs( $_[1] ))->{codes}; |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
'=' => sub { |
23
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
24
|
0
|
|
|
|
|
0
|
bless {%$self}, ref $self; |
25
|
|
|
|
|
|
|
}, |
26
|
22
|
|
|
|
|
447
|
fallback => 1, |
27
|
22
|
|
|
22
|
|
138
|
); |
|
22
|
|
|
|
|
49
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# new({ str => "...", codes => $n }); |
30
|
|
|
|
|
|
|
# $str must be utf-8 |
31
|
|
|
|
|
|
|
# $n can be undef, meaning "nowhere in this string" |
32
|
|
|
|
|
|
|
sub new { |
33
|
0
|
|
|
0
|
0
|
|
return bless $_[1], $_[0]; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# codes is the default perl5 representation |
37
|
|
|
|
|
|
|
# graphs is the default perl6 representation |
38
|
|
|
|
|
|
|
sub from_str_graphs { |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# -- downgrade as appropriate |
41
|
|
|
|
|
|
|
#die "string has invalid internal encoding" |
42
|
0
|
0
|
|
0
|
0
|
|
return from_str_codes( @_ ) |
43
|
|
|
|
|
|
|
unless utf8::is_utf8( $_[1] ); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$_[1] =~ m/^\X{$_[2]}/g; |
46
|
0
|
|
|
|
|
|
return bless { str => $_[1], codes => pos($_[1]) }, $_[0]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub from_str_codes { |
50
|
0
|
|
|
0
|
0
|
|
return bless { str => $_[1], codes => $_[2] }, $_[0]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub from_str { |
54
|
0
|
|
|
0
|
0
|
|
return bless { str => $_[1], codes => pos( $_[1] ) }, $_[0]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub clone { |
58
|
0
|
|
|
0
|
0
|
|
return bless { %{$_[0]} }, ref( $_[0] ); |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub bool { |
62
|
0
|
|
|
0
|
0
|
|
defined $_[0]->{codes} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub codes { |
66
|
0
|
|
|
0
|
0
|
|
$_[0]->{codes} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub bytes { |
70
|
0
|
0
|
|
0
|
0
|
|
return undef unless defined $_[0]->{codes}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# -- downgrade as appropriate |
73
|
|
|
|
|
|
|
#die "string has invalid internal encoding" |
74
|
0
|
0
|
|
|
|
|
return $_[0]->codes |
75
|
|
|
|
|
|
|
unless utf8::is_utf8( $_[0]->{str} ); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $s = substr( $_[0]->{str}, 0, $_[0]->{codes} ); |
78
|
|
|
|
|
|
|
{ |
79
|
22
|
|
|
22
|
|
12647
|
use bytes; |
|
22
|
|
|
|
|
49
|
|
|
22
|
|
|
|
|
218
|
|
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return length( $s ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
#my @bytes = unpack("C*", substr( $_[0]->{str}, 0, $_[0]->{codes} ) ); |
83
|
|
|
|
|
|
|
#print "[",join(",", @bytes),"]\n"; |
84
|
|
|
|
|
|
|
#return scalar @bytes; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub graphs { |
88
|
0
|
0
|
|
0
|
0
|
|
return undef unless defined $_[0]->{codes}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# -- downgrade as appropriate |
91
|
|
|
|
|
|
|
#die "string has invalid internal encoding" |
92
|
0
|
0
|
|
|
|
|
return $_[0]->codes |
93
|
|
|
|
|
|
|
unless utf8::is_utf8( $_[0]->{str} ); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#return scalar( substr( $_[0]->{str}, 0, $_[0]->{codes} ) =~ m/\X/g ); |
96
|
0
|
|
|
|
|
|
my @g = substr( $_[0]->{str}, 0, $_[0]->{codes} ) =~ m/\X/g; |
97
|
0
|
|
|
|
|
|
return scalar @g; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub langs { |
101
|
0
|
|
|
0
|
0
|
|
die "TODO: langs()"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub add_codes { |
105
|
0
|
|
|
0
|
0
|
|
(ref $_[0])->from_str_codes( $_[0]->{str}, $_[0]->codes + $_[1] ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub add_graphs { |
109
|
0
|
|
|
0
|
0
|
|
(ref $_[0])->from_str_graphs( $_[0]->{str}, $_[0]->graphs + $_[1] ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub perl { |
113
|
0
|
|
|
0
|
0
|
|
local $Data::Dumper::Terse = 1; |
114
|
0
|
|
|
|
|
|
local $Data::Dumper::Sortkeys = 1; |
115
|
0
|
|
|
|
|
|
local $Data::Dumper::Pad = ' '; |
116
|
0
|
|
|
|
|
|
return Dumper( $_[0] ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub yaml { |
120
|
0
|
|
|
0
|
0
|
|
require YAML::Syck; |
121
|
|
|
|
|
|
|
# interoperability with other YAML/Syck bindings: |
122
|
0
|
|
|
|
|
|
$YAML::Syck::ImplicitTyping = 1; |
123
|
0
|
|
|
|
|
|
YAML::Syck::Dump( $_[0] ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# for Pugs interoperability |
127
|
|
|
|
|
|
|
sub dump_hs { |
128
|
0
|
|
|
0
|
0
|
|
die "TODO"; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |