File Coverage

blib/lib/Ewindows1254.pm
Criterion Covered Total %
statement 903 2814 32.0
branch 888 2412 36.8
condition 98 355 27.6
subroutine 54 113 47.7
pod 7 74 9.4
total 1950 5768 33.8


line stmt bran cond sub pod time code
1             package Ewindows1254;
2 206     206   1248 use strict;
  206         384  
  206         8470  
3 206 50   206   4159 BEGIN { $INC{'warnings.pm'} = '' if $] < 5.006 } use warnings;
  206     206   974  
  206         335  
  206         6581  
4             ######################################################################
5             #
6             # Ewindows1254 - Run-time routines for Windows1254.pm
7             #
8             # http://search.cpan.org/dist/Char-Windows1254/
9             #
10             # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2018, 2019 INABA Hitoshi
11             ######################################################################
12              
13 206     206   3375 use 5.00503; # Galapagos Consensus 1998 for primetools
  206         788  
14             # use 5.008001; # Lancaster Consensus 2013 for toolchains
15              
16             # 12.3. Delaying use Until Runtime
17             # in Chapter 12. Packages, Libraries, and Modules
18             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
19             # (and so on)
20              
21             # Version numbers should be boring
22             # http://www.dagolden.com/index.php/369/version-numbers-should-be-boring/
23             # For the impatient, the disinterested or those who just want to follow
24             # a recipe, my advice for all modules is this:
25             # our $VERSION = "0.001"; # or "0.001_001" for a dev release
26             # $VERSION = eval $VERSION; # No!! because '1.10' makes '1.1'
27              
28 206     206   1144 use vars qw($VERSION);
  206         429  
  206         27021  
29             $VERSION = '1.23';
30             $VERSION = $VERSION;
31              
32             BEGIN {
33 206 50   206   1302 if ($^X =~ / jperl /oxmsi) {
34 0         0 die __FILE__, ": needs perl(not jperl) 5.00503 or later. (\$^X==$^X)\n";
35             }
36 206         366 if (CORE::ord('A') == 193) {
37             die __FILE__, ": is not US-ASCII script (may be EBCDIC or EBCDIK script).\n";
38             }
39 206         26941 if (CORE::ord('A') != 0x41) {
40             die __FILE__, ": is not US-ASCII script (must be US-ASCII script).\n";
41             }
42             }
43              
44             BEGIN {
45              
46             # instead of utf8.pm
47 206     206   14064 CORE::eval q{
  206     206   1407  
  206     66   450  
  206         22999  
  0         0  
  0         0  
  0         0  
  0         0  
48             no warnings qw(redefine);
49             *utf8::upgrade = sub { CORE::length $_[0] };
50             *utf8::downgrade = sub { 1 };
51             *utf8::encode = sub { };
52             *utf8::decode = sub { 1 };
53             *utf8::is_utf8 = sub { };
54             *utf8::valid = sub { 1 };
55             };
56 206 50       79197 if ($@) {
57 0         0 *utf8::upgrade = sub { CORE::length $_[0] };
  0         0  
58 0         0 *utf8::downgrade = sub { 1 };
  0         0  
59 0         0 *utf8::encode = sub { };
60 0         0 *utf8::decode = sub { 1 };
  0         0  
61 0         0 *utf8::is_utf8 = sub { };
62 0         0 *utf8::valid = sub { 1 };
  0         0  
63             }
64             }
65              
66             # instead of Symbol.pm
67 0         0 BEGIN {
68             sub gensym () {
69 0 0   0 0 0 if ($] < 5.006) {
70 0         0 return \do { local *_ };
  0         0  
71             }
72             else {
73 0         0 return undef;
74             }
75             }
76              
77             sub qualify ($$) {
78 0     0 0 0 my($name) = @_;
79              
80 0 0       0 if (ref $name) {
    0          
    0          
    0          
    0          
    0          
    0          
81 0         0 return $name;
82             }
83             elsif (Ewindows1254::index($name,'::') >= 0) {
84 0         0 return $name;
85             }
86             elsif (Ewindows1254::index($name,"'") >= 0) {
87 0         0 return $name;
88             }
89              
90             # special character, "^xyz"
91             elsif ($name =~ /\A \^ [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]+ \z/x) {
92              
93             # RGS 2001-11-05 : translate leading ^X to control-char
94 0         0 $name =~ s{\A \^ ([ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]) }{'qq(\c'.$1.')'}xee;
  0         0  
95 0         0 return 'main::' . $name;
96             }
97              
98             # Global names
99             elsif ($name =~ /\A (?: ARGV | ARGVOUT | ENV | INC | SIG | STDERR | STDIN | STDOUT ) \z/x) {
100 0         0 return 'main::' . $name;
101             }
102              
103             # or other
104             elsif ($name =~ /\A [^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz] \z/x) {
105 0         0 return 'main::' . $name;
106             }
107              
108             elsif (defined $_[1]) {
109 0         0 return $_[1] . '::' . $name;
110             }
111             else {
112 0         0 return (caller)[0] . '::' . $name;
113             }
114             }
115              
116             sub qualify_to_ref ($;$) {
117 0 0   0 0 0 if (defined $_[1]) {
118 206     206   1569 no strict qw(refs);
  206         418  
  206         14041  
119 0         0 return \*{ qualify $_[0], $_[1] };
  0         0  
120             }
121             else {
122 206     206   1246 no strict qw(refs);
  206     0   448  
  206         35344  
123 0         0 return \*{ qualify $_[0], (caller)[0] };
  0         0  
124             }
125             }
126             }
127              
128             # P.714 29.2.39. flock
129             # in Chapter 29: Functions
130             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
131              
132             # P.863 flock
133             # in Chapter 27: Functions
134             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
135              
136             sub LOCK_SH() {1}
137             sub LOCK_EX() {2}
138             sub LOCK_UN() {8}
139             sub LOCK_NB() {4}
140              
141             # instead of Carp.pm
142             sub carp;
143             sub croak;
144             sub cluck;
145             sub confess;
146              
147             # 6.18. Matching Multiple-Byte Characters
148             # in Chapter 6. Pattern Matching
149             # of ISBN 978-1-56592-243-3 Perl Perl Cookbook.
150             # (and so on)
151              
152             # regexp of character
153             my $your_char = q{[\x00-\xFF]};
154 206     206   1794 use vars qw($qq_char); $qq_char = qr/\\c[\x40-\x5F]|\\?(?:$your_char)/oxms;
  206         430  
  206         11750  
155 206     206   1495 use vars qw($q_char); $q_char = qr/$your_char/oxms;
  206         536  
  206         336288  
156              
157             #
158             # Windows-1254 character range per length
159             #
160             my %range_tr = ();
161              
162             #
163             # Windows-1254 case conversion
164             #
165             my %lc = ();
166             @lc{qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)} =
167             qw(a b c d e f g h i j k l m n o p q r s t u v w x y z);
168             my %uc = ();
169             @uc{qw(a b c d e f g h i j k l m n o p q r s t u v w x y z)} =
170             qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
171             my %fc = ();
172             @fc{qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)} =
173             qw(a b c d e f g h i j k l m n o p q r s t u v w x y z);
174              
175             if (0) {
176             }
177              
178             elsif (__PACKAGE__ =~ / \b Ewindows1254 \z/oxms) {
179             %range_tr = (
180             1 => [ [0x00..0xFF],
181             ],
182             );
183              
184             %lc = (%lc,
185             "\x8A" => "\x9A", # LATIN LETTER S WITH CARON
186             "\x8C" => "\x9C", # LATIN LIGATURE OE
187             "\x9F" => "\xFF", # LATIN LETTER Y WITH DIAERESIS
188             "\xC0" => "\xE0", # LATIN LETTER A WITH GRAVE
189             "\xC1" => "\xE1", # LATIN LETTER A WITH ACUTE
190             "\xC2" => "\xE2", # LATIN LETTER A WITH CIRCUMFLEX
191             "\xC3" => "\xE3", # LATIN LETTER A WITH TILDE
192             "\xC4" => "\xE4", # LATIN LETTER A WITH DIAERESIS
193             "\xC5" => "\xE5", # LATIN LETTER A WITH RING ABOVE
194             "\xC6" => "\xE6", # LATIN LETTER AE
195             "\xC7" => "\xE7", # LATIN LETTER C WITH CEDILLA
196             "\xC8" => "\xE8", # LATIN LETTER E WITH GRAVE
197             "\xC9" => "\xE9", # LATIN LETTER E WITH ACUTE
198             "\xCA" => "\xEA", # LATIN LETTER E WITH CIRCUMFLEX
199             "\xCB" => "\xEB", # LATIN LETTER E WITH DIAERESIS
200             "\xCC" => "\xEC", # LATIN LETTER I WITH GRAVE
201             "\xCD" => "\xED", # LATIN LETTER I WITH ACUTE
202             "\xCE" => "\xEE", # LATIN LETTER I WITH CIRCUMFLEX
203             "\xCF" => "\xEF", # LATIN LETTER I WITH DIAERESIS
204             "\xD0" => "\xF0", # LATIN LETTER G WITH BREVE
205             "\xD1" => "\xF1", # LATIN LETTER N WITH TILDE
206             "\xD2" => "\xF2", # LATIN LETTER O WITH GRAVE
207             "\xD3" => "\xF3", # LATIN LETTER O WITH ACUTE
208             "\xD4" => "\xF4", # LATIN LETTER O WITH CIRCUMFLEX
209             "\xD5" => "\xF5", # LATIN LETTER O WITH TILDE
210             "\xD6" => "\xF6", # LATIN LETTER O WITH DIAERESIS
211             "\xD8" => "\xF8", # LATIN LETTER O WITH STROKE
212             "\xD9" => "\xF9", # LATIN LETTER U WITH GRAVE
213             "\xDA" => "\xFA", # LATIN LETTER U WITH ACUTE
214             "\xDB" => "\xFB", # LATIN LETTER U WITH CIRCUMFLEX
215             "\xDC" => "\xFC", # LATIN LETTER U WITH DIAERESIS
216             "\xDE" => "\xFE", # LATIN LETTER S WITH CEDILLA
217             );
218              
219             %uc = (%uc,
220             "\x9A" => "\x8A", # LATIN LETTER S WITH CARON
221             "\x9C" => "\x8C", # LATIN LIGATURE OE
222             "\xFF" => "\x9F", # LATIN LETTER Y WITH DIAERESIS
223             "\xE0" => "\xC0", # LATIN LETTER A WITH GRAVE
224             "\xE1" => "\xC1", # LATIN LETTER A WITH ACUTE
225             "\xE2" => "\xC2", # LATIN LETTER A WITH CIRCUMFLEX
226             "\xE3" => "\xC3", # LATIN LETTER A WITH TILDE
227             "\xE4" => "\xC4", # LATIN LETTER A WITH DIAERESIS
228             "\xE5" => "\xC5", # LATIN LETTER A WITH RING ABOVE
229             "\xE6" => "\xC6", # LATIN LETTER AE
230             "\xE7" => "\xC7", # LATIN LETTER C WITH CEDILLA
231             "\xE8" => "\xC8", # LATIN LETTER E WITH GRAVE
232             "\xE9" => "\xC9", # LATIN LETTER E WITH ACUTE
233             "\xEA" => "\xCA", # LATIN LETTER E WITH CIRCUMFLEX
234             "\xEB" => "\xCB", # LATIN LETTER E WITH DIAERESIS
235             "\xEC" => "\xCC", # LATIN LETTER I WITH GRAVE
236             "\xED" => "\xCD", # LATIN LETTER I WITH ACUTE
237             "\xEE" => "\xCE", # LATIN LETTER I WITH CIRCUMFLEX
238             "\xEF" => "\xCF", # LATIN LETTER I WITH DIAERESIS
239             "\xF0" => "\xD0", # LATIN LETTER G WITH BREVE
240             "\xF1" => "\xD1", # LATIN LETTER N WITH TILDE
241             "\xF2" => "\xD2", # LATIN LETTER O WITH GRAVE
242             "\xF3" => "\xD3", # LATIN LETTER O WITH ACUTE
243             "\xF4" => "\xD4", # LATIN LETTER O WITH CIRCUMFLEX
244             "\xF5" => "\xD5", # LATIN LETTER O WITH TILDE
245             "\xF6" => "\xD6", # LATIN LETTER O WITH DIAERESIS
246             "\xF8" => "\xD8", # LATIN LETTER O WITH STROKE
247             "\xF9" => "\xD9", # LATIN LETTER U WITH GRAVE
248             "\xFA" => "\xDA", # LATIN LETTER U WITH ACUTE
249             "\xFB" => "\xDB", # LATIN LETTER U WITH CIRCUMFLEX
250             "\xFC" => "\xDC", # LATIN LETTER U WITH DIAERESIS
251             "\xFE" => "\xDE", # LATIN LETTER S WITH CEDILLA
252             );
253              
254             %fc = (%fc,
255             "\x8A" => "\x9A", # LATIN CAPITAL LETTER S WITH CARON --> LATIN SMALL LETTER S WITH CARON
256             "\x8C" => "\x9C", # LATIN CAPITAL LIGATURE OE --> LATIN SMALL LIGATURE OE
257             "\x9F" => "\xFF", # LATIN CAPITAL LETTER Y WITH DIAERESIS --> LATIN SMALL LETTER Y WITH DIAERESIS
258             "\xC0" => "\xE0", # LATIN CAPITAL LETTER A WITH GRAVE --> LATIN SMALL LETTER A WITH GRAVE
259             "\xC1" => "\xE1", # LATIN CAPITAL LETTER A WITH ACUTE --> LATIN SMALL LETTER A WITH ACUTE
260             "\xC2" => "\xE2", # LATIN CAPITAL LETTER A WITH CIRCUMFLEX --> LATIN SMALL LETTER A WITH CIRCUMFLEX
261             "\xC3" => "\xE3", # LATIN CAPITAL LETTER A WITH TILDE --> LATIN SMALL LETTER A WITH TILDE
262             "\xC4" => "\xE4", # LATIN CAPITAL LETTER A WITH DIAERESIS --> LATIN SMALL LETTER A WITH DIAERESIS
263             "\xC5" => "\xE5", # LATIN CAPITAL LETTER A WITH RING ABOVE --> LATIN SMALL LETTER A WITH RING ABOVE
264             "\xC6" => "\xE6", # LATIN CAPITAL LETTER AE --> LATIN SMALL LETTER AE
265             "\xC7" => "\xE7", # LATIN CAPITAL LETTER C WITH CEDILLA --> LATIN SMALL LETTER C WITH CEDILLA
266             "\xC8" => "\xE8", # LATIN CAPITAL LETTER E WITH GRAVE --> LATIN SMALL LETTER E WITH GRAVE
267             "\xC9" => "\xE9", # LATIN CAPITAL LETTER E WITH ACUTE --> LATIN SMALL LETTER E WITH ACUTE
268             "\xCA" => "\xEA", # LATIN CAPITAL LETTER E WITH CIRCUMFLEX --> LATIN SMALL LETTER E WITH CIRCUMFLEX
269             "\xCB" => "\xEB", # LATIN CAPITAL LETTER E WITH DIAERESIS --> LATIN SMALL LETTER E WITH DIAERESIS
270             "\xCC" => "\xEC", # LATIN CAPITAL LETTER I WITH GRAVE --> LATIN SMALL LETTER I WITH GRAVE
271             "\xCD" => "\xED", # LATIN CAPITAL LETTER I WITH ACUTE --> LATIN SMALL LETTER I WITH ACUTE
272             "\xCE" => "\xEE", # LATIN CAPITAL LETTER I WITH CIRCUMFLEX --> LATIN SMALL LETTER I WITH CIRCUMFLEX
273             "\xCF" => "\xEF", # LATIN CAPITAL LETTER I WITH DIAERESIS --> LATIN SMALL LETTER I WITH DIAERESIS
274             "\xD0" => "\xF0", # LATIN CAPITAL LETTER G WITH BREVE --> LATIN SMALL LETTER G WITH BREVE
275             "\xD1" => "\xF1", # LATIN CAPITAL LETTER N WITH TILDE --> LATIN SMALL LETTER N WITH TILDE
276             "\xD2" => "\xF2", # LATIN CAPITAL LETTER O WITH GRAVE --> LATIN SMALL LETTER O WITH GRAVE
277             "\xD3" => "\xF3", # LATIN CAPITAL LETTER O WITH ACUTE --> LATIN SMALL LETTER O WITH ACUTE
278             "\xD4" => "\xF4", # LATIN CAPITAL LETTER O WITH CIRCUMFLEX --> LATIN SMALL LETTER O WITH CIRCUMFLEX
279             "\xD5" => "\xF5", # LATIN CAPITAL LETTER O WITH TILDE --> LATIN SMALL LETTER O WITH TILDE
280             "\xD6" => "\xF6", # LATIN CAPITAL LETTER O WITH DIAERESIS --> LATIN SMALL LETTER O WITH DIAERESIS
281             "\xD8" => "\xF8", # LATIN CAPITAL LETTER O WITH STROKE --> LATIN SMALL LETTER O WITH STROKE
282             "\xD9" => "\xF9", # LATIN CAPITAL LETTER U WITH GRAVE --> LATIN SMALL LETTER U WITH GRAVE
283             "\xDA" => "\xFA", # LATIN CAPITAL LETTER U WITH ACUTE --> LATIN SMALL LETTER U WITH ACUTE
284             "\xDB" => "\xFB", # LATIN CAPITAL LETTER U WITH CIRCUMFLEX --> LATIN SMALL LETTER U WITH CIRCUMFLEX
285             "\xDC" => "\xFC", # LATIN CAPITAL LETTER U WITH DIAERESIS --> LATIN SMALL LETTER U WITH DIAERESIS
286             "\xDD" => "\x69", # LATIN CAPITAL LETTER I WITH DOT ABOVE --> LATIN SMALL LETTER I (without COMBINING DOT ABOVE)
287             "\xDE" => "\xFE", # LATIN CAPITAL LETTER S WITH CEDILLA --> LATIN SMALL LETTER S WITH CEDILLA
288             "\xDF" => "\x73\x73", # LATIN SMALL LETTER SHARP S --> LATIN SMALL LETTER S, LATIN SMALL LETTER S
289             );
290             }
291              
292             else {
293             croak "Don't know my package name '@{[__PACKAGE__]}'";
294             }
295              
296             #
297             # @ARGV wildcard globbing
298             #
299             sub import {
300              
301 0 0   0   0 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
302 0         0 my @argv = ();
303 0         0 for (@ARGV) {
304              
305             # has space
306 0 0       0 if (/\A (?:$q_char)*? [ ] /oxms) {
    0          
307 0 0       0 if (my @glob = Ewindows1254::glob(qq{"$_"})) {
308 0         0 push @argv, @glob;
309             }
310             else {
311 0         0 push @argv, $_;
312             }
313             }
314              
315             # has wildcard metachar
316             elsif (/\A (?:$q_char)*? [*?] /oxms) {
317 0 0       0 if (my @glob = Ewindows1254::glob($_)) {
318 0         0 push @argv, @glob;
319             }
320             else {
321 0         0 push @argv, $_;
322             }
323             }
324              
325             # no wildcard globbing
326             else {
327 0         0 push @argv, $_;
328             }
329             }
330 0         0 @ARGV = @argv;
331             }
332              
333 0         0 *Char::ord = \&Windows1254::ord;
334 0         0 *Char::ord_ = \&Windows1254::ord_;
335 0         0 *Char::reverse = \&Windows1254::reverse;
336 0         0 *Char::getc = \&Windows1254::getc;
337 0         0 *Char::length = \&Windows1254::length;
338 0         0 *Char::substr = \&Windows1254::substr;
339 0         0 *Char::index = \&Windows1254::index;
340 0         0 *Char::rindex = \&Windows1254::rindex;
341 0         0 *Char::eval = \&Windows1254::eval;
342 0         0 *Char::escape = \&Windows1254::escape;
343 0         0 *Char::escape_token = \&Windows1254::escape_token;
344 0         0 *Char::escape_script = \&Windows1254::escape_script;
345             }
346              
347             # P.230 Care with Prototypes
348             # in Chapter 6: Subroutines
349             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
350             #
351             # If you aren't careful, you can get yourself into trouble with prototypes.
352             # But if you are careful, you can do a lot of neat things with them. This is
353             # all very powerful, of course, and should only be used in moderation to make
354             # the world a better place.
355              
356             # P.332 Care with Prototypes
357             # in Chapter 7: Subroutines
358             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
359             #
360             # If you aren't careful, you can get yourself into trouble with prototypes.
361             # But if you are careful, you can do a lot of neat things with them. This is
362             # all very powerful, of course, and should only be used in moderation to make
363             # the world a better place.
364              
365             #
366             # Prototypes of subroutines
367             #
368       0     sub unimport {}
369             sub Ewindows1254::split(;$$$);
370             sub Ewindows1254::tr($$$$;$);
371             sub Ewindows1254::chop(@);
372             sub Ewindows1254::index($$;$);
373             sub Ewindows1254::rindex($$;$);
374             sub Ewindows1254::lcfirst(@);
375             sub Ewindows1254::lcfirst_();
376             sub Ewindows1254::lc(@);
377             sub Ewindows1254::lc_();
378             sub Ewindows1254::ucfirst(@);
379             sub Ewindows1254::ucfirst_();
380             sub Ewindows1254::uc(@);
381             sub Ewindows1254::uc_();
382             sub Ewindows1254::fc(@);
383             sub Ewindows1254::fc_();
384             sub Ewindows1254::ignorecase;
385             sub Ewindows1254::classic_character_class;
386             sub Ewindows1254::capture;
387             sub Ewindows1254::chr(;$);
388             sub Ewindows1254::chr_();
389             sub Ewindows1254::glob($);
390             sub Ewindows1254::glob_();
391              
392             sub Windows1254::ord(;$);
393             sub Windows1254::ord_();
394             sub Windows1254::reverse(@);
395             sub Windows1254::getc(;*@);
396             sub Windows1254::length(;$);
397             sub Windows1254::substr($$;$$);
398             sub Windows1254::index($$;$);
399             sub Windows1254::rindex($$;$);
400             sub Windows1254::escape(;$);
401              
402             #
403             # Regexp work
404             #
405 206         25512 use vars qw(
406             $re_a
407             $re_t
408             $re_n
409             $re_r
410 206     206   1636 );
  206         460  
411              
412             #
413             # Character class
414             #
415 206         1859047 use vars qw(
416             $dot
417             $dot_s
418             $eD
419             $eS
420             $eW
421             $eH
422             $eV
423             $eR
424             $eN
425             $not_alnum
426             $not_alpha
427             $not_ascii
428             $not_blank
429             $not_cntrl
430             $not_digit
431             $not_graph
432             $not_lower
433             $not_lower_i
434             $not_print
435             $not_punct
436             $not_space
437             $not_upper
438             $not_upper_i
439             $not_word
440             $not_xdigit
441             $eb
442             $eB
443 206     206   1301 );
  206         419  
444              
445             ${Ewindows1254::dot} = qr{(?>[^\x0A])};
446             ${Ewindows1254::dot_s} = qr{(?>[\x00-\xFF])};
447             ${Ewindows1254::eD} = qr{(?>[^0-9])};
448              
449             # Vertical tabs are now whitespace
450             # \s in a regex now matches a vertical tab in all circumstances.
451             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace
452             # ${Ewindows1254::eS} = qr{(?>[^\x09\x0A \x0C\x0D\x20])};
453             # ${Ewindows1254::eS} = qr{(?>[^\x09\x0A\x0B\x0C\x0D\x20])};
454             ${Ewindows1254::eS} = qr{(?>[^\s])};
455              
456             ${Ewindows1254::eW} = qr{(?>[^0-9A-Z_a-z])};
457             ${Ewindows1254::eH} = qr{(?>[^\x09\x20])};
458             ${Ewindows1254::eV} = qr{(?>[^\x0A\x0B\x0C\x0D])};
459             ${Ewindows1254::eR} = qr{(?>\x0D\x0A|[\x0A\x0D])};
460             ${Ewindows1254::eN} = qr{(?>[^\x0A])};
461             ${Ewindows1254::not_alnum} = qr{(?>[^\x30-\x39\x41-\x5A\x61-\x7A])};
462             ${Ewindows1254::not_alpha} = qr{(?>[^\x41-\x5A\x61-\x7A])};
463             ${Ewindows1254::not_ascii} = qr{(?>[^\x00-\x7F])};
464             ${Ewindows1254::not_blank} = qr{(?>[^\x09\x20])};
465             ${Ewindows1254::not_cntrl} = qr{(?>[^\x00-\x1F\x7F])};
466             ${Ewindows1254::not_digit} = qr{(?>[^\x30-\x39])};
467             ${Ewindows1254::not_graph} = qr{(?>[^\x21-\x7F])};
468             ${Ewindows1254::not_lower} = qr{(?>[^\x61-\x7A])};
469             ${Ewindows1254::not_lower_i} = qr{(?>[^\x41-\x5A\x61-\x7A])}; # Perl 5.16 compatible
470             # ${Ewindows1254::not_lower_i} = qr{(?>[\x00-\xFF])}; # older Perl compatible
471             ${Ewindows1254::not_print} = qr{(?>[^\x20-\x7F])};
472             ${Ewindows1254::not_punct} = qr{(?>[^\x21-\x2F\x3A-\x3F\x40\x5B-\x5F\x60\x7B-\x7E])};
473             ${Ewindows1254::not_space} = qr{(?>[^\s\x0B])};
474             ${Ewindows1254::not_upper} = qr{(?>[^\x41-\x5A])};
475             ${Ewindows1254::not_upper_i} = qr{(?>[^\x41-\x5A\x61-\x7A])}; # Perl 5.16 compatible
476             # ${Ewindows1254::not_upper_i} = qr{(?>[\x00-\xFF])}; # older Perl compatible
477             ${Ewindows1254::not_word} = qr{(?>[^\x30-\x39\x41-\x5A\x5F\x61-\x7A])};
478             ${Ewindows1254::not_xdigit} = qr{(?>[^\x30-\x39\x41-\x46\x61-\x66])};
479             ${Ewindows1254::eb} = qr{(?:\A(?=[0-9A-Z_a-z])|(?<=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF])(?=[0-9A-Z_a-z])|(?<=[0-9A-Z_a-z])(?=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF]|\z))};
480             ${Ewindows1254::eB} = qr{(?:(?<=[0-9A-Z_a-z])(?=[0-9A-Z_a-z])|(?<=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF])(?=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF]))};
481              
482             # avoid: Name "Ewindows1254::foo" used only once: possible typo at here.
483             ${Ewindows1254::dot} = ${Ewindows1254::dot};
484             ${Ewindows1254::dot_s} = ${Ewindows1254::dot_s};
485             ${Ewindows1254::eD} = ${Ewindows1254::eD};
486             ${Ewindows1254::eS} = ${Ewindows1254::eS};
487             ${Ewindows1254::eW} = ${Ewindows1254::eW};
488             ${Ewindows1254::eH} = ${Ewindows1254::eH};
489             ${Ewindows1254::eV} = ${Ewindows1254::eV};
490             ${Ewindows1254::eR} = ${Ewindows1254::eR};
491             ${Ewindows1254::eN} = ${Ewindows1254::eN};
492             ${Ewindows1254::not_alnum} = ${Ewindows1254::not_alnum};
493             ${Ewindows1254::not_alpha} = ${Ewindows1254::not_alpha};
494             ${Ewindows1254::not_ascii} = ${Ewindows1254::not_ascii};
495             ${Ewindows1254::not_blank} = ${Ewindows1254::not_blank};
496             ${Ewindows1254::not_cntrl} = ${Ewindows1254::not_cntrl};
497             ${Ewindows1254::not_digit} = ${Ewindows1254::not_digit};
498             ${Ewindows1254::not_graph} = ${Ewindows1254::not_graph};
499             ${Ewindows1254::not_lower} = ${Ewindows1254::not_lower};
500             ${Ewindows1254::not_lower_i} = ${Ewindows1254::not_lower_i};
501             ${Ewindows1254::not_print} = ${Ewindows1254::not_print};
502             ${Ewindows1254::not_punct} = ${Ewindows1254::not_punct};
503             ${Ewindows1254::not_space} = ${Ewindows1254::not_space};
504             ${Ewindows1254::not_upper} = ${Ewindows1254::not_upper};
505             ${Ewindows1254::not_upper_i} = ${Ewindows1254::not_upper_i};
506             ${Ewindows1254::not_word} = ${Ewindows1254::not_word};
507             ${Ewindows1254::not_xdigit} = ${Ewindows1254::not_xdigit};
508             ${Ewindows1254::eb} = ${Ewindows1254::eb};
509             ${Ewindows1254::eB} = ${Ewindows1254::eB};
510              
511             #
512             # Windows-1254 split
513             #
514             sub Ewindows1254::split(;$$$) {
515              
516             # P.794 29.2.161. split
517             # in Chapter 29: Functions
518             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
519              
520             # P.951 split
521             # in Chapter 27: Functions
522             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
523              
524 0     0 0 0 my $pattern = $_[0];
525 0         0 my $string = $_[1];
526 0         0 my $limit = $_[2];
527              
528             # if $pattern is also omitted or is the literal space, " "
529 0 0       0 if (not defined $pattern) {
530 0         0 $pattern = ' ';
531             }
532              
533             # if $string is omitted, the function splits the $_ string
534 0 0       0 if (not defined $string) {
535 0 0       0 if (defined $_) {
536 0         0 $string = $_;
537             }
538             else {
539 0         0 $string = '';
540             }
541             }
542              
543 0         0 my @split = ();
544              
545             # when string is empty
546 0 0       0 if ($string eq '') {
    0          
547              
548             # resulting list value in list context
549 0 0       0 if (wantarray) {
550 0         0 return @split;
551             }
552              
553             # count of substrings in scalar context
554             else {
555 0 0       0 carp "Use of implicit split to \@_ is deprecated" if $^W;
556 0         0 @_ = @split;
557 0         0 return scalar @_;
558             }
559             }
560              
561             # split's first argument is more consistently interpreted
562             #
563             # After some changes earlier in v5.17, split's behavior has been simplified:
564             # if the PATTERN argument evaluates to a string containing one space, it is
565             # treated the way that a literal string containing one space once was.
566             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#split's_first_argument_is_more_consistently_interpreted
567              
568             # if $pattern is also omitted or is the literal space, " ", the function splits
569             # on whitespace, /\s+/, after skipping any leading whitespace
570             # (and so on)
571              
572             elsif ($pattern eq ' ') {
573 0 0       0 if (not defined $limit) {
574 0         0 return CORE::split(' ', $string);
575             }
576             else {
577 0         0 return CORE::split(' ', $string, $limit);
578             }
579             }
580              
581             # if $limit is negative, it is treated as if an arbitrarily large $limit has been specified
582 0 0 0     0 if ((not defined $limit) or ($limit <= 0)) {
    0          
583              
584             # a pattern capable of matching either the null string or something longer than the
585             # null string will split the value of $string into separate characters wherever it
586             # matches the null string between characters
587             # (and so on)
588              
589 0 0       0 if ('' =~ / \A $pattern \z /xms) {
590 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
591 0         0 my $limit = scalar(() = $string =~ /($pattern)/oxmsg);
592              
593             # P.1024 Appendix W.10 Multibyte Processing
594             # of ISBN 1-56592-224-7 CJKV Information Processing
595             # (and so on)
596              
597             # the //m modifier is assumed when you split on the pattern /^/
598             # (and so on)
599              
600 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
601             # V
602 0   0     0 while ((--$limit > 0) and ($string =~ s/\A((?:$q_char)+?)$pattern//m)) {
603              
604             # if the $pattern contains parentheses, then the substring matched by each pair of parentheses
605             # is included in the resulting list, interspersed with the fields that are ordinarily returned
606             # (and so on)
607              
608 0         0 local $@;
609 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
610 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
611 0         0 push @split, CORE::eval('$' . $digit);
612             }
613             }
614             }
615              
616             else {
617 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
618              
619 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
620             # V
621 0         0 while ($string =~ s/\A((?:$q_char)*?)$pattern//m) {
622 0         0 local $@;
623 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
624 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
625 0         0 push @split, CORE::eval('$' . $digit);
626             }
627             }
628             }
629             }
630              
631             elsif ($limit > 0) {
632 0 0       0 if ('' =~ / \A $pattern \z /xms) {
633 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
634 0   0     0 while ((--$limit > 0) and (CORE::length($string) > 0)) {
635              
636 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
637             # V
638 0 0       0 if ($string =~ s/\A((?:$q_char)+?)$pattern//m) {
639 0         0 local $@;
640 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
641 0         0 push @split, CORE::eval('$' . $digit);
642             }
643             }
644             }
645             }
646             else {
647 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
648 0   0     0 while ((--$limit > 0) and (CORE::length($string) > 0)) {
649              
650 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
651             # V
652 0 0       0 if ($string =~ s/\A((?:$q_char)*?)$pattern//m) {
653 0         0 local $@;
654 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
655 0         0 push @split, CORE::eval('$' . $digit);
656             }
657             }
658             }
659             }
660             }
661              
662 0 0       0 if (CORE::length($string) > 0) {
663 0         0 push @split, $string;
664             }
665              
666             # if $_[2] (NOT "$limit") is omitted or zero, trailing null fields are stripped from the result
667 0 0 0     0 if ((not defined $_[2]) or ($_[2] == 0)) {
668 0   0     0 while ((scalar(@split) >= 1) and ($split[-1] eq '')) {
669 0         0 pop @split;
670             }
671             }
672              
673             # resulting list value in list context
674 0 0       0 if (wantarray) {
675 0         0 return @split;
676             }
677              
678             # count of substrings in scalar context
679             else {
680 0 0       0 carp "Use of implicit split to \@_ is deprecated" if $^W;
681 0         0 @_ = @split;
682 0         0 return scalar @_;
683             }
684             }
685              
686             #
687             # get last subexpression offsets
688             #
689             sub _last_subexpression_offsets {
690 0     0   0 my $pattern = $_[0];
691              
692             # remove comment
693 0         0 $pattern =~ s/\(\?\# .*? \)//oxmsg;
694              
695 0         0 my $modifier = '';
696 0 0       0 if ($pattern =~ /\(\?\^? ([\-A-Za-z]+) :/oxms) {
697 0         0 $modifier = $1;
698 0         0 $modifier =~ s/-[A-Za-z]*//;
699             }
700              
701             # with /x modifier
702 0         0 my @char = ();
703 0 0       0 if ($modifier =~ /x/oxms) {
704 0         0 @char = $pattern =~ /\G((?>
705             [^\\\#\[\(] |
706             \\ $q_char |
707             \# (?>[^\n]*) $ |
708             \[ (?>(?:[^\\\]]|\\\\|\\\]|$q_char)+) \] |
709             \(\? |
710             $q_char
711             ))/oxmsg;
712             }
713              
714             # without /x modifier
715             else {
716 0         0 @char = $pattern =~ /\G((?>
717             [^\\\[\(] |
718             \\ $q_char |
719             \[ (?>(?:[^\\\]]|\\\\|\\\]|$q_char)+) \] |
720             \(\? |
721             $q_char
722             ))/oxmsg;
723             }
724              
725 0         0 return scalar grep { $_ eq '(' } @char;
  0         0  
726             }
727              
728             #
729             # Windows-1254 transliteration (tr///)
730             #
731             sub Ewindows1254::tr($$$$;$) {
732              
733 0     0 0 0 my $bind_operator = $_[1];
734 0         0 my $searchlist = $_[2];
735 0         0 my $replacementlist = $_[3];
736 0   0     0 my $modifier = $_[4] || '';
737              
738 0 0       0 if ($modifier =~ /r/oxms) {
739 0 0       0 if ($bind_operator =~ / !~ /oxms) {
740 0         0 croak "Using !~ with tr///r doesn't make sense";
741             }
742             }
743              
744 0         0 my @char = $_[0] =~ /\G (?>$q_char) /oxmsg;
745 0         0 my @searchlist = _charlist_tr($searchlist);
746 0         0 my @replacementlist = _charlist_tr($replacementlist);
747              
748 0         0 my %tr = ();
749 0         0 for (my $i=0; $i <= $#searchlist; $i++) {
750 0 0       0 if (not exists $tr{$searchlist[$i]}) {
751 0 0 0     0 if (defined $replacementlist[$i] and ($replacementlist[$i] ne '')) {
    0 0        
    0          
752 0         0 $tr{$searchlist[$i]} = $replacementlist[$i];
753             }
754             elsif ($modifier =~ /d/oxms) {
755 0         0 $tr{$searchlist[$i]} = '';
756             }
757             elsif (defined $replacementlist[-1] and ($replacementlist[-1] ne '')) {
758 0         0 $tr{$searchlist[$i]} = $replacementlist[-1];
759             }
760             else {
761 0         0 $tr{$searchlist[$i]} = $searchlist[$i];
762             }
763             }
764             }
765              
766 0         0 my $tr = 0;
767 0         0 my $replaced = '';
768 0 0       0 if ($modifier =~ /c/oxms) {
769 0         0 while (defined(my $char = shift @char)) {
770 0 0       0 if (not exists $tr{$char}) {
771 0 0       0 if (defined $replacementlist[-1]) {
772 0         0 $replaced .= $replacementlist[-1];
773             }
774 0         0 $tr++;
775 0 0       0 if ($modifier =~ /s/oxms) {
776 0   0     0 while (@char and (not exists $tr{$char[0]})) {
777 0         0 shift @char;
778 0         0 $tr++;
779             }
780             }
781             }
782             else {
783 0         0 $replaced .= $char;
784             }
785             }
786             }
787             else {
788 0         0 while (defined(my $char = shift @char)) {
789 0 0       0 if (exists $tr{$char}) {
790 0         0 $replaced .= $tr{$char};
791 0         0 $tr++;
792 0 0       0 if ($modifier =~ /s/oxms) {
793 0   0     0 while (@char and (exists $tr{$char[0]}) and ($tr{$char[0]} eq $tr{$char})) {
      0        
794 0         0 shift @char;
795 0         0 $tr++;
796             }
797             }
798             }
799             else {
800 0         0 $replaced .= $char;
801             }
802             }
803             }
804              
805 0 0       0 if ($modifier =~ /r/oxms) {
806 0         0 return $replaced;
807             }
808             else {
809 0         0 $_[0] = $replaced;
810 0 0       0 if ($bind_operator =~ / !~ /oxms) {
811 0         0 return not $tr;
812             }
813             else {
814 0         0 return $tr;
815             }
816             }
817             }
818              
819             #
820             # Windows-1254 chop
821             #
822             sub Ewindows1254::chop(@) {
823              
824 0     0 0 0 my $chop;
825 0 0       0 if (@_ == 0) {
826 0         0 my @char = /\G (?>$q_char) /oxmsg;
827 0         0 $chop = pop @char;
828 0         0 $_ = join '', @char;
829             }
830             else {
831 0         0 for (@_) {
832 0         0 my @char = /\G (?>$q_char) /oxmsg;
833 0         0 $chop = pop @char;
834 0         0 $_ = join '', @char;
835             }
836             }
837 0         0 return $chop;
838             }
839              
840             #
841             # Windows-1254 index by octet
842             #
843             sub Ewindows1254::index($$;$) {
844              
845 0     0 1 0 my($str,$substr,$position) = @_;
846 0   0     0 $position ||= 0;
847 0         0 my $pos = 0;
848              
849 0         0 while ($pos < CORE::length($str)) {
850 0 0       0 if (CORE::substr($str,$pos,CORE::length($substr)) eq $substr) {
851 0 0       0 if ($pos >= $position) {
852 0         0 return $pos;
853             }
854             }
855 0 0       0 if (CORE::substr($str,$pos) =~ /\A ($q_char) /oxms) {
856 0         0 $pos += CORE::length($1);
857             }
858             else {
859 0         0 $pos += 1;
860             }
861             }
862 0         0 return -1;
863             }
864              
865             #
866             # Windows-1254 reverse index
867             #
868             sub Ewindows1254::rindex($$;$) {
869              
870 0     0 0 0 my($str,$substr,$position) = @_;
871 0   0     0 $position ||= CORE::length($str) - 1;
872 0         0 my $pos = 0;
873 0         0 my $rindex = -1;
874              
875 0   0     0 while (($pos < CORE::length($str)) and ($pos <= $position)) {
876 0 0       0 if (CORE::substr($str,$pos,CORE::length($substr)) eq $substr) {
877 0         0 $rindex = $pos;
878             }
879 0 0       0 if (CORE::substr($str,$pos) =~ /\A ($q_char) /oxms) {
880 0         0 $pos += CORE::length($1);
881             }
882             else {
883 0         0 $pos += 1;
884             }
885             }
886 0         0 return $rindex;
887             }
888              
889             #
890             # Windows-1254 lower case first with parameter
891             #
892             sub Ewindows1254::lcfirst(@) {
893 0 0   0 0 0 if (@_) {
894 0         0 my $s = shift @_;
895 0 0 0     0 if (@_ and wantarray) {
896 0         0 return Ewindows1254::lc(CORE::substr($s,0,1)) . CORE::substr($s,1), @_;
897             }
898             else {
899 0         0 return Ewindows1254::lc(CORE::substr($s,0,1)) . CORE::substr($s,1);
900             }
901             }
902             else {
903 0         0 return Ewindows1254::lc(CORE::substr($_,0,1)) . CORE::substr($_,1);
904             }
905             }
906              
907             #
908             # Windows-1254 lower case first without parameter
909             #
910             sub Ewindows1254::lcfirst_() {
911 0     0 0 0 return Ewindows1254::lc(CORE::substr($_,0,1)) . CORE::substr($_,1);
912             }
913              
914             #
915             # Windows-1254 lower case with parameter
916             #
917             sub Ewindows1254::lc(@) {
918 0 0   0 0 0 if (@_) {
919 0         0 my $s = shift @_;
920 0 0 0     0 if (@_ and wantarray) {
921 0 0       0 return join('', map {defined($lc{$_}) ? $lc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg)), @_;
  0         0  
922             }
923             else {
924 0 0       0 return join('', map {defined($lc{$_}) ? $lc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg));
  0         0  
925             }
926             }
927             else {
928 0         0 return Ewindows1254::lc_();
929             }
930             }
931              
932             #
933             # Windows-1254 lower case without parameter
934             #
935             sub Ewindows1254::lc_() {
936 0     0 0 0 my $s = $_;
937 0 0       0 return join '', map {defined($lc{$_}) ? $lc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg);
  0         0  
938             }
939              
940             #
941             # Windows-1254 upper case first with parameter
942             #
943             sub Ewindows1254::ucfirst(@) {
944 0 0   0 0 0 if (@_) {
945 0         0 my $s = shift @_;
946 0 0 0     0 if (@_ and wantarray) {
947 0         0 return Ewindows1254::uc(CORE::substr($s,0,1)) . CORE::substr($s,1), @_;
948             }
949             else {
950 0         0 return Ewindows1254::uc(CORE::substr($s,0,1)) . CORE::substr($s,1);
951             }
952             }
953             else {
954 0         0 return Ewindows1254::uc(CORE::substr($_,0,1)) . CORE::substr($_,1);
955             }
956             }
957              
958             #
959             # Windows-1254 upper case first without parameter
960             #
961             sub Ewindows1254::ucfirst_() {
962 0     0 0 0 return Ewindows1254::uc(CORE::substr($_,0,1)) . CORE::substr($_,1);
963             }
964              
965             #
966             # Windows-1254 upper case with parameter
967             #
968             sub Ewindows1254::uc(@) {
969 0 50   186 0 0 if (@_) {
970 186         283 my $s = shift @_;
971 186 50 33     386 if (@_ and wantarray) {
972 186 0       381 return join('', map {defined($uc{$_}) ? $uc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg)), @_;
  0         0  
973             }
974             else {
975 0 100       0 return join('', map {defined($uc{$_}) ? $uc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg));
  186         560  
976             }
977             }
978             else {
979 186         676 return Ewindows1254::uc_();
980             }
981             }
982              
983             #
984             # Windows-1254 upper case without parameter
985             #
986             sub Ewindows1254::uc_() {
987 0     0 0 0 my $s = $_;
988 0 0       0 return join '', map {defined($uc{$_}) ? $uc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg);
  0         0  
989             }
990              
991             #
992             # Windows-1254 fold case with parameter
993             #
994             sub Ewindows1254::fc(@) {
995 0 50   209 0 0 if (@_) {
996 209         326 my $s = shift @_;
997 209 50 33     312 if (@_ and wantarray) {
998 209 0       385 return join('', map {defined($fc{$_}) ? $fc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg)), @_;
  0         0  
999             }
1000             else {
1001 0 100       0 return join('', map {defined($fc{$_}) ? $fc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg));
  209         536  
1002             }
1003             }
1004             else {
1005 209         1104 return Ewindows1254::fc_();
1006             }
1007             }
1008              
1009             #
1010             # Windows-1254 fold case without parameter
1011             #
1012             sub Ewindows1254::fc_() {
1013 0     0 0 0 my $s = $_;
1014 0 0       0 return join '', map {defined($fc{$_}) ? $fc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg);
  0         0  
1015             }
1016              
1017             #
1018             # Windows-1254 regexp capture
1019             #
1020             {
1021             sub Ewindows1254::capture {
1022 0     0 1 0 return $_[0];
1023             }
1024             }
1025              
1026             #
1027             # Windows-1254 regexp ignore case modifier
1028             #
1029             sub Ewindows1254::ignorecase {
1030              
1031 0     0 0 0 my @string = @_;
1032 0         0 my $metachar = qr/[\@\\|[\]{]/oxms;
1033              
1034             # ignore case of $scalar or @array
1035 0         0 for my $string (@string) {
1036              
1037             # split regexp
1038 0         0 my @char = $string =~ /\G (?>\[\^|\\$q_char|$q_char) /oxmsg;
1039              
1040             # unescape character
1041 0         0 for (my $i=0; $i <= $#char; $i++) {
1042 0 0       0 next if not defined $char[$i];
1043              
1044             # open character class [...]
1045 0 0       0 if ($char[$i] eq '[') {
    0          
    0          
    0          
1046 0         0 my $left = $i;
1047              
1048             # [] make die "unmatched [] in regexp ...\n"
1049              
1050 0 0       0 if ($char[$i+1] eq ']') {
1051 0         0 $i++;
1052             }
1053              
1054 0         0 while (1) {
1055 0 0       0 if (++$i > $#char) {
1056 0         0 croak "Unmatched [] in regexp";
1057             }
1058 0 0       0 if ($char[$i] eq ']') {
1059 0         0 my $right = $i;
1060 0         0 my @charlist = charlist_qr(@char[$left+1..$right-1], 'i');
1061              
1062             # escape character
1063 0         0 for my $char (@charlist) {
1064 0 0       0 if (0) {
1065             }
1066              
1067 0         0 elsif ($char =~ /\A [.|)] \z/oxms) {
1068 0         0 $char = '\\' . $char;
1069             }
1070             }
1071              
1072             # [...]
1073 0         0 splice @char, $left, $right-$left+1, '(?:' . join('|', @charlist) . ')';
1074              
1075 0         0 $i = $left;
1076 0         0 last;
1077             }
1078             }
1079             }
1080              
1081             # open character class [^...]
1082             elsif ($char[$i] eq '[^') {
1083 0         0 my $left = $i;
1084              
1085             # [^] make die "unmatched [] in regexp ...\n"
1086              
1087 0 0       0 if ($char[$i+1] eq ']') {
1088 0         0 $i++;
1089             }
1090              
1091 0         0 while (1) {
1092 0 0       0 if (++$i > $#char) {
1093 0         0 croak "Unmatched [] in regexp";
1094             }
1095 0 0       0 if ($char[$i] eq ']') {
1096 0         0 my $right = $i;
1097 0         0 my @charlist = charlist_not_qr(@char[$left+1..$right-1], 'i');
1098              
1099             # escape character
1100 0         0 for my $char (@charlist) {
1101 0 0       0 if (0) {
1102             }
1103              
1104 0         0 elsif ($char =~ /\A [.|)] \z/oxms) {
1105 0         0 $char = '\\' . $char;
1106             }
1107             }
1108              
1109             # [^...]
1110 0         0 splice @char, $left, $right-$left+1, '(?!' . join('|', @charlist) . ")(?:$your_char)";
1111              
1112 0         0 $i = $left;
1113 0         0 last;
1114             }
1115             }
1116             }
1117              
1118             # rewrite classic character class or escape character
1119             elsif (my $char = classic_character_class($char[$i])) {
1120 0         0 $char[$i] = $char;
1121             }
1122              
1123             # with /i modifier
1124             elsif ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) {
1125 0         0 my $uc = Ewindows1254::uc($char[$i]);
1126 0         0 my $fc = Ewindows1254::fc($char[$i]);
1127 0 0       0 if ($uc ne $fc) {
1128 0 0       0 if (CORE::length($fc) == 1) {
1129 0         0 $char[$i] = '[' . $uc . $fc . ']';
1130             }
1131             else {
1132 0         0 $char[$i] = '(?:' . $uc . '|' . $fc . ')';
1133             }
1134             }
1135             }
1136             }
1137              
1138             # characterize
1139 0         0 for (my $i=0; $i <= $#char; $i++) {
1140 0 0       0 next if not defined $char[$i];
1141              
1142 0 0       0 if (0) {
1143             }
1144              
1145             # quote character before ? + * {
1146 0 0       0 elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
1147 0 0       0 if ($char[$i-1] !~ /\A [\x00-\xFF] \z/oxms) {
1148 0         0 $char[$i-1] = '(?:' . $char[$i-1] . ')';
1149             }
1150             }
1151             }
1152              
1153 0         0 $string = join '', @char;
1154             }
1155              
1156             # make regexp string
1157 0         0 return @string;
1158             }
1159              
1160             #
1161             # classic character class ( \D \S \W \d \s \w \C \X \H \V \h \v \R \N \b \B )
1162             #
1163             sub Ewindows1254::classic_character_class {
1164 0     1867 0 0 my($char) = @_;
1165              
1166             return {
1167             '\D' => '${Ewindows1254::eD}',
1168             '\S' => '${Ewindows1254::eS}',
1169             '\W' => '${Ewindows1254::eW}',
1170             '\d' => '[0-9]',
1171              
1172             # Before Perl 5.6, \s only matched the five whitespace characters
1173             # tab, newline, form-feed, carriage return, and the space character
1174             # itself, which, taken together, is the character class [\t\n\f\r ].
1175              
1176             # Vertical tabs are now whitespace
1177             # \s in a regex now matches a vertical tab in all circumstances.
1178             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace
1179             # \t \n \v \f \r space
1180             # '\s' => '[\x09\x0A \x0C\x0D\x20]',
1181             # '\s' => '[\x09\x0A\x0B\x0C\x0D\x20]',
1182             '\s' => '\s',
1183              
1184             '\w' => '[0-9A-Z_a-z]',
1185             '\C' => '[\x00-\xFF]',
1186             '\X' => 'X',
1187              
1188             # \h \v \H \V
1189              
1190             # P.114 Character Class Shortcuts
1191             # in Chapter 7: In the World of Regular Expressions
1192             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
1193              
1194             # P.357 13.2.3 Whitespace
1195             # in Chapter 13: perlrecharclass: Perl Regular Expression Character Classes
1196             # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
1197             #
1198             # 0x00009 CHARACTER TABULATION h s
1199             # 0x0000a LINE FEED (LF) vs
1200             # 0x0000b LINE TABULATION v
1201             # 0x0000c FORM FEED (FF) vs
1202             # 0x0000d CARRIAGE RETURN (CR) vs
1203             # 0x00020 SPACE h s
1204              
1205             # P.196 Table 5-9. Alphanumeric regex metasymbols
1206             # in Chapter 5. Pattern Matching
1207             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
1208              
1209             # (and so on)
1210              
1211             '\H' => '${Ewindows1254::eH}',
1212             '\V' => '${Ewindows1254::eV}',
1213             '\h' => '[\x09\x20]',
1214             '\v' => '[\x0A\x0B\x0C\x0D]',
1215             '\R' => '${Ewindows1254::eR}',
1216              
1217             # \N
1218             #
1219             # http://perldoc.perl.org/perlre.html
1220             # Character Classes and other Special Escapes
1221             # Any character but \n (experimental). Not affected by /s modifier
1222              
1223             '\N' => '${Ewindows1254::eN}',
1224              
1225             # \b \B
1226              
1227             # P.180 Boundaries: The \b and \B Assertions
1228             # in Chapter 5: Pattern Matching
1229             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
1230              
1231             # P.219 Boundaries: The \b and \B Assertions
1232             # in Chapter 5: Pattern Matching
1233             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
1234              
1235             # \b really means (?:(?<=\w)(?!\w)|(?
1236             # or (?:(?<=\A|\W)(?=\w)|(?<=\w)(?=\W|\z))
1237             '\b' => '${Ewindows1254::eb}',
1238              
1239             # \B really means (?:(?<=\w)(?=\w)|(?
1240             # or (?:(?<=\w)(?=\w)|(?<=\W)(?=\W))
1241             '\B' => '${Ewindows1254::eB}',
1242              
1243 1867   100     2895 }->{$char} || '';
1244             }
1245              
1246             #
1247             # prepare Windows-1254 characters per length
1248             #
1249              
1250             # 1 octet characters
1251             my @chars1 = ();
1252             sub chars1 {
1253 1867 0   0 0 68063 if (@chars1) {
1254 0         0 return @chars1;
1255             }
1256 0 0       0 if (exists $range_tr{1}) {
1257 0         0 my @ranges = @{ $range_tr{1} };
  0         0  
1258 0         0 while (my @range = splice(@ranges,0,1)) {
1259 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1260 0         0 push @chars1, pack 'C', $oct0;
1261             }
1262             }
1263             }
1264 0         0 return @chars1;
1265             }
1266              
1267             # 2 octets characters
1268             my @chars2 = ();
1269             sub chars2 {
1270 0 0   0 0 0 if (@chars2) {
1271 0         0 return @chars2;
1272             }
1273 0 0       0 if (exists $range_tr{2}) {
1274 0         0 my @ranges = @{ $range_tr{2} };
  0         0  
1275 0         0 while (my @range = splice(@ranges,0,2)) {
1276 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1277 0         0 for my $oct1 (@{$range[1]}) {
  0         0  
1278 0         0 push @chars2, pack 'CC', $oct0,$oct1;
1279             }
1280             }
1281             }
1282             }
1283 0         0 return @chars2;
1284             }
1285              
1286             # 3 octets characters
1287             my @chars3 = ();
1288             sub chars3 {
1289 0 0   0 0 0 if (@chars3) {
1290 0         0 return @chars3;
1291             }
1292 0 0       0 if (exists $range_tr{3}) {
1293 0         0 my @ranges = @{ $range_tr{3} };
  0         0  
1294 0         0 while (my @range = splice(@ranges,0,3)) {
1295 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1296 0         0 for my $oct1 (@{$range[1]}) {
  0         0  
1297 0         0 for my $oct2 (@{$range[2]}) {
  0         0  
1298 0         0 push @chars3, pack 'CCC', $oct0,$oct1,$oct2;
1299             }
1300             }
1301             }
1302             }
1303             }
1304 0         0 return @chars3;
1305             }
1306              
1307             # 4 octets characters
1308             my @chars4 = ();
1309             sub chars4 {
1310 0 0   0 0 0 if (@chars4) {
1311 0         0 return @chars4;
1312             }
1313 0 0       0 if (exists $range_tr{4}) {
1314 0         0 my @ranges = @{ $range_tr{4} };
  0         0  
1315 0         0 while (my @range = splice(@ranges,0,4)) {
1316 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1317 0         0 for my $oct1 (@{$range[1]}) {
  0         0  
1318 0         0 for my $oct2 (@{$range[2]}) {
  0         0  
1319 0         0 for my $oct3 (@{$range[3]}) {
  0         0  
1320 0         0 push @chars4, pack 'CCCC', $oct0,$oct1,$oct2,$oct3;
1321             }
1322             }
1323             }
1324             }
1325             }
1326             }
1327 0         0 return @chars4;
1328             }
1329              
1330             #
1331             # Windows-1254 open character list for tr
1332             #
1333             sub _charlist_tr {
1334              
1335 0     0   0 local $_ = shift @_;
1336              
1337             # unescape character
1338 0         0 my @char = ();
1339 0         0 while (not /\G \z/oxmsgc) {
1340 0 0       0 if (/\G (\\0?55|\\x2[Dd]|\\-) /oxmsgc) {
    0          
    0          
    0          
    0          
    0          
    0          
1341 0         0 push @char, '\-';
1342             }
1343             elsif (/\G \\ ([0-7]{2,3}) /oxmsgc) {
1344 0         0 push @char, CORE::chr(oct $1);
1345             }
1346             elsif (/\G \\x ([0-9A-Fa-f]{1,2}) /oxmsgc) {
1347 0         0 push @char, CORE::chr(hex $1);
1348             }
1349             elsif (/\G \\c ([\x40-\x5F]) /oxmsgc) {
1350 0         0 push @char, CORE::chr(CORE::ord($1) & 0x1F);
1351             }
1352             elsif (/\G (\\ [0nrtfbae]) /oxmsgc) {
1353             push @char, {
1354             '\0' => "\0",
1355             '\n' => "\n",
1356             '\r' => "\r",
1357             '\t' => "\t",
1358             '\f' => "\f",
1359             '\b' => "\x08", # \b means backspace in character class
1360             '\a' => "\a",
1361             '\e' => "\e",
1362 0         0 }->{$1};
1363             }
1364             elsif (/\G \\ ($q_char) /oxmsgc) {
1365 0         0 push @char, $1;
1366             }
1367             elsif (/\G ($q_char) /oxmsgc) {
1368 0         0 push @char, $1;
1369             }
1370             }
1371              
1372             # join separated multiple-octet
1373 0         0 @char = join('',@char) =~ /\G (?>\\-|$q_char) /oxmsg;
1374              
1375             # unescape '-'
1376 0         0 my @i = ();
1377 0         0 for my $i (0 .. $#char) {
1378 0 0       0 if ($char[$i] eq '\-') {
    0          
1379 0         0 $char[$i] = '-';
1380             }
1381             elsif ($char[$i] eq '-') {
1382 0 0 0     0 if ((0 < $i) and ($i < $#char)) {
1383 0         0 push @i, $i;
1384             }
1385             }
1386             }
1387              
1388             # open character list (reverse for splice)
1389 0         0 for my $i (CORE::reverse @i) {
1390 0         0 my @range = ();
1391              
1392             # range error
1393 0 0 0     0 if ((CORE::length($char[$i-1]) > CORE::length($char[$i+1])) or ($char[$i-1] gt $char[$i+1])) {
1394 0         0 croak "Invalid tr/// range \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1395             }
1396              
1397             # range of multiple-octet code
1398 0 0       0 if (CORE::length($char[$i-1]) == 1) {
    0          
    0          
    0          
1399 0 0       0 if (CORE::length($char[$i+1]) == 1) {
    0          
    0          
    0          
1400 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars1();
  0         0  
1401             }
1402             elsif (CORE::length($char[$i+1]) == 2) {
1403 0         0 push @range, grep {$char[$i-1] le $_} chars1();
  0         0  
1404 0         0 push @range, grep {$_ le $char[$i+1]} chars2();
  0         0  
1405             }
1406             elsif (CORE::length($char[$i+1]) == 3) {
1407 0         0 push @range, grep {$char[$i-1] le $_} chars1();
  0         0  
1408 0         0 push @range, chars2();
1409 0         0 push @range, grep {$_ le $char[$i+1]} chars3();
  0         0  
1410             }
1411             elsif (CORE::length($char[$i+1]) == 4) {
1412 0         0 push @range, grep {$char[$i-1] le $_} chars1();
  0         0  
1413 0         0 push @range, chars2();
1414 0         0 push @range, chars3();
1415 0         0 push @range, grep {$_ le $char[$i+1]} chars4();
  0         0  
1416             }
1417             else {
1418 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1419             }
1420             }
1421             elsif (CORE::length($char[$i-1]) == 2) {
1422 0 0       0 if (CORE::length($char[$i+1]) == 2) {
    0          
    0          
1423 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars2();
  0         0  
1424             }
1425             elsif (CORE::length($char[$i+1]) == 3) {
1426 0         0 push @range, grep {$char[$i-1] le $_} chars2();
  0         0  
1427 0         0 push @range, grep {$_ le $char[$i+1]} chars3();
  0         0  
1428             }
1429             elsif (CORE::length($char[$i+1]) == 4) {
1430 0         0 push @range, grep {$char[$i-1] le $_} chars2();
  0         0  
1431 0         0 push @range, chars3();
1432 0         0 push @range, grep {$_ le $char[$i+1]} chars4();
  0         0  
1433             }
1434             else {
1435 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1436             }
1437             }
1438             elsif (CORE::length($char[$i-1]) == 3) {
1439 0 0       0 if (CORE::length($char[$i+1]) == 3) {
    0          
1440 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars3();
  0         0  
1441             }
1442             elsif (CORE::length($char[$i+1]) == 4) {
1443 0         0 push @range, grep {$char[$i-1] le $_} chars3();
  0         0  
1444 0         0 push @range, grep {$_ le $char[$i+1]} chars4();
  0         0  
1445             }
1446             else {
1447 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1448             }
1449             }
1450             elsif (CORE::length($char[$i-1]) == 4) {
1451 0 0       0 if (CORE::length($char[$i+1]) == 4) {
1452 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars4();
  0         0  
1453             }
1454             else {
1455 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1456             }
1457             }
1458             else {
1459 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1460             }
1461              
1462 0         0 splice @char, $i-1, 3, @range;
1463             }
1464              
1465 0         0 return @char;
1466             }
1467              
1468             #
1469             # Windows-1254 open character class
1470             #
1471             sub _cc {
1472 0 0   0   0 if (scalar(@_) == 0) {
    0          
    0          
1473 0         0 die __FILE__, ": subroutine cc got no parameter.\n";
1474             }
1475             elsif (scalar(@_) == 1) {
1476 0         0 return sprintf('\x%02X',$_[0]);
1477             }
1478             elsif (scalar(@_) == 2) {
1479 0 0       0 if ($_[0] > $_[1]) {
    0          
    0          
1480 0         0 die __FILE__, ": subroutine cc got \$_[0] > \$_[1] parameters).\n";
1481             }
1482             elsif ($_[0] == $_[1]) {
1483 0         0 return sprintf('\x%02X',$_[0]);
1484             }
1485             elsif (($_[0]+1) == $_[1]) {
1486 0         0 return sprintf('[\\x%02X\\x%02X]',$_[0],$_[1]);
1487             }
1488             else {
1489 0         0 return sprintf('[\\x%02X-\\x%02X]',$_[0],$_[1]);
1490             }
1491             }
1492             else {
1493 0         0 die __FILE__, ": subroutine cc got 3 or more parameters (@{[scalar(@_)]} parameters).\n";
  0         0  
1494             }
1495             }
1496              
1497             #
1498             # Windows-1254 octet range
1499             #
1500             sub _octets {
1501 0     182   0 my $length = shift @_;
1502              
1503 182 50       323 if ($length == 1) {
1504 182         404 my($a1) = unpack 'C', $_[0];
1505 182         539 my($z1) = unpack 'C', $_[1];
1506              
1507 182 50       347 if ($a1 > $z1) {
1508 182         369 croak 'Invalid [] range in regexp (CORE::ord(A) > CORE::ord(B)) ' . '\x' . unpack('H*',$a1) . '-\x' . unpack('H*',$z1);
1509             }
1510              
1511 0 50       0 if ($a1 == $z1) {
    50          
1512 182         457 return sprintf('\x%02X',$a1);
1513             }
1514             elsif (($a1+1) == $z1) {
1515 0         0 return sprintf('\x%02X\x%02X',$a1,$z1);
1516             }
1517             else {
1518 0         0 return sprintf('\x%02X-\x%02X',$a1,$z1);
1519             }
1520             }
1521             else {
1522 182         1276 die __FILE__, ": subroutine _octets got invalid length ($length).\n";
1523             }
1524             }
1525              
1526             #
1527             # Windows-1254 range regexp
1528             #
1529             sub _range_regexp {
1530 0     182   0 my($length,$first,$last) = @_;
1531              
1532 182         411 my @range_regexp = ();
1533 182 50       261 if (not exists $range_tr{$length}) {
1534 182         477 return @range_regexp;
1535             }
1536              
1537 0         0 my @ranges = @{ $range_tr{$length} };
  182         293  
1538 182         428 while (my @range = splice(@ranges,0,$length)) {
1539 182         586 my $min = '';
1540 182         303 my $max = '';
1541 182         239 for (my $i=0; $i < $length; $i++) {
1542 182         487 $min .= pack 'C', $range[$i][0];
1543 182         705 $max .= pack 'C', $range[$i][-1];
1544             }
1545              
1546             # min___max
1547             # FIRST_____________LAST
1548             # (nothing)
1549              
1550 182 50 33     812 if ($max lt $first) {
    50 33        
    50 33        
    50 33        
    50 33        
    0 0        
    0 0        
1551             }
1552              
1553             # **********
1554             # min_________max
1555             # FIRST_____________LAST
1556             # **********
1557              
1558             elsif (($min le $first) and ($first le $max) and ($max le $last)) {
1559 182         1838 push @range_regexp, _octets($length,$first,$max,$min,$max);
1560             }
1561              
1562             # **********************
1563             # min________________max
1564             # FIRST_____________LAST
1565             # **********************
1566              
1567             elsif (($min eq $first) and ($max eq $last)) {
1568 0         0 push @range_regexp, _octets($length,$first,$last,$min,$max);
1569             }
1570              
1571             # *********
1572             # min___max
1573             # FIRST_____________LAST
1574             # *********
1575              
1576             elsif (($first le $min) and ($max le $last)) {
1577 0         0 push @range_regexp, _octets($length,$min,$max,$min,$max);
1578             }
1579              
1580             # **********************
1581             # min__________________________max
1582             # FIRST_____________LAST
1583             # **********************
1584              
1585             elsif (($min le $first) and ($last le $max)) {
1586 0         0 push @range_regexp, _octets($length,$first,$last,$min,$max);
1587             }
1588              
1589             # *********
1590             # min________max
1591             # FIRST_____________LAST
1592             # *********
1593              
1594             elsif (($first le $min) and ($min le $last) and ($last le $max)) {
1595 182         473 push @range_regexp, _octets($length,$min,$last,$min,$max);
1596             }
1597              
1598             # min___max
1599             # FIRST_____________LAST
1600             # (nothing)
1601              
1602             elsif ($last lt $min) {
1603             }
1604              
1605             else {
1606 0         0 die __FILE__, ": subroutine _range_regexp panic.\n";
1607             }
1608             }
1609              
1610 0         0 return @range_regexp;
1611             }
1612              
1613             #
1614             # Windows-1254 open character list for qr and not qr
1615             #
1616             sub _charlist {
1617              
1618 182     358   399 my $modifier = pop @_;
1619 358         1027 my @char = @_;
1620              
1621 358 100       838 my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
1622              
1623             # unescape character
1624 358         863 for (my $i=0; $i <= $#char; $i++) {
1625              
1626             # escape - to ...
1627 358 100 100     1285 if ($char[$i] eq '-') {
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    100          
    100          
    100          
    100          
1628 1125 100 100     8833 if ((0 < $i) and ($i < $#char)) {
1629 206         884 $char[$i] = '...';
1630             }
1631             }
1632              
1633             # octal escape sequence
1634             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
1635 182         412 $char[$i] = octchr($1);
1636             }
1637              
1638             # hexadecimal escape sequence
1639             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
1640 0         0 $char[$i] = hexchr($1);
1641             }
1642              
1643             # \b{...} --> b\{...}
1644             # \B{...} --> B\{...}
1645             # \N{CHARNAME} --> N\{CHARNAME}
1646             # \p{PROPERTY} --> p\{PROPERTY}
1647             # \P{PROPERTY} --> P\{PROPERTY}
1648             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^0-9\}][^\}]*) \} ) \z/oxms) {
1649 0         0 $char[$i] = $1 . '\\' . $2;
1650             }
1651              
1652             # \p, \P, \X --> p, P, X
1653             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
1654 0         0 $char[$i] = $1;
1655             }
1656              
1657             elsif ($char[$i] =~ /\A \\ ([0-7]{2,3}) \z/oxms) {
1658 0         0 $char[$i] = CORE::chr oct $1;
1659             }
1660             elsif ($char[$i] =~ /\A \\x ([0-9A-Fa-f]{1,2}) \z/oxms) {
1661 0         0 $char[$i] = CORE::chr hex $1;
1662             }
1663             elsif ($char[$i] =~ /\A \\c ([\x40-\x5F]) \z/oxms) {
1664 22         154 $char[$i] = CORE::chr(CORE::ord($1) & 0x1F);
1665             }
1666             elsif ($char[$i] =~ /\A (\\ [0nrtfbaedswDSWHVhvR]) \z/oxms) {
1667             $char[$i] = {
1668             '\0' => "\0",
1669             '\n' => "\n",
1670             '\r' => "\r",
1671             '\t' => "\t",
1672             '\f' => "\f",
1673             '\b' => "\x08", # \b means backspace in character class
1674             '\a' => "\a",
1675             '\e' => "\e",
1676             '\d' => '[0-9]',
1677              
1678             # Vertical tabs are now whitespace
1679             # \s in a regex now matches a vertical tab in all circumstances.
1680             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace
1681             # \t \n \v \f \r space
1682             # '\s' => '[\x09\x0A \x0C\x0D\x20]',
1683             # '\s' => '[\x09\x0A\x0B\x0C\x0D\x20]',
1684             '\s' => '\s',
1685              
1686             '\w' => '[0-9A-Z_a-z]',
1687             '\D' => '${Ewindows1254::eD}',
1688             '\S' => '${Ewindows1254::eS}',
1689             '\W' => '${Ewindows1254::eW}',
1690              
1691             '\H' => '${Ewindows1254::eH}',
1692             '\V' => '${Ewindows1254::eV}',
1693             '\h' => '[\x09\x20]',
1694             '\v' => '[\x0A\x0B\x0C\x0D]',
1695             '\R' => '${Ewindows1254::eR}',
1696              
1697 0         0 }->{$1};
1698             }
1699              
1700             # POSIX-style character classes
1701             elsif ($ignorecase and ($char[$i] =~ /\A ( \[\: \^? (?:lower|upper) :\] ) \z/oxms)) {
1702             $char[$i] = {
1703              
1704             '[:lower:]' => '[\x41-\x5A\x61-\x7A]',
1705             '[:upper:]' => '[\x41-\x5A\x61-\x7A]',
1706             '[:^lower:]' => '${Ewindows1254::not_lower_i}',
1707             '[:^upper:]' => '${Ewindows1254::not_upper_i}',
1708              
1709 25         460 }->{$1};
1710             }
1711             elsif ($char[$i] =~ /\A ( \[\: \^? (?:alnum|alpha|ascii|blank|cntrl|digit|graph|lower|print|punct|space|upper|word|xdigit) :\] ) \z/oxms) {
1712             $char[$i] = {
1713              
1714             '[:alnum:]' => '[\x30-\x39\x41-\x5A\x61-\x7A]',
1715             '[:alpha:]' => '[\x41-\x5A\x61-\x7A]',
1716             '[:ascii:]' => '[\x00-\x7F]',
1717             '[:blank:]' => '[\x09\x20]',
1718             '[:cntrl:]' => '[\x00-\x1F\x7F]',
1719             '[:digit:]' => '[\x30-\x39]',
1720             '[:graph:]' => '[\x21-\x7F]',
1721             '[:lower:]' => '[\x61-\x7A]',
1722             '[:print:]' => '[\x20-\x7F]',
1723             '[:punct:]' => '[\x21-\x2F\x3A-\x3F\x40\x5B-\x5F\x60\x7B-\x7E]',
1724              
1725             # P.174 POSIX-Style Character Classes
1726             # in Chapter 5: Pattern Matching
1727             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
1728              
1729             # P.311 11.2.4 Character Classes and other Special Escapes
1730             # in Chapter 11: perlre: Perl regular expressions
1731             # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
1732              
1733             # P.210 POSIX-Style Character Classes
1734             # in Chapter 5: Pattern Matching
1735             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
1736              
1737             '[:space:]' => '[\s\x0B]', # "\s" plus vertical tab ("\cK")
1738              
1739             '[:upper:]' => '[\x41-\x5A]',
1740             '[:word:]' => '[\x30-\x39\x41-\x5A\x5F\x61-\x7A]',
1741             '[:xdigit:]' => '[\x30-\x39\x41-\x46\x61-\x66]',
1742             '[:^alnum:]' => '${Ewindows1254::not_alnum}',
1743             '[:^alpha:]' => '${Ewindows1254::not_alpha}',
1744             '[:^ascii:]' => '${Ewindows1254::not_ascii}',
1745             '[:^blank:]' => '${Ewindows1254::not_blank}',
1746             '[:^cntrl:]' => '${Ewindows1254::not_cntrl}',
1747             '[:^digit:]' => '${Ewindows1254::not_digit}',
1748             '[:^graph:]' => '${Ewindows1254::not_graph}',
1749             '[:^lower:]' => '${Ewindows1254::not_lower}',
1750             '[:^print:]' => '${Ewindows1254::not_print}',
1751             '[:^punct:]' => '${Ewindows1254::not_punct}',
1752             '[:^space:]' => '${Ewindows1254::not_space}',
1753             '[:^upper:]' => '${Ewindows1254::not_upper}',
1754             '[:^word:]' => '${Ewindows1254::not_word}',
1755             '[:^xdigit:]' => '${Ewindows1254::not_xdigit}',
1756              
1757 8         65 }->{$1};
1758             }
1759             elsif ($char[$i] =~ /\A \\ ($q_char) \z/oxms) {
1760 70         1305 $char[$i] = $1;
1761             }
1762             }
1763              
1764             # open character list
1765 7         41 my @singleoctet = ();
1766 358         668 my @multipleoctet = ();
1767 358         579 for (my $i=0; $i <= $#char; ) {
1768              
1769             # escaped -
1770 358 100 100     876 if (defined($char[$i+1]) and ($char[$i+1] eq '...')) {
    100          
    100          
    50          
    50          
    100          
1771 943         4200 $i += 1;
1772 182         255 next;
1773             }
1774              
1775             # make range regexp
1776             elsif ($char[$i] eq '...') {
1777              
1778             # range error
1779 182 50       370 if (CORE::length($char[$i-1]) > CORE::length($char[$i+1])) {
    50          
1780 182         691 croak 'Invalid [] range in regexp (length(A) > length(B)) ' . '\x' . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]);
1781             }
1782             elsif (CORE::length($char[$i-1]) == CORE::length($char[$i+1])) {
1783 0 50       0 if ($char[$i-1] gt $char[$i+1]) {
1784 182         470 croak 'Invalid [] range in regexp (CORE::ord(A) > CORE::ord(B)) ' . '\x' . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]);
1785             }
1786             }
1787              
1788             # make range regexp per length
1789 0         0 for my $length (CORE::length($char[$i-1]) .. CORE::length($char[$i+1])) {
1790 182         563 my @regexp = ();
1791              
1792             # is first and last
1793 182 50 33     261 if (($length == CORE::length($char[$i-1])) and ($length == CORE::length($char[$i+1]))) {
    0 0        
    0          
    0          
1794 182         698 push @regexp, _range_regexp($length, $char[$i-1], $char[$i+1]);
1795             }
1796              
1797             # is first
1798             elsif ($length == CORE::length($char[$i-1])) {
1799 182         523 push @regexp, _range_regexp($length, $char[$i-1], "\xFF" x $length);
1800             }
1801              
1802             # is inside in first and last
1803             elsif ((CORE::length($char[$i-1]) < $length) and ($length < CORE::length($char[$i+1]))) {
1804 0         0 push @regexp, _range_regexp($length, "\x00" x $length, "\xFF" x $length);
1805             }
1806              
1807             # is last
1808             elsif ($length == CORE::length($char[$i+1])) {
1809 0         0 push @regexp, _range_regexp($length, "\x00" x $length, $char[$i+1]);
1810             }
1811              
1812             else {
1813 0         0 die __FILE__, ": subroutine make_regexp panic.\n";
1814             }
1815              
1816 0 50       0 if ($length == 1) {
1817 182         384 push @singleoctet, @regexp;
1818             }
1819             else {
1820 182         472 push @multipleoctet, @regexp;
1821             }
1822             }
1823              
1824 0         0 $i += 2;
1825             }
1826              
1827             # with /i modifier
1828             elsif ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) {
1829 182 100       391 if ($modifier =~ /i/oxms) {
1830 493         847 my $uc = Ewindows1254::uc($char[$i]);
1831 24         45 my $fc = Ewindows1254::fc($char[$i]);
1832 24 50       51 if ($uc ne $fc) {
1833 24 50       44 if (CORE::length($fc) == 1) {
1834 24         45 push @singleoctet, $uc, $fc;
1835             }
1836             else {
1837 24         44 push @singleoctet, $uc;
1838 0         0 push @multipleoctet, $fc;
1839             }
1840             }
1841             else {
1842 0         0 push @singleoctet, $char[$i];
1843             }
1844             }
1845             else {
1846 0         0 push @singleoctet, $char[$i];
1847             }
1848 469         840 $i += 1;
1849             }
1850              
1851             # single character of single octet code
1852             elsif ($char[$i] =~ /\A (?: \\h ) \z/oxms) {
1853 493         942 push @singleoctet, "\t", "\x20";
1854 0         0 $i += 1;
1855             }
1856             elsif ($char[$i] =~ /\A (?: \\v ) \z/oxms) {
1857 0         0 push @singleoctet, "\x0A", "\x0B", "\x0C", "\x0D";
1858 0         0 $i += 1;
1859             }
1860             elsif ($char[$i] =~ /\A (?: \\d | \\s | \\w ) \z/oxms) {
1861 0         0 push @singleoctet, $char[$i];
1862 2         7 $i += 1;
1863             }
1864              
1865             # single character of multiple-octet code
1866             else {
1867 2         7 push @multipleoctet, $char[$i];
1868 84         178 $i += 1;
1869             }
1870             }
1871              
1872             # quote metachar
1873 84         175 for (@singleoctet) {
1874 358 50       742 if ($_ eq '...') {
    100          
    100          
    100          
    100          
1875 701         3491 $_ = '-';
1876             }
1877             elsif (/\A \n \z/oxms) {
1878 0         0 $_ = '\n';
1879             }
1880             elsif (/\A \r \z/oxms) {
1881 8         18 $_ = '\r';
1882             }
1883             elsif (/\A ([\x00-\x20\x7F-\xFF]) \z/oxms) {
1884 8         19 $_ = sprintf('\x%02X', CORE::ord $1);
1885             }
1886             elsif (/\A [\x00-\xFF] \z/oxms) {
1887 72         240 $_ = quotemeta $_;
1888             }
1889             }
1890              
1891             # return character list
1892 429         774 return \@singleoctet, \@multipleoctet;
1893             }
1894              
1895             #
1896             # Windows-1254 octal escape sequence
1897             #
1898             sub octchr {
1899 358     5 0 1315 my($octdigit) = @_;
1900              
1901 5         16 my @binary = ();
1902 5         8 for my $octal (split(//,$octdigit)) {
1903             push @binary, {
1904             '0' => '000',
1905             '1' => '001',
1906             '2' => '010',
1907             '3' => '011',
1908             '4' => '100',
1909             '5' => '101',
1910             '6' => '110',
1911             '7' => '111',
1912 5         24 }->{$octal};
1913             }
1914 50         193 my $binary = join '', @binary;
1915              
1916             my $octchr = {
1917             # 1234567
1918             1 => pack('B*', "0000000$binary"),
1919             2 => pack('B*', "000000$binary"),
1920             3 => pack('B*', "00000$binary"),
1921             4 => pack('B*', "0000$binary"),
1922             5 => pack('B*', "000$binary"),
1923             6 => pack('B*', "00$binary"),
1924             7 => pack('B*', "0$binary"),
1925             0 => pack('B*', "$binary"),
1926              
1927 5         17 }->{CORE::length($binary) % 8};
1928              
1929 5         84 return $octchr;
1930             }
1931              
1932             #
1933             # Windows-1254 hexadecimal escape sequence
1934             #
1935             sub hexchr {
1936 5     5 0 21 my($hexdigit) = @_;
1937              
1938             my $hexchr = {
1939             1 => pack('H*', "0$hexdigit"),
1940             0 => pack('H*', "$hexdigit"),
1941              
1942 5         19 }->{CORE::length($_[0]) % 2};
1943              
1944 5         64 return $hexchr;
1945             }
1946              
1947             #
1948             # Windows-1254 open character list for qr
1949             #
1950             sub charlist_qr {
1951              
1952 5     314 0 20 my $modifier = pop @_;
1953 314         658 my @char = @_;
1954              
1955 314         817 my($singleoctet, $multipleoctet) = _charlist(@char, $modifier);
1956 314         964 my @singleoctet = @$singleoctet;
1957 314         717 my @multipleoctet = @$multipleoctet;
1958              
1959             # return character list
1960 314 100       510 if (scalar(@singleoctet) >= 1) {
1961              
1962             # with /i modifier
1963 314 100       752 if ($modifier =~ m/i/oxms) {
1964 236         574 my %singleoctet_ignorecase = ();
1965 22         62 for (@singleoctet) {
1966 22   100     34 while (s/ \A \\x(..) - \\x(..) //oxms or s/ \A \\x((..)) //oxms) {
1967 58         251 for my $ord (hex($1) .. hex($2)) {
1968 58         164 my $char = CORE::chr($ord);
1969 78         121 my $uc = Ewindows1254::uc($char);
1970 78         127 my $fc = Ewindows1254::fc($char);
1971 78 50       161 if ($uc eq $fc) {
1972 78         139 $singleoctet_ignorecase{unpack 'C*', $char} = 1;
1973             }
1974             else {
1975 0 50       0 if (CORE::length($fc) == 1) {
1976 78         121 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
1977 78         192 $singleoctet_ignorecase{unpack 'C*', $fc} = 1;
1978             }
1979             else {
1980 78         289 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
1981 0         0 push @multipleoctet, join '', map {sprintf('\x%02X',$_)} unpack 'C*', $fc;
  0         0  
1982             }
1983             }
1984             }
1985             }
1986 0 50       0 if ($_ ne '') {
1987 58         130 $singleoctet_ignorecase{unpack 'C*', $_} = 1;
1988             }
1989             }
1990 0         0 my $i = 0;
1991 22         33 my @singleoctet_ignorecase = ();
1992 22         37 for my $ord (0 .. 255) {
1993 22 100       48 if (exists $singleoctet_ignorecase{$ord}) {
1994 5632         7610 push @{$singleoctet_ignorecase[$i]}, $ord;
  108         114  
1995             }
1996             else {
1997 108         228 $i++;
1998             }
1999             }
2000 5524         6147 @singleoctet = ();
2001 22         43 for my $range (@singleoctet_ignorecase) {
2002 22 100       64 if (ref $range) {
2003 3636 100       5984 if (scalar(@{$range}) == 1) {
  68 50       73  
2004 68         112 push @singleoctet, sprintf('\x%02X', @{$range}[0]);
  48         60  
2005             }
2006 48         140 elsif (scalar(@{$range}) == 2) {
2007 20         33 push @singleoctet, sprintf('\x%02X\x%02X', @{$range}[0], @{$range}[-1]);
  0         0  
  0         0  
2008             }
2009             else {
2010 0         0 push @singleoctet, sprintf('\x%02X-\x%02X', @{$range}[0], @{$range}[-1]);
  20         27  
  20         33  
2011             }
2012             }
2013             }
2014             }
2015              
2016 20         116 my $not_anchor = '';
2017              
2018 236         401 push @multipleoctet, join('', $not_anchor, '[', @singleoctet, ']' );
2019             }
2020 236 100       711 if (scalar(@multipleoctet) >= 2) {
2021 314         741 return '(?:' . join('|', @multipleoctet) . ')';
2022             }
2023             else {
2024 6         38 return $multipleoctet[0];
2025             }
2026             }
2027              
2028             #
2029             # Windows-1254 open character list for not qr
2030             #
2031             sub charlist_not_qr {
2032              
2033 308     44 0 1315 my $modifier = pop @_;
2034 44         97 my @char = @_;
2035              
2036 44         310 my($singleoctet, $multipleoctet) = _charlist(@char, $modifier);
2037 44         151 my @singleoctet = @$singleoctet;
2038 44         108 my @multipleoctet = @$multipleoctet;
2039              
2040             # with /i modifier
2041 44 100       78 if ($modifier =~ m/i/oxms) {
2042 44         133 my %singleoctet_ignorecase = ();
2043 10         28 for (@singleoctet) {
2044 10   66     18 while (s/ \A \\x(..) - \\x(..) //oxms or s/ \A \\x((..)) //oxms) {
2045 10         48 for my $ord (hex($1) .. hex($2)) {
2046 10         40 my $char = CORE::chr($ord);
2047 30         53 my $uc = Ewindows1254::uc($char);
2048 30         48 my $fc = Ewindows1254::fc($char);
2049 30 50       56 if ($uc eq $fc) {
2050 30         47 $singleoctet_ignorecase{unpack 'C*', $char} = 1;
2051             }
2052             else {
2053 0 50       0 if (CORE::length($fc) == 1) {
2054 30         44 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2055 30         68 $singleoctet_ignorecase{unpack 'C*', $fc} = 1;
2056             }
2057             else {
2058 30         96 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2059 0         0 push @multipleoctet, join '', map {sprintf('\x%02X',$_)} unpack 'C*', $fc;
  0         0  
2060             }
2061             }
2062             }
2063             }
2064 0 50       0 if ($_ ne '') {
2065 10         25 $singleoctet_ignorecase{unpack 'C*', $_} = 1;
2066             }
2067             }
2068 0         0 my $i = 0;
2069 10         11 my @singleoctet_ignorecase = ();
2070 10         17 for my $ord (0 .. 255) {
2071 10 100       14 if (exists $singleoctet_ignorecase{$ord}) {
2072 2560         3012 push @{$singleoctet_ignorecase[$i]}, $ord;
  60         56  
2073             }
2074             else {
2075 60         102 $i++;
2076             }
2077             }
2078 2500         2520 @singleoctet = ();
2079 10         18 for my $range (@singleoctet_ignorecase) {
2080 10 100       28 if (ref $range) {
2081 960 50       1917 if (scalar(@{$range}) == 1) {
  20 50       21  
2082 20         34 push @singleoctet, sprintf('\x%02X', @{$range}[0]);
  0         0  
2083             }
2084 0         0 elsif (scalar(@{$range}) == 2) {
2085 20         30 push @singleoctet, sprintf('\x%02X\x%02X', @{$range}[0], @{$range}[-1]);
  0         0  
  0         0  
2086             }
2087             else {
2088 0         0 push @singleoctet, sprintf('\x%02X-\x%02X', @{$range}[0], @{$range}[-1]);
  20         26  
  20         26  
2089             }
2090             }
2091             }
2092             }
2093              
2094             # return character list
2095 20 50       81 if (scalar(@multipleoctet) >= 1) {
2096 44 0       110 if (scalar(@singleoctet) >= 1) {
2097              
2098             # any character other than multiple-octet and single octet character class
2099 0         0 return '(?!' . join('|', @multipleoctet) . ')(?:[^' . join('', @singleoctet) . '])';
2100             }
2101             else {
2102              
2103             # any character other than multiple-octet character class
2104 0         0 return '(?!' . join('|', @multipleoctet) . ")(?:$your_char)";
2105             }
2106             }
2107             else {
2108 0 50       0 if (scalar(@singleoctet) >= 1) {
2109              
2110             # any character other than single octet character class
2111 44         90 return '(?:[^' . join('', @singleoctet) . '])';
2112             }
2113             else {
2114              
2115             # any character
2116 44         280 return "(?:$your_char)";
2117             }
2118             }
2119             }
2120              
2121             #
2122             # open file in read mode
2123             #
2124             sub _open_r {
2125 0     412   0 my(undef,$file) = @_;
2126 206     206   2303 use Fcntl qw(O_RDONLY);
  206         4577  
  206         27280  
2127 412         1225 return CORE::sysopen($_[0], $file, &O_RDONLY);
2128             }
2129              
2130             #
2131             # open file in append mode
2132             #
2133             sub _open_a {
2134 412     206   17867 my(undef,$file) = @_;
2135 206     206   1550 use Fcntl qw(O_WRONLY O_APPEND O_CREAT);
  206         470  
  206         575817  
2136 206         761 return CORE::sysopen($_[0], $file, &O_WRONLY|&O_APPEND|&O_CREAT);
2137             }
2138              
2139             #
2140             # safe system
2141             #
2142             sub _systemx {
2143              
2144             # P.707 29.2.33. exec
2145             # in Chapter 29: Functions
2146             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2147             #
2148             # Be aware that in older releases of Perl, exec (and system) did not flush
2149             # your output buffer, so you needed to enable command buffering by setting $|
2150             # on one or more filehandles to avoid lost output in the case of exec, or
2151             # misordererd output in the case of system. This situation was largely remedied
2152             # in the 5.6 release of Perl. (So, 5.005 release not yet.)
2153              
2154             # P.855 exec
2155             # in Chapter 27: Functions
2156             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2157             #
2158             # In very old release of Perl (before v5.6), exec (and system) did not flush
2159             # your output buffer, so you needed to enable command buffering by setting $|
2160             # on one or more filehandles to avoid lost output with exec or misordered
2161             # output with system.
2162              
2163 206     206   24981 $| = 1;
2164              
2165             # P.565 23.1.2. Cleaning Up Your Environment
2166             # in Chapter 23: Security
2167             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2168              
2169             # P.656 Cleaning Up Your Environment
2170             # in Chapter 20: Security
2171             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2172              
2173             # local $ENV{'PATH'} = '.';
2174 206         868 local @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
2175              
2176             # P.707 29.2.33. exec
2177             # in Chapter 29: Functions
2178             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2179             #
2180             # As we mentioned earlier, exec treats a discrete list of arguments as an
2181             # indication that it should bypass shell processing. However, there is one
2182             # place where you might still get tripped up. The exec call (and system, too)
2183             # will not distinguish between a single scalar argument and an array containing
2184             # only one element.
2185             #
2186             # @args = ("echo surprise"); # just one element in list
2187             # exec @args # still subject to shell escapes
2188             # or die "exec: $!"; # because @args == 1
2189             #
2190             # To avoid this, you can use the PATHNAME syntax, explicitly duplicating the
2191             # first argument as the pathname, which forces the rest of the arguments to be
2192             # interpreted as a list, even if there is only one of them:
2193             #
2194             # exec { $args[0] } @args # safe even with one-argument list
2195             # or die "can't exec @args: $!";
2196              
2197             # P.855 exec
2198             # in Chapter 27: Functions
2199             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2200             #
2201             # As we mentioned earlier, exec treats a discrete list of arguments as a
2202             # directive to bypass shell processing. However, there is one place where
2203             # you might still get tripped up. The exec call (and system, too) cannot
2204             # distinguish between a single scalar argument and an array containing
2205             # only one element.
2206             #
2207             # @args = ("echo surprise"); # just one element in list
2208             # exec @args # still subject to shell escapes
2209             # || die "exec: $!"; # because @args == 1
2210             #
2211             # To avoid this, use the PATHNAME syntax, explicitly duplicating the first
2212             # argument as the pathname, which forces the rest of the arguments to be
2213             # interpreted as a list, even if there is only one of them:
2214             #
2215             # exec { $args[0] } @args # safe even with one-argument list
2216             # || die "can't exec @args: $!";
2217              
2218 206         2053 return CORE::system { $_[0] } @_; # safe even with one-argument list
  206         479  
2219             }
2220              
2221             #
2222             # Windows-1254 order to character (with parameter)
2223             #
2224             sub Ewindows1254::chr(;$) {
2225              
2226 206 0   0 0 14200731 my $c = @_ ? $_[0] : $_;
2227              
2228 0 0       0 if ($c == 0x00) {
2229 0         0 return "\x00";
2230             }
2231             else {
2232 0         0 my @chr = ();
2233 0         0 while ($c > 0) {
2234 0         0 unshift @chr, ($c % 0x100);
2235 0         0 $c = int($c / 0x100);
2236             }
2237 0         0 return pack 'C*', @chr;
2238             }
2239             }
2240              
2241             #
2242             # Windows-1254 order to character (without parameter)
2243             #
2244             sub Ewindows1254::chr_() {
2245              
2246 0     0 0 0 my $c = $_;
2247              
2248 0 0       0 if ($c == 0x00) {
2249 0         0 return "\x00";
2250             }
2251             else {
2252 0         0 my @chr = ();
2253 0         0 while ($c > 0) {
2254 0         0 unshift @chr, ($c % 0x100);
2255 0         0 $c = int($c / 0x100);
2256             }
2257 0         0 return pack 'C*', @chr;
2258             }
2259             }
2260              
2261             #
2262             # Windows-1254 path globbing (with parameter)
2263             #
2264             sub Ewindows1254::glob($) {
2265              
2266 0 0   0 0 0 if (wantarray) {
2267 0         0 my @glob = _DOS_like_glob(@_);
2268 0         0 for my $glob (@glob) {
2269 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
2270             }
2271 0         0 return @glob;
2272             }
2273             else {
2274 0         0 my $glob = _DOS_like_glob(@_);
2275 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
2276 0         0 return $glob;
2277             }
2278             }
2279              
2280             #
2281             # Windows-1254 path globbing (without parameter)
2282             #
2283             sub Ewindows1254::glob_() {
2284              
2285 0 0   0 0 0 if (wantarray) {
2286 0         0 my @glob = _DOS_like_glob();
2287 0         0 for my $glob (@glob) {
2288 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
2289             }
2290 0         0 return @glob;
2291             }
2292             else {
2293 0         0 my $glob = _DOS_like_glob();
2294 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
2295 0         0 return $glob;
2296             }
2297             }
2298              
2299             #
2300             # Windows-1254 path globbing via File::DosGlob 1.10
2301             #
2302             # Often I confuse "_dosglob" and "_doglob".
2303             # So, I renamed "_dosglob" to "_DOS_like_glob".
2304             #
2305             my %iter;
2306             my %entries;
2307             sub _DOS_like_glob {
2308              
2309             # context (keyed by second cxix argument provided by core)
2310 0     0   0 my($expr,$cxix) = @_;
2311              
2312             # glob without args defaults to $_
2313 0 0       0 $expr = $_ if not defined $expr;
2314              
2315             # represents the current user's home directory
2316             #
2317             # 7.3. Expanding Tildes in Filenames
2318             # in Chapter 7. File Access
2319             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
2320             #
2321             # and File::HomeDir, File::HomeDir::Windows module
2322              
2323             # DOS-like system
2324 0 0       0 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
2325 0         0 $expr =~ s{ \A ~ (?= [^/\\] ) }
  0         0  
2326             { my_home_MSWin32() }oxmse;
2327             }
2328              
2329             # UNIX-like system
2330 0 0 0     0 else {
  0         0  
2331             $expr =~ s{ \A ~ ( (?:[^/])* ) }
2332             { $1 ? (CORE::eval(q{(getpwnam($1))[7]})||my_home()) : my_home() }oxmse;
2333             }
2334 0 0       0  
2335 0 0       0 # assume global context if not provided one
2336             $cxix = '_G_' if not defined $cxix;
2337             $iter{$cxix} = 0 if not exists $iter{$cxix};
2338 0 0       0  
2339 0         0 # if we're just beginning, do it all first
2340             if ($iter{$cxix} == 0) {
2341             $entries{$cxix} = [ _do_glob(1, _parse_line($expr)) ];
2342             }
2343 0 0       0  
2344 0         0 # chuck it all out, quick or slow
2345 0         0 if (wantarray) {
  0         0  
2346             delete $iter{$cxix};
2347             return @{delete $entries{$cxix}};
2348 0 0       0 }
  0         0  
2349 0         0 else {
  0         0  
2350             if ($iter{$cxix} = scalar @{$entries{$cxix}}) {
2351             return shift @{$entries{$cxix}};
2352             }
2353 0         0 else {
2354 0         0 # return undef for EOL
2355 0         0 delete $iter{$cxix};
2356             delete $entries{$cxix};
2357             return undef;
2358             }
2359             }
2360             }
2361              
2362             #
2363             # Windows-1254 path globbing subroutine
2364             #
2365 0     0   0 sub _do_glob {
2366 0         0  
2367 0         0 my($cond,@expr) = @_;
2368             my @glob = ();
2369             my $fix_drive_relative_paths = 0;
2370 0         0  
2371 0 0       0 OUTER:
2372 0 0       0 for my $expr (@expr) {
2373             next OUTER if not defined $expr;
2374 0         0 next OUTER if $expr eq '';
2375 0         0  
2376 0         0 my @matched = ();
2377 0         0 my @globdir = ();
2378 0         0 my $head = '.';
2379             my $pathsep = '/';
2380             my $tail;
2381 0 0       0  
2382 0         0 # if argument is within quotes strip em and do no globbing
2383 0 0       0 if ($expr =~ /\A " ((?:$q_char)*?) " \z/oxms) {
2384 0 0       0 $expr = $1;
2385 0         0 if ($cond eq 'd') {
2386             if (-d $expr) {
2387             push @glob, $expr;
2388             }
2389 0 0       0 }
2390 0         0 else {
2391             if (-e $expr) {
2392             push @glob, $expr;
2393 0         0 }
2394             }
2395             next OUTER;
2396             }
2397              
2398 0 0       0 # wildcards with a drive prefix such as h:*.pm must be changed
2399 0 0       0 # to h:./*.pm to expand correctly
2400 0         0 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
2401             if ($expr =~ s# \A ((?:[A-Za-z]:)?) ([^/\\]) #$1./$2#oxms) {
2402             $fix_drive_relative_paths = 1;
2403             }
2404 0 0       0 }
2405 0 0       0  
2406 0         0 if (($head, $tail) = _parse_path($expr,$pathsep)) {
2407 0         0 if ($tail eq '') {
2408             push @glob, $expr;
2409 0 0       0 next OUTER;
2410 0 0       0 }
2411 0         0 if ($head =~ / \A (?:$q_char)*? [*?] /oxms) {
  0         0  
2412 0         0 if (@globdir = _do_glob('d', $head)) {
2413             push @glob, _do_glob($cond, map {"$_$pathsep$tail"} @globdir);
2414             next OUTER;
2415 0 0 0     0 }
2416 0         0 }
2417             if ($head eq '' or $head =~ /\A [A-Za-z]: \z/oxms) {
2418 0         0 $head .= $pathsep;
2419             }
2420             $expr = $tail;
2421             }
2422 0 0       0  
2423 0 0       0 # If file component has no wildcards, we can avoid opendir
2424 0         0 if ($expr !~ / \A (?:$q_char)*? [*?] /oxms) {
2425             if ($head eq '.') {
2426 0 0 0     0 $head = '';
2427 0         0 }
2428             if ($head ne '' and ($head =~ / \G ($q_char) /oxmsg)[-1] ne $pathsep) {
2429 0         0 $head .= $pathsep;
2430 0 0       0 }
2431 0 0       0 $head .= $expr;
2432 0         0 if ($cond eq 'd') {
2433             if (-d $head) {
2434             push @glob, $head;
2435             }
2436 0 0       0 }
2437 0         0 else {
2438             if (-e $head) {
2439             push @glob, $head;
2440 0         0 }
2441             }
2442 0 0       0 next OUTER;
2443 0         0 }
2444 0         0 opendir(*DIR, $head) or next OUTER;
2445             my @leaf = readdir DIR;
2446 0 0       0 closedir DIR;
2447 0         0  
2448             if ($head eq '.') {
2449 0 0 0     0 $head = '';
2450 0         0 }
2451             if ($head ne '' and ($head =~ / \G ($q_char) /oxmsg)[-1] ne $pathsep) {
2452             $head .= $pathsep;
2453 0         0 }
2454 0         0  
2455 0         0 my $pattern = '';
2456             while ($expr =~ / \G ($q_char) /oxgc) {
2457             my $char = $1;
2458              
2459             # 6.9. Matching Shell Globs as Regular Expressions
2460             # in Chapter 6. Pattern Matching
2461             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
2462 0 0       0 # (and so on)
    0          
    0          
2463 0         0  
2464             if ($char eq '*') {
2465             $pattern .= "(?:$your_char)*",
2466 0         0 }
2467             elsif ($char eq '?') {
2468             $pattern .= "(?:$your_char)?", # DOS style
2469             # $pattern .= "(?:$your_char)", # UNIX style
2470 0         0 }
2471             elsif ((my $fc = Ewindows1254::fc($char)) ne $char) {
2472             $pattern .= $fc;
2473 0         0 }
2474             else {
2475             $pattern .= quotemeta $char;
2476 0     0   0 }
  0         0  
2477             }
2478             my $matchsub = sub { Ewindows1254::fc($_[0]) =~ /\A $pattern \z/xms };
2479              
2480             # if ($@) {
2481             # print STDERR "$0: $@\n";
2482             # next OUTER;
2483             # }
2484 0         0  
2485 0 0 0     0 INNER:
2486 0         0 for my $leaf (@leaf) {
2487             if ($leaf eq '.' or $leaf eq '..') {
2488 0 0 0     0 next INNER;
2489 0         0 }
2490             if ($cond eq 'd' and not -d "$head$leaf") {
2491             next INNER;
2492 0 0       0 }
2493 0         0  
2494 0         0 if (&$matchsub($leaf)) {
2495             push @matched, "$head$leaf";
2496             next INNER;
2497             }
2498              
2499             # [DOS compatibility special case]
2500 0 0 0     0 # Failed, add a trailing dot and try again, but only...
      0        
2501              
2502             if (Ewindows1254::index($leaf,'.') == -1 and # if name does not have a dot in it *and*
2503             CORE::length($leaf) <= 8 and # name is shorter than or equal to 8 chars *and*
2504 0 0       0 Ewindows1254::index($pattern,'\\.') != -1 # pattern has a dot.
2505 0         0 ) {
2506 0         0 if (&$matchsub("$leaf.")) {
2507             push @matched, "$head$leaf";
2508             next INNER;
2509             }
2510 0 0       0 }
2511 0         0 }
2512             if (@matched) {
2513             push @glob, @matched;
2514 0 0       0 }
2515 0         0 }
2516 0         0 if ($fix_drive_relative_paths) {
2517             for my $glob (@glob) {
2518             $glob =~ s# \A ([A-Za-z]:) \./ #$1#oxms;
2519 0         0 }
2520             }
2521             return @glob;
2522             }
2523              
2524             #
2525             # Windows-1254 parse line
2526             #
2527 0     0   0 sub _parse_line {
2528              
2529 0         0 my($line) = @_;
2530 0         0  
2531 0         0 $line .= ' ';
2532             my @piece = ();
2533             while ($line =~ /
2534             " ( (?>(?: [^"] )* ) ) " (?>\s+) |
2535             ( (?>(?: [^"\s] )* ) ) (?>\s+)
2536 0 0       0 /oxmsg
2537             ) {
2538 0         0 push @piece, defined($1) ? $1 : $2;
2539             }
2540             return @piece;
2541             }
2542              
2543             #
2544             # Windows-1254 parse path
2545             #
2546 0     0   0 sub _parse_path {
2547              
2548 0         0 my($path,$pathsep) = @_;
2549 0         0  
2550 0         0 $path .= '/';
2551             my @subpath = ();
2552             while ($path =~ /
2553             ((?: [^\/\\] )+?) [\/\\]
2554 0         0 /oxmsg
2555             ) {
2556             push @subpath, $1;
2557 0         0 }
2558 0         0  
2559 0         0 my $tail = pop @subpath;
2560             my $head = join $pathsep, @subpath;
2561             return $head, $tail;
2562             }
2563              
2564             #
2565             # via File::HomeDir::Windows 1.00
2566             #
2567             sub my_home_MSWin32 {
2568              
2569             # A lot of unix people and unix-derived tools rely on
2570 0 0 0 0 0 0 # the ability to overload HOME. We will support it too
    0 0        
    0 0        
      0        
      0        
2571 0         0 # so that they can replace raw HOME calls with File::HomeDir.
2572             if (exists $ENV{'HOME'} and $ENV{'HOME'}) {
2573             return $ENV{'HOME'};
2574             }
2575              
2576 0         0 # Do we have a user profile?
2577             elsif (exists $ENV{'USERPROFILE'} and $ENV{'USERPROFILE'}) {
2578             return $ENV{'USERPROFILE'};
2579             }
2580              
2581 0         0 # Some Windows use something like $ENV{'HOME'}
2582             elsif (exists $ENV{'HOMEDRIVE'} and exists $ENV{'HOMEPATH'} and $ENV{'HOMEDRIVE'} and $ENV{'HOMEPATH'}) {
2583             return join '', $ENV{'HOMEDRIVE'}, $ENV{'HOMEPATH'};
2584 0         0 }
2585              
2586             return undef;
2587             }
2588              
2589             #
2590             # via File::HomeDir::Unix 1.00
2591 0     0 0 0 #
2592             sub my_home {
2593 0 0 0     0 my $home;
    0 0        
2594 0         0  
2595             if (exists $ENV{'HOME'} and defined $ENV{'HOME'}) {
2596             $home = $ENV{'HOME'};
2597             }
2598              
2599             # This is from the original code, but I'm guessing
2600 0         0 # it means "login directory" and exists on some Unixes.
2601             elsif (exists $ENV{'LOGDIR'} and $ENV{'LOGDIR'}) {
2602             $home = $ENV{'LOGDIR'};
2603             }
2604              
2605             ### More-desperate methods
2606              
2607 0         0 # Light desperation on any (Unixish) platform
2608             else {
2609             $home = CORE::eval q{ (getpwuid($<))[7] };
2610             }
2611              
2612 0 0 0     0 # On Unix in general, a non-existant home means "no home"
2613 0         0 # For example, "nobody"-like users might use /nonexistant
2614             if (defined $home and ! -d($home)) {
2615 0         0 $home = undef;
2616             }
2617             return $home;
2618             }
2619              
2620             #
2621             # ${^PREMATCH}, $PREMATCH, $` the string preceding what was matched
2622 0     0 0 0 #
2623             sub Ewindows1254::PREMATCH {
2624             return $`;
2625             }
2626              
2627             #
2628             # ${^MATCH}, $MATCH, $& the string that matched
2629 0     0 0 0 #
2630             sub Ewindows1254::MATCH {
2631             return $&;
2632             }
2633              
2634             #
2635             # ${^POSTMATCH}, $POSTMATCH, $' the string following what was matched
2636 0     0 0 0 #
2637             sub Ewindows1254::POSTMATCH {
2638             return $';
2639             }
2640              
2641             #
2642             # Windows-1254 character to order (with parameter)
2643             #
2644 0 0   0 1 0 sub Windows1254::ord(;$) {
2645              
2646 0 0       0 local $_ = shift if @_;
2647 0         0  
2648 0         0 if (/\A ($q_char) /oxms) {
2649 0         0 my @ord = unpack 'C*', $1;
2650 0         0 my $ord = 0;
2651             while (my $o = shift @ord) {
2652 0         0 $ord = $ord * 0x100 + $o;
2653             }
2654             return $ord;
2655 0         0 }
2656             else {
2657             return CORE::ord $_;
2658             }
2659             }
2660              
2661             #
2662             # Windows-1254 character to order (without parameter)
2663             #
2664 0 0   0 0 0 sub Windows1254::ord_() {
2665 0         0  
2666 0         0 if (/\A ($q_char) /oxms) {
2667 0         0 my @ord = unpack 'C*', $1;
2668 0         0 my $ord = 0;
2669             while (my $o = shift @ord) {
2670 0         0 $ord = $ord * 0x100 + $o;
2671             }
2672             return $ord;
2673 0         0 }
2674             else {
2675             return CORE::ord $_;
2676             }
2677             }
2678              
2679             #
2680             # Windows-1254 reverse
2681             #
2682 0 0   0 0 0 sub Windows1254::reverse(@) {
2683 0         0  
2684             if (wantarray) {
2685             return CORE::reverse @_;
2686             }
2687             else {
2688              
2689             # One of us once cornered Larry in an elevator and asked him what
2690             # problem he was solving with this, but he looked as far off into
2691             # the distance as he could in an elevator and said, "It seemed like
2692 0         0 # a good idea at the time."
2693              
2694             return join '', CORE::reverse(join('',@_) =~ /\G ($q_char) /oxmsg);
2695             }
2696             }
2697              
2698             #
2699             # Windows-1254 getc (with parameter, without parameter)
2700             #
2701 0     0 0 0 sub Windows1254::getc(;*@) {
2702 0 0       0  
2703 0 0 0     0 my($package) = caller;
2704             my $fh = @_ ? qualify_to_ref(shift,$package) : \*STDIN;
2705 0         0 croak 'Too many arguments for Windows1254::getc' if @_ and not wantarray;
  0         0  
2706 0         0  
2707 0         0 my @length = sort { $a <=> $b } keys %range_tr;
2708 0         0 my $getc = '';
2709 0 0       0 for my $length ($length[0] .. $length[-1]) {
2710 0 0       0 $getc .= CORE::getc($fh);
2711 0 0       0 if (exists $range_tr{CORE::length($getc)}) {
2712             if ($getc =~ /\A ${Ewindows1254::dot_s} \z/oxms) {
2713             return wantarray ? ($getc,@_) : $getc;
2714             }
2715 0 0       0 }
2716             }
2717             return wantarray ? ($getc,@_) : $getc;
2718             }
2719              
2720             #
2721             # Windows-1254 length by character
2722             #
2723 0 0   0 1 0 sub Windows1254::length(;$) {
2724              
2725 0         0 local $_ = shift if @_;
2726 0         0  
2727             local @_ = /\G ($q_char) /oxmsg;
2728             return scalar @_;
2729             }
2730              
2731             #
2732             # Windows-1254 substr by character
2733             #
2734             BEGIN {
2735              
2736             # P.232 The lvalue Attribute
2737             # in Chapter 6: Subroutines
2738             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2739              
2740             # P.336 The lvalue Attribute
2741             # in Chapter 7: Subroutines
2742             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2743              
2744             # P.144 8.4 Lvalue subroutines
2745             # in Chapter 8: perlsub: Perl subroutines
2746 206 50 0 206 1 140762 # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
  0 0   0   0  
  0 0   0   0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
2747              
2748             CORE::eval sprintf(<<'END', ($] >= 5.014000) ? ':lvalue' : '');
2749             # vv----------------------*******
2750             sub Windows1254::substr($$;$$) %s {
2751              
2752             my @char = $_[0] =~ /\G (?>$q_char) /oxmsg;
2753              
2754             # If the substring is beyond either end of the string, substr() returns the undefined
2755             # value and produces a warning. When used as an lvalue, specifying a substring that
2756             # is entirely outside the string raises an exception.
2757             # http://perldoc.perl.org/functions/substr.html
2758              
2759             # A return with no argument returns the scalar value undef in scalar context,
2760             # an empty list () in list context, and (naturally) nothing at all in void
2761             # context.
2762              
2763             my $offset = $_[1];
2764             if (($offset > scalar(@char)) or ($offset < (-1 * scalar(@char)))) {
2765             return;
2766             }
2767              
2768             # substr($string,$offset,$length,$replacement)
2769             if (@_ == 4) {
2770             my(undef,undef,$length,$replacement) = @_;
2771             my $substr = join '', splice(@char, $offset, $length, $replacement);
2772             $_[0] = join '', @char;
2773              
2774             # return $substr; this doesn't work, don't say "return"
2775             $substr;
2776             }
2777              
2778             # substr($string,$offset,$length)
2779             elsif (@_ == 3) {
2780             my(undef,undef,$length) = @_;
2781             my $octet_offset = 0;
2782             my $octet_length = 0;
2783             if ($offset == 0) {
2784             $octet_offset = 0;
2785             }
2786             elsif ($offset > 0) {
2787             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
2788             $octet_offset = CORE::length(join '', @char[0..$offset-1]);
2789             }
2790             else {
2791             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
2792             $octet_offset = -1 * CORE::length(join '', @char[$#char+$offset+1..$#char]);
2793             }
2794             if ($length == 0) {
2795             $octet_length = 0;
2796             }
2797             elsif ($length > 0) {
2798             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
2799             $octet_length = CORE::length(join '', @char[$offset..$offset+$length-1]);
2800             }
2801             else {
2802             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
2803             $octet_length = -1 * CORE::length(join '', @char[$#char+$length+1..$#char]);
2804             }
2805             CORE::substr($_[0], $octet_offset, $octet_length);
2806             }
2807              
2808             # substr($string,$offset)
2809             else {
2810             my $octet_offset = 0;
2811             if ($offset == 0) {
2812             $octet_offset = 0;
2813             }
2814             elsif ($offset > 0) {
2815             $octet_offset = CORE::length(join '', @char[0..$offset-1]);
2816             }
2817             else {
2818             $octet_offset = -1 * CORE::length(join '', @char[$#char+$offset+1..$#char]);
2819             }
2820             CORE::substr($_[0], $octet_offset);
2821             }
2822             }
2823             END
2824             }
2825              
2826             #
2827             # Windows-1254 index by character
2828             #
2829 0     0 1 0 sub Windows1254::index($$;$) {
2830 0 0       0  
2831 0         0 my $index;
2832             if (@_ == 3) {
2833             $index = Ewindows1254::index($_[0], $_[1], CORE::length(Windows1254::substr($_[0], 0, $_[2])));
2834 0         0 }
2835             else {
2836             $index = Ewindows1254::index($_[0], $_[1]);
2837 0 0       0 }
2838 0         0  
2839             if ($index == -1) {
2840             return -1;
2841 0         0 }
2842             else {
2843             return Windows1254::length(CORE::substr $_[0], 0, $index);
2844             }
2845             }
2846              
2847             #
2848             # Windows-1254 rindex by character
2849             #
2850 0     0 1 0 sub Windows1254::rindex($$;$) {
2851 0 0       0  
2852 0         0 my $rindex;
2853             if (@_ == 3) {
2854             $rindex = Ewindows1254::rindex($_[0], $_[1], CORE::length(Windows1254::substr($_[0], 0, $_[2])));
2855 0         0 }
2856             else {
2857             $rindex = Ewindows1254::rindex($_[0], $_[1]);
2858 0 0       0 }
2859 0         0  
2860             if ($rindex == -1) {
2861             return -1;
2862 0         0 }
2863             else {
2864             return Windows1254::length(CORE::substr $_[0], 0, $rindex);
2865             }
2866             }
2867              
2868 206     206   1683 # when 'm//', '/' means regexp match 'm//' and '?' means regexp match '??'
  206         462  
  206         32801  
2869             # when 'div', '/' means division operator and '?' means conditional operator (condition ? then : else)
2870             use vars qw($slash); $slash = 'm//';
2871              
2872             # ord() to ord() or Windows1254::ord()
2873             my $function_ord = 'ord';
2874              
2875             # ord to ord or Windows1254::ord_
2876             my $function_ord_ = 'ord';
2877              
2878             # reverse to reverse or Windows1254::reverse
2879             my $function_reverse = 'reverse';
2880              
2881             # getc to getc or Windows1254::getc
2882             my $function_getc = 'getc';
2883              
2884             # P.1023 Appendix W.9 Multibyte Anchoring
2885             # of ISBN 1-56592-224-7 CJKV Information Processing
2886              
2887 206     206   1477 my $anchor = '';
  206     0   419  
  206         7590123  
2888              
2889             use vars qw($nest);
2890              
2891             # regexp of nested parens in qqXX
2892              
2893             # P.340 Matching Nested Constructs with Embedded Code
2894             # in Chapter 7: Perl
2895             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
2896              
2897             my $qq_paren = qr{(?{local $nest=0}) (?>(?:
2898             [^\\()] |
2899             \( (?{$nest++}) |
2900             \) (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
2901             \\ [^c] |
2902             \\c[\x40-\x5F] |
2903             [\x00-\xFF]
2904             }xms;
2905              
2906             my $qq_brace = qr{(?{local $nest=0}) (?>(?:
2907             [^\\{}] |
2908             \{ (?{$nest++}) |
2909             \} (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
2910             \\ [^c] |
2911             \\c[\x40-\x5F] |
2912             [\x00-\xFF]
2913             }xms;
2914              
2915             my $qq_bracket = qr{(?{local $nest=0}) (?>(?:
2916             [^\\\[\]] |
2917             \[ (?{$nest++}) |
2918             \] (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
2919             \\ [^c] |
2920             \\c[\x40-\x5F] |
2921             [\x00-\xFF]
2922             }xms;
2923              
2924             my $qq_angle = qr{(?{local $nest=0}) (?>(?:
2925             [^\\<>] |
2926             \< (?{$nest++}) |
2927             \> (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
2928             \\ [^c] |
2929             \\c[\x40-\x5F] |
2930             [\x00-\xFF]
2931             }xms;
2932              
2933             my $qq_scalar = qr{(?: \{ (?:$qq_brace)*? \} |
2934             (?: ::)? (?:
2935             (?> [a-zA-Z_][a-zA-Z_0-9]* (?: ::[a-zA-Z_][a-zA-Z_0-9]*)* )
2936             (?>(?: \[ (?: \$\[ | \$\] | $qq_char )*? \] | \{ (?:$qq_brace)*? \} )*)
2937             (?>(?: (?: -> )? (?: [\$\@\%\&\*]\* | \$\#\* | [\@\%]? \[ (?: \$\[ | \$\] | $qq_char )*? \] | [\@\%\*]? \{ (?:$qq_brace)*? \} ) )*)
2938             ))
2939             }xms;
2940              
2941             my $qq_variable = qr{(?: \{ (?:$qq_brace)*? \} |
2942             (?: ::)? (?:
2943             (?>[0-9]+) |
2944             [^a-zA-Z_0-9\[\]] |
2945             ^[A-Z] |
2946             (?> [a-zA-Z_][a-zA-Z_0-9]* (?: ::[a-zA-Z_][a-zA-Z_0-9]*)* )
2947             (?>(?: \[ (?: \$\[ | \$\] | $qq_char )*? \] | \{ (?:$qq_brace)*? \} )*)
2948             (?>(?: (?: -> )? (?: [\$\@\%\&\*]\* | \$\#\* | [\@\%]? \[ (?: \$\[ | \$\] | $qq_char )*? \] | [\@\%\*]? \{ (?:$qq_brace)*? \} ) )*)
2949             ))
2950             }xms;
2951              
2952             my $qq_substr = qr{(?> Char::substr | Windows1254::substr | CORE::substr | substr ) (?>\s*) \( $qq_paren \)
2953             }xms;
2954              
2955             # regexp of nested parens in qXX
2956             my $q_paren = qr{(?{local $nest=0}) (?>(?:
2957             [^()] |
2958             \( (?{$nest++}) |
2959             \) (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
2960             [\x00-\xFF]
2961             }xms;
2962              
2963             my $q_brace = qr{(?{local $nest=0}) (?>(?:
2964             [^\{\}] |
2965             \{ (?{$nest++}) |
2966             \} (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
2967             [\x00-\xFF]
2968             }xms;
2969              
2970             my $q_bracket = qr{(?{local $nest=0}) (?>(?:
2971             [^\[\]] |
2972             \[ (?{$nest++}) |
2973             \] (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
2974             [\x00-\xFF]
2975             }xms;
2976              
2977             my $q_angle = qr{(?{local $nest=0}) (?>(?:
2978             [^<>] |
2979             \< (?{$nest++}) |
2980             \> (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
2981             [\x00-\xFF]
2982             }xms;
2983              
2984             my $matched = '';
2985             my $s_matched = '';
2986              
2987             my $tr_variable = ''; # variable of tr///
2988             my $sub_variable = ''; # variable of s///
2989             my $bind_operator = ''; # =~ or !~
2990              
2991             my @heredoc = (); # here document
2992             my @heredoc_delimiter = ();
2993             my $here_script = ''; # here script
2994              
2995             #
2996             # escape Windows-1254 script
2997 0 50   206 0 0 #
2998             sub Windows1254::escape(;$) {
2999             local($_) = $_[0] if @_;
3000              
3001             # P.359 The Study Function
3002             # in Chapter 7: Perl
3003 206         696 # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
3004              
3005             study $_; # Yes, I studied study yesterday.
3006              
3007             # while all script
3008              
3009             # 6.14. Matching from Where the Last Pattern Left Off
3010             # in Chapter 6. Pattern Matching
3011             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
3012             # (and so on)
3013              
3014             # one member of Tag-team
3015             #
3016             # P.128 Start of match (or end of previous match): \G
3017             # P.130 Advanced Use of \G with Perl
3018             # in Chapter 3: Overview of Regular Expression Features and Flavors
3019             # P.255 Use leading anchors
3020             # P.256 Expose ^ and \G at the front expressions
3021             # in Chapter 6: Crafting an Efficient Expression
3022             # P.315 "Tag-team" matching with /gc
3023             # in Chapter 7: Perl
3024 206         463 # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
3025 206         376  
3026 206         853 my $e_script = '';
3027             while (not /\G \z/oxgc) { # member
3028             $e_script .= Windows1254::escape_token();
3029 75456         122400 }
3030              
3031             return $e_script;
3032             }
3033              
3034             #
3035             # escape Windows-1254 token of script
3036             #
3037             sub Windows1254::escape_token {
3038              
3039 206     75456 0 2811 # \n output here document
3040              
3041             my $ignore_modules = join('|', qw(
3042             utf8
3043             bytes
3044             charnames
3045             I18N::Japanese
3046             I18N::Collate
3047             I18N::JExt
3048             File::DosGlob
3049             Wild
3050             Wildcard
3051             Japanese
3052             ));
3053              
3054             # another member of Tag-team
3055             #
3056             # P.315 "Tag-team" matching with /gc
3057             # in Chapter 7: Perl
3058 75456 100 100     94319 # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
    100 66        
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    50          
    100          
    50          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    100          
    50          
    100          
    100          
    50          
    100          
    50          
    50          
    50          
    100          
    50          
    50          
    50          
    100          
    50          
    100          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    100          
    50          
    100          
    50          
    100          
    100          
    100          
    50          
    50          
    50          
    100          
    50          
    50          
    100          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    100          
    100          
    50          
    50          
    50          
    100          
    100          
    100          
    100          
    100          
    100          
    50          
    100          
    100          
    50          
    100          
    50          
    50          
    50          
    100          
    50          
    50          
    100          
    100          
    100          
    50          
3059 75456         2901866  
3060 12522 100       16129 if (/\G ( \n ) /oxgc) { # another member (and so on)
3061 12522         22596 my $heredoc = '';
3062             if (scalar(@heredoc_delimiter) >= 1) {
3063 174         244 $slash = 'm//';
3064 174         445  
3065             $heredoc = join '', @heredoc;
3066             @heredoc = ();
3067 174         319  
3068 174         304 # skip here document
3069             for my $heredoc_delimiter (@heredoc_delimiter) {
3070 174         1133 /\G .*? \n $heredoc_delimiter \n/xmsgc;
3071             }
3072 174         338 @heredoc_delimiter = ();
3073              
3074 174         264 $here_script = '';
3075             }
3076             return "\n" . $heredoc;
3077             }
3078 12522         37449  
3079             # ignore space, comment
3080             elsif (/\G ((?>\s+)|\#.*) /oxgc) { return $1; }
3081              
3082             # if (, elsif (, unless (, while (, until (, given (, and when (
3083              
3084             # given, when
3085              
3086             # P.225 The given Statement
3087             # in Chapter 15: Smart Matching and given-when
3088             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
3089              
3090             # P.133 The given Statement
3091             # in Chapter 4: Statements and Declarations
3092             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
3093 17927         56261  
3094 1401         2242 elsif (/\G ( (?: if | elsif | unless | while | until | given | when ) (?>\s*) \( ) /oxgc) {
3095             $slash = 'm//';
3096             return $1;
3097             }
3098              
3099             # scalar variable ($scalar = ...) =~ tr///;
3100             # scalar variable ($scalar = ...) =~ s///;
3101              
3102             # state
3103              
3104             # P.68 Persistent, Private Variables
3105             # in Chapter 4: Subroutines
3106             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
3107              
3108             # P.160 Persistent Lexically Scoped Variables: state
3109             # in Chapter 4: Statements and Declarations
3110             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
3111              
3112             # (and so on)
3113 1401         4604  
3114             elsif (/\G ( \( (?>\s*) (?: local \b | my \b | our \b | state \b )? (?>\s*) \$ $qq_scalar ) /oxgc) {
3115 86 50       185 my $e_string = e_string($1);
    50          
3116 86         2576  
3117 0         0 if (/\G ( (?>\s*) = $qq_paren \) ) ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= (?: tr | y ) \b ) /oxgc) {
3118 0         0 $tr_variable = $e_string . e_string($1);
3119 0         0 $bind_operator = $2;
3120             $slash = 'm//';
3121             return '';
3122 0         0 }
3123 0         0 elsif (/\G ( (?>\s*) = $qq_paren \) ) ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= s \b ) /oxgc) {
3124 0         0 $sub_variable = $e_string . e_string($1);
3125 0         0 $bind_operator = $2;
3126             $slash = 'm//';
3127             return '';
3128 0         0 }
3129 86         171 else {
3130             $slash = 'div';
3131             return $e_string;
3132             }
3133             }
3134              
3135 86         299 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ewindows1254::PREMATCH()
3136 4         8 elsif (/\G ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH \b | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) /oxmsgc) {
3137             $slash = 'div';
3138             return q{Ewindows1254::PREMATCH()};
3139             }
3140              
3141 4         15 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ewindows1254::MATCH()
3142 28         49 elsif (/\G ( \$& | \$\{&\} | \$ (?>\s*) MATCH \b | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) /oxmsgc) {
3143             $slash = 'div';
3144             return q{Ewindows1254::MATCH()};
3145             }
3146              
3147 28         160 # $', ${'} --> $', ${'}
3148 1         2 elsif (/\G ( \$' | \$\{'\} ) /oxmsgc) {
3149             $slash = 'div';
3150             return $1;
3151             }
3152              
3153 1         4 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ewindows1254::POSTMATCH()
3154 3         5 elsif (/\G ( \$ (?>\s*) POSTMATCH \b | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) /oxmsgc) {
3155             $slash = 'div';
3156             return q{Ewindows1254::POSTMATCH()};
3157             }
3158              
3159             # scalar variable $scalar =~ tr///;
3160             # scalar variable $scalar =~ s///;
3161             # substr() =~ tr///;
3162 3         10 # substr() =~ s///;
3163             elsif (/\G ( \$ $qq_scalar | $qq_substr ) /oxgc) {
3164 1673 100       3855 my $scalar = e_string($1);
    100          
3165 1673         6655  
3166 1         4 if (/\G ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= (?: tr | y ) \b ) /oxgc) {
3167 1         2 $tr_variable = $scalar;
3168 1         15 $bind_operator = $1;
3169             $slash = 'm//';
3170             return '';
3171 1         4 }
3172 61         134 elsif (/\G ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= s \b ) /oxgc) {
3173 61         131 $sub_variable = $scalar;
3174 61         95 $bind_operator = $1;
3175             $slash = 'm//';
3176             return '';
3177 61         196 }
3178 1611         2575 else {
3179             $slash = 'div';
3180             return $scalar;
3181             }
3182             }
3183              
3184 1611         4552 # end of statement
3185             elsif (/\G ( [,;] ) /oxgc) {
3186             $slash = 'm//';
3187 4995         7827  
3188             # clear tr/// variable
3189             $tr_variable = '';
3190 4995         6304  
3191             # clear s/// variable
3192 4995         6085 $sub_variable = '';
3193              
3194 4995         5827 $bind_operator = '';
3195              
3196             return $1;
3197             }
3198              
3199 4995         16927 # bareword
3200             elsif (/\G ( \{ (?>\s*) (?: tr | index | rindex | reverse ) (?>\s*) \} ) /oxmsgc) {
3201             return $1;
3202             }
3203              
3204 0         0 # $0 --> $0
3205 2         6 elsif (/\G ( \$ 0 ) /oxmsgc) {
3206             $slash = 'div';
3207             return $1;
3208 2         8 }
3209 0         0 elsif (/\G ( \$ \{ (?>\s*) 0 (?>\s*) \} ) /oxmsgc) {
3210             $slash = 'div';
3211             return $1;
3212             }
3213              
3214 0         0 # $$ --> $$
3215 1         2 elsif (/\G ( \$ \$ ) (?![\w\{]) /oxmsgc) {
3216             $slash = 'div';
3217             return $1;
3218             }
3219              
3220             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
3221 1         4 # $1, $2, $3 --> $1, $2, $3 otherwise
3222 4         7 elsif (/\G \$ ((?>[1-9][0-9]*)) /oxmsgc) {
3223             $slash = 'div';
3224             return e_capture($1);
3225 4         8 }
3226 0         0 elsif (/\G \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} /oxmsgc) {
3227             $slash = 'div';
3228             return e_capture($1);
3229             }
3230              
3231 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
3232 0         0 elsif (/\G \$ ( \$ (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ .+? \] ) /oxmsgc) {
3233             $slash = 'div';
3234             return e_capture($1.'->'.$2);
3235             }
3236              
3237 0         0 # $$foo{ ... } --> $ $foo->{ ... }
3238 0         0 elsif (/\G \$ ( \$ (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ .+? \} ) /oxmsgc) {
3239             $slash = 'div';
3240             return e_capture($1.'->'.$2);
3241             }
3242              
3243 0         0 # $$foo
3244 0         0 elsif (/\G \$ ( \$ (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) /oxmsgc) {
3245             $slash = 'div';
3246             return e_capture($1);
3247             }
3248              
3249 0         0 # ${ foo }
3250 0         0 elsif (/\G \$ (?>\s*) \{ ( (?>\s*) (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* ) (?>\s*) ) \} /oxmsgc) {
3251             $slash = 'div';
3252             return '${' . $1 . '}';
3253             }
3254              
3255 0         0 # ${ ... }
3256 0         0 elsif (/\G \$ (?>\s*) \{ (?>\s*) ( $qq_brace ) (?>\s*) \} /oxmsgc) {
3257             $slash = 'div';
3258             return e_capture($1);
3259             }
3260              
3261             # variable or function
3262 0         0 # $ @ % & * $ #
3263 42         66 elsif (/\G ( (?: [\$\@\%\&\*] | \$\# | -> | \b sub \b) (?>\s*) (?: split | chop | index | rindex | lc | uc | fc | chr | ord | reverse | getc | tr | y | q | qq | qx | qw | m | s | qr | glob | lstat | opendir | stat | unlink | chdir ) ) \b /oxmsgc) {
3264             $slash = 'div';
3265             return $1;
3266             }
3267             # $ $ $ $ $ $ $ $ $ $ $ $ $ $
3268 42         155 # $ @ # \ ' " / ? ( ) [ ] < >
3269 62         122 elsif (/\G ( \$[\$\@\#\\\'\"\/\?\(\)\[\]\<\>] ) /oxmsgc) {
3270             $slash = 'div';
3271             return $1;
3272             }
3273              
3274 62         236 # while ()
3275             elsif (/\G \b (while (?>\s*) \( (?>\s*) <[\$]?[A-Za-z_][A-Za-z_0-9]*> (?>\s*) \)) \b /oxgc) {
3276             return $1;
3277             }
3278              
3279             # while () --- glob
3280              
3281             # avoid "Error: Runtime exception" of perl version 5.005_03
3282 0         0  
3283             elsif (/\G \b while (?>\s*) \( (?>\s*) < ((?:[^>\0\a\e\f\n\r\t])+?) > (?>\s*) \) \b /oxgc) {
3284             return 'while ($_ = Ewindows1254::glob("' . $1 . '"))';
3285             }
3286              
3287 0         0 # while (glob)
3288             elsif (/\G \b while (?>\s*) \( (?>\s*) glob (?>\s*) \) /oxgc) {
3289             return 'while ($_ = Ewindows1254::glob_)';
3290             }
3291              
3292 0         0 # while (glob(WILDCARD))
3293             elsif (/\G \b while (?>\s*) \( (?>\s*) glob \b /oxgc) {
3294             return 'while ($_ = Ewindows1254::glob';
3295             }
3296 0         0  
  248         588  
3297             # doit if, doit unless, doit while, doit until, doit for, doit when
3298             elsif (/\G \b ( if | unless | while | until | for | when ) \b /oxgc) { $slash = 'm//'; return $1; }
3299 248         1000  
  19         36  
3300 19         72 # subroutines of package Ewindows1254
  0         0  
3301 0         0 elsif (/\G \b (CORE:: | ->(>?\s*) (?: atan2 | [a-z]{2,})) \b /oxgc) { $slash = 'm//'; return $1; }
  13         18  
3302 13         32 elsif (/\G \b Char::eval (?= (?>\s*) \{ ) /oxgc) { $slash = 'm//'; return 'eval'; }
  0         0  
3303 0         0 elsif (/\G \b Windows1254::eval (?= (?>\s*) \{ ) /oxgc) { $slash = 'm//'; return 'eval'; }
  114         174  
3304 114         302 elsif (/\G \b Char::eval \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'eval Char::escape'; }
  2         6  
3305 2         6 elsif (/\G \b Windows1254::eval \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'eval Windows1254::escape'; }
  0         0  
3306 0         0 elsif (/\G \b bytes::substr \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'substr'; }
  2         3  
3307 2         6 elsif (/\G \b chop \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::chop'; }
  0         0  
3308 0         0 elsif (/\G \b bytes::index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'index'; }
  0         0  
3309 0         0 elsif (/\G \b Char::index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Char::index'; }
  0         0  
3310 0         0 elsif (/\G \b Windows1254::index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Windows1254::index'; }
  2         4  
3311 2         7 elsif (/\G \b index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::index'; }
  0         0  
3312 0         0 elsif (/\G \b bytes::rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'rindex'; }
  0         0  
3313 0         0 elsif (/\G \b Char::rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Char::rindex'; }
  0         0  
3314 0         0 elsif (/\G \b Windows1254::rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Windows1254::rindex'; }
  1         2  
3315 1         3 elsif (/\G \b rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::rindex'; }
  0         0  
3316 0         0 elsif (/\G \b lc (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ewindows1254::lc'; }
  1         4  
3317 1         3 elsif (/\G \b lcfirst (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ewindows1254::lcfirst'; }
  0         0  
3318 0         0 elsif (/\G \b uc (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ewindows1254::uc'; }
  6         9  
3319             elsif (/\G \b ucfirst (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ewindows1254::ucfirst'; }
3320             elsif (/\G \b fc (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ewindows1254::fc'; }
3321 6         16  
  0         0  
3322 0         0 # "-s '' ..." means file test "-s 'filename' ..." (not means "- s/// ...")
  0         0  
3323 0         0 elsif (/\G -s (?>\s*) (\") ((?:$qq_char)+?) (\") /oxgc) { $slash = 'm//'; return '-s ' . e_qq('', $1,$3,$2); }
  0         0  
3324 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\#) ((?:$qq_char)+?) (\#) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
3325 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\() ((?:$qq_paren)+?) (\)) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
3326 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\{) ((?:$qq_brace)+?) (\}) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
3327 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\[) ((?:$qq_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
3328             elsif (/\G -s (?>\s+) qq (?>\s*) (\<) ((?:$qq_angle)+?) (\>) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
3329 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\S) ((?:$qq_char)+?) (\1) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
3330 0         0  
  0         0  
3331 0         0 elsif (/\G -s (?>\s*) (\') ((?:\\\'|\\\\|$q_char)+?) (\') /oxgc) { $slash = 'm//'; return '-s ' . e_q ('', $1,$3,$2); }
  0         0  
3332 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\#) ((?:\\\#|\\\\|$q_char)+?) (\#) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
3333 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\() ((?:\\\)|\\\\|$q_paren)+?) (\)) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
3334 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\{) ((?:\\\}|\\\\|$q_brace)+?) (\}) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
3335 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\[) ((?:\\\]|\\\\|$q_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
3336             elsif (/\G -s (?>\s+) q (?>\s*) (\<) ((?:\\\>|\\\\|$q_angle)+?) (\>) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
3337             elsif (/\G -s (?>\s+) q (?>\s*) (\S) ((?:\\\1|\\\\|$q_char)+?) (\1) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
3338 0         0  
  0         0  
3339 0         0 elsif (/\G -s (?>\s*) (\$ (?> \w+ (?: ::\w+)* ) (?: (?: ->)? (?: [\$\@\%\&\*]\* | \$\#\* | \( (?:$qq_paren)*? \) | [\@\%\*]? \{ (?:$qq_brace)+? \} | [\@\%]? \[ (?:$qq_bracket)+? \] ) )*) /oxgc)
  0         0  
3340 0         0 { $slash = 'm//'; return "-s $1"; }
  0         0  
3341 0         0 elsif (/\G -s (?>\s*) \( ((?:$qq_paren)*?) \) /oxgc) { $slash = 'm//'; return "-s ($1)"; }
  0         0  
3342             elsif (/\G -s (?= (?>\s+) [a-z]+) /oxgc) { $slash = 'm//'; return '-s'; }
3343 0         0 elsif (/\G -s (?>\s+) ((?>\w+)) /oxgc) { $slash = 'm//'; return "-s $1"; }
  2         4  
3344 2         6  
  2         16  
3345 2         7 elsif (/\G \b bytes::length (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'length'; }
  36         70  
3346 36         118 elsif (/\G \b bytes::chr (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'chr'; }
  2         5  
3347 2         7 elsif (/\G \b chr (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ewindows1254::chr'; }
  8         15  
3348 8         23 elsif (/\G \b bytes::ord (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'div'; return 'ord'; }
  0         0  
3349 0         0 elsif (/\G \b ord (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'div'; return $function_ord; }
  0         0  
3350 0         0 elsif (/\G \b glob (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ewindows1254::glob'; }
  0         0  
3351 0         0 elsif (/\G \b lc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::lc_'; }
  0         0  
3352 0         0 elsif (/\G \b lcfirst \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::lcfirst_'; }
  0         0  
3353 0         0 elsif (/\G \b uc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::uc_'; }
  0         0  
3354 0         0 elsif (/\G \b ucfirst \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::ucfirst_'; }
  0         0  
3355             elsif (/\G \b fc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::fc_'; }
3356 0         0 elsif (/\G -s \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return '-s '; }
  0         0  
3357 0         0  
  0         0  
3358 0         0 elsif (/\G \b bytes::length \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'length'; }
  0         0  
3359 0         0 elsif (/\G \b bytes::chr \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'chr'; }
  0         0  
3360 0         0 elsif (/\G \b chr \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::chr_'; }
  0         0  
3361 0         0 elsif (/\G \b bytes::ord \b (?! (?>\s*) => ) /oxgc) { $slash = 'div'; return 'ord'; }
  0         0  
3362 0         0 elsif (/\G \b ord \b (?! (?>\s*) => ) /oxgc) { $slash = 'div'; return $function_ord_; }
  0         0  
3363 0         0 elsif (/\G \b glob \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ewindows1254::glob_'; }
  8         19  
3364             elsif (/\G \b reverse \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return $function_reverse; }
3365             elsif (/\G \b getc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return $function_getc; }
3366 8         30 # split
3367             elsif (/\G \b (split) \b (?! (?>\s*) => ) /oxgc) {
3368 87         200 $slash = 'm//';
3369 87         174  
3370 87         365 my $e = '';
3371             while (/\G ( (?>\s+) | \( | \#.* ) /oxgc) {
3372             $e .= $1;
3373             }
3374 85 100       340  
  87 100       6114  
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    50          
    100          
    50          
    100          
    50          
    50          
    50          
3375             # end of split
3376             if (/\G (?= [,;\)\}\]] ) /oxgc) { return 'Ewindows1254::split' . $e; }
3377 2         9  
3378             # split scalar value
3379             elsif (/\G ( [\$\@\&\*] $qq_scalar ) /oxgc) { return 'Ewindows1254::split' . $e . e_string($1); }
3380 1         5  
3381 0         0 # split literal space
3382 0         0 elsif (/\G \b qq (\#) [ ] (\#) /oxgc) { return 'Ewindows1254::split' . $e . qq {qq$1 $2}; }
3383 0         0 elsif (/\G \b qq ((?>\s*)) (\() [ ] (\)) /oxgc) { return 'Ewindows1254::split' . $e . qq{$1qq$2 $3}; }
3384 0         0 elsif (/\G \b qq ((?>\s*)) (\{) [ ] (\}) /oxgc) { return 'Ewindows1254::split' . $e . qq{$1qq$2 $3}; }
3385 0         0 elsif (/\G \b qq ((?>\s*)) (\[) [ ] (\]) /oxgc) { return 'Ewindows1254::split' . $e . qq{$1qq$2 $3}; }
3386 0         0 elsif (/\G \b qq ((?>\s*)) (\<) [ ] (\>) /oxgc) { return 'Ewindows1254::split' . $e . qq{$1qq$2 $3}; }
3387 0         0 elsif (/\G \b qq ((?>\s*)) (\S) [ ] (\2) /oxgc) { return 'Ewindows1254::split' . $e . qq{$1qq$2 $3}; }
3388 0         0 elsif (/\G \b q (\#) [ ] (\#) /oxgc) { return 'Ewindows1254::split' . $e . qq {q$1 $2}; }
3389 0         0 elsif (/\G \b q ((?>\s*)) (\() [ ] (\)) /oxgc) { return 'Ewindows1254::split' . $e . qq {$1q$2 $3}; }
3390 0         0 elsif (/\G \b q ((?>\s*)) (\{) [ ] (\}) /oxgc) { return 'Ewindows1254::split' . $e . qq {$1q$2 $3}; }
3391 0         0 elsif (/\G \b q ((?>\s*)) (\[) [ ] (\]) /oxgc) { return 'Ewindows1254::split' . $e . qq {$1q$2 $3}; }
3392 0         0 elsif (/\G \b q ((?>\s*)) (\<) [ ] (\>) /oxgc) { return 'Ewindows1254::split' . $e . qq {$1q$2 $3}; }
3393 10         49 elsif (/\G \b q ((?>\s*)) (\S) [ ] (\2) /oxgc) { return 'Ewindows1254::split' . $e . qq {$1q$2 $3}; }
3394             elsif (/\G ' [ ] ' /oxgc) { return 'Ewindows1254::split' . $e . qq {' '}; }
3395             elsif (/\G " [ ] " /oxgc) { return 'Ewindows1254::split' . $e . qq {" "}; }
3396              
3397 0 0       0 # split qq//
  0         0  
3398             elsif (/\G \b (qq) \b /oxgc) {
3399 0         0 if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq# # --> qr # #
3400 0 0       0 else {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
3401 0         0 while (not /\G \z/oxgc) {
3402 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3403 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq ( ) --> qr ( )
3404 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq { } --> qr { }
3405 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq [ ] --> qr [ ]
3406 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq < > --> qr < >
3407             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) /oxgc) { return e_split($e.'qr','{','}',$2,''); } # qq | | --> qr { }
3408 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq * * --> qr * *
3409             }
3410             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3411             }
3412             }
3413              
3414 0 50       0 # split qr//
  12         427  
3415             elsif (/\G \b (qr) \b /oxgc) {
3416 0         0 if (/\G (\#) ((?:$qq_char)*?) (\#) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1,$3,$2,$4); } # qr# #
3417 12 50       66 else {
  12 50       3430  
    50          
    50          
    50          
    50          
    50          
    50          
3418 0         0 while (not /\G \z/oxgc) {
3419 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3420 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr ( )
3421 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr { }
3422 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr [ ]
3423 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr < >
3424 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([imosxpadlunbB]*) /oxgc) { return e_split_q($e.'qr',$1, $3, $2,$4); } # qr ' '
3425             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr','{','}',$2,$4); } # qr | | --> qr { }
3426 12         83 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr * *
3427             }
3428             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3429             }
3430             }
3431              
3432 0 0       0 # split q//
  0         0  
3433             elsif (/\G \b (q) \b /oxgc) {
3434 0         0 if (/\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q# # --> qr # #
3435 0 0       0 else {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
3436 0         0 while (not /\G \z/oxgc) {
3437 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3438 0         0 elsif (/\G (\() ((?:\\\\|\\\)|\\\(|$q_paren)*?) (\)) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q ( ) --> qr ( )
3439 0         0 elsif (/\G (\{) ((?:\\\\|\\\}|\\\{|$q_brace)*?) (\}) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q { } --> qr { }
3440 0         0 elsif (/\G (\[) ((?:\\\\|\\\]|\\\[|$q_bracket)*?) (\]) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q [ ] --> qr [ ]
3441 0         0 elsif (/\G (\<) ((?:\\\\|\\\>|\\\<|$q_angle)*?) (\>) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q < > --> qr < >
3442             elsif (/\G ([*\-:?\\^|]) ((?:$q_char)*?) (\1) /oxgc) { return e_split_q($e.'qr','{','}',$2,''); } # q | | --> qr { }
3443 0         0 elsif (/\G (\S) ((?:\\\\|\\\1| $q_char)*?) (\1) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q * * --> qr * *
3444             }
3445             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3446             }
3447             }
3448              
3449 0 50       0 # split m//
  18         485  
3450             elsif (/\G \b (m) \b /oxgc) {
3451 0         0 if (/\G (\#) ((?:$qq_char)*?) (\#) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1,$3,$2,$4); } # m# # --> qr # #
3452 18 50       87 else {
  18 50       3910  
    50          
    50          
    50          
    50          
    50          
    50          
3453 0         0 while (not /\G \z/oxgc) {
3454 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3455 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m ( ) --> qr ( )
3456 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m { } --> qr { }
3457 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m [ ] --> qr [ ]
3458 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m < > --> qr < >
3459 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cgimosxpadlunbB]*) /oxgc) { return e_split_q($e.'qr',$1, $3, $2,$4); } # m ' ' --> qr ' '
3460             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr','{','}',$2,$4); } # m | | --> qr { }
3461 18         111 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m * * --> qr * *
3462             }
3463             die __FILE__, ": Search pattern not terminated\n";
3464             }
3465             }
3466              
3467 0         0 # split ''
3468 0         0 elsif (/\G (\') /oxgc) {
3469 0 0       0 my $q_string = '';
  0 0       0  
    0          
    0          
3470 0         0 while (not /\G \z/oxgc) {
3471 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
3472 0         0 elsif (/\G (\\\') /oxgc) { $q_string .= $1; } # splitqr'' --> split qr''
3473             elsif (/\G \' /oxgc) { return e_split_q($e.q{ qr},"'","'",$q_string,''); } # ' ' --> qr ' '
3474 0         0 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
3475             }
3476             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3477             }
3478              
3479 0         0 # split ""
3480 0         0 elsif (/\G (\") /oxgc) {
3481 0 0       0 my $qq_string = '';
  0 0       0  
    0          
    0          
3482 0         0 while (not /\G \z/oxgc) {
3483 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
3484 0         0 elsif (/\G (\\\") /oxgc) { $qq_string .= $1; } # splitqr"" --> split qr""
3485             elsif (/\G \" /oxgc) { return e_split($e.q{ qr},'"','"',$qq_string,''); } # " " --> qr " "
3486 0         0 elsif (/\G ($q_char) /oxgc) { $qq_string .= $1; }
3487             }
3488             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3489             }
3490              
3491 0         0 # split //
3492 44         121 elsif (/\G (\/) /oxgc) {
3493 44 50       180 my $regexp = '';
  381 50       1696  
    100          
    50          
3494 0         0 while (not /\G \z/oxgc) {
3495 0         0 if (/\G (\\\\) /oxgc) { $regexp .= $1; }
3496 44         258 elsif (/\G (\\\/) /oxgc) { $regexp .= $1; } # splitqr// --> split qr//
3497             elsif (/\G \/ ([cgimosxpadlunbB]*) /oxgc) { return e_split($e.q{ qr}, '/','/',$regexp,$1); } # / / --> qr / /
3498 337         815 elsif (/\G ($q_char) /oxgc) { $regexp .= $1; }
3499             }
3500             die __FILE__, ": Search pattern not terminated\n";
3501             }
3502             }
3503              
3504             # tr/// or y///
3505              
3506             # about [cdsrbB]* (/B modifier)
3507             #
3508             # P.559 appendix C
3509             # of ISBN 4-89052-384-7 Programming perl
3510             # (Japanese title is: Perl puroguramingu)
3511 0         0  
3512             elsif (/\G \b ( tr | y ) \b /oxgc) {
3513             my $ope = $1;
3514 3 50       8  
3515 3         41 # $1 $2 $3 $4 $5 $6
3516 0         0 if (/\G (\#) ((?:$qq_char)*?) (\#) ((?:$qq_char)*?) (\#) ([cdsrbB]*) /oxgc) { # tr# # #
3517             my @tr = ($tr_variable,$2);
3518             return e_tr(@tr,'',$4,$6);
3519 0         0 }
3520 3         7 else {
3521 3 50       11 my $e = '';
  3 50       246  
    50          
    50          
    50          
    50          
3522             while (not /\G \z/oxgc) {
3523 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3524 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) {
3525 0 0       0 my @tr = ($tr_variable,$2);
  0 0       0  
    0          
    0          
    0          
    0          
3526 0         0 while (not /\G \z/oxgc) {
3527 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3528 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) ( )
3529 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) { }
3530 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) [ ]
3531             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) < >
3532 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) * *
3533             }
3534             die __FILE__, ": Transliteration replacement not terminated\n";
3535 0         0 }
3536 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) {
3537 0 0       0 my @tr = ($tr_variable,$2);
  0 0       0  
    0          
    0          
    0          
    0          
3538 0         0 while (not /\G \z/oxgc) {
3539 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3540 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } ( )
3541 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } { }
3542 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } [ ]
3543             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } < >
3544 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } * *
3545             }
3546             die __FILE__, ": Transliteration replacement not terminated\n";
3547 0         0 }
3548 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) {
3549 0 0       0 my @tr = ($tr_variable,$2);
  0 0       0  
    0          
    0          
    0          
    0          
3550 0         0 while (not /\G \z/oxgc) {
3551 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3552 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] ( )
3553 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] { }
3554 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] [ ]
3555             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] < >
3556 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] * *
3557             }
3558             die __FILE__, ": Transliteration replacement not terminated\n";
3559 0         0 }
3560 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) {
3561 0 0       0 my @tr = ($tr_variable,$2);
  0 0       0  
    0          
    0          
    0          
    0          
3562 0         0 while (not /\G \z/oxgc) {
3563 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3564 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > ( )
3565 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > { }
3566 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > [ ]
3567             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > < >
3568 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > * *
3569             }
3570             die __FILE__, ": Transliteration replacement not terminated\n";
3571             }
3572 0         0 # $1 $2 $3 $4 $5 $6
3573 3         12 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { # tr * * *
3574             my @tr = ($tr_variable,$2);
3575             return e_tr(@tr,'',$4,$6);
3576 3         11 }
3577             }
3578             die __FILE__, ": Transliteration pattern not terminated\n";
3579             }
3580             }
3581              
3582 0         0 # qq//
3583             elsif (/\G \b (qq) \b /oxgc) {
3584             my $ope = $1;
3585 2180 50       5076  
3586 2180         4136 # if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { return e_qq($ope,$1,$3,$2); } # qq# #
3587 0         0 if (/\G (\#) /oxgc) { # qq# #
3588 0 0       0 my $qq_string = '';
  0 0       0  
    0          
    0          
3589 0         0 while (not /\G \z/oxgc) {
3590 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
3591 0         0 elsif (/\G (\\\#) /oxgc) { $qq_string .= $1; }
3592             elsif (/\G (\#) /oxgc) { return e_qq($ope,'#','#',$qq_string); }
3593 0         0 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
3594             }
3595             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3596             }
3597 0         0  
3598 2180         3114 else {
3599 2180 50       5164 my $e = '';
  2180 50       8881  
    100          
    50          
    50          
    0          
3600             while (not /\G \z/oxgc) {
3601             if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3602              
3603 0         0 # elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq ( )
3604 0         0 elsif (/\G (\() /oxgc) { # qq ( )
3605 0         0 my $qq_string = '';
3606 0 0       0 local $nest = 1;
  0 0       0  
    0          
    0          
    0          
3607 0         0 while (not /\G \z/oxgc) {
3608 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
  0         0  
3609             elsif (/\G (\\\)) /oxgc) { $qq_string .= $1; }
3610 0 0       0 elsif (/\G (\() /oxgc) { $qq_string .= $1; $nest++; }
  0         0  
3611 0         0 elsif (/\G (\)) /oxgc) {
3612             if (--$nest == 0) { return $e . e_qq($ope,'(',')',$qq_string); }
3613 0         0 else { $qq_string .= $1; }
3614             }
3615 0         0 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
3616             }
3617             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3618             }
3619              
3620 0         0 # elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq { }
3621 2150         3018 elsif (/\G (\{) /oxgc) { # qq { }
3622 2150         3062 my $qq_string = '';
3623 2150 100       4780 local $nest = 1;
  84071 50       264388  
    100          
    100          
    50          
3624 722         1408 while (not /\G \z/oxgc) {
3625 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
  1153         1625  
3626             elsif (/\G (\\\}) /oxgc) { $qq_string .= $1; }
3627 1153 100       2048 elsif (/\G (\{) /oxgc) { $qq_string .= $1; $nest++; }
  3303         5268  
3628 2150         4594 elsif (/\G (\}) /oxgc) {
3629             if (--$nest == 0) { return $e . e_qq($ope,'{','}',$qq_string); }
3630 1153         2466 else { $qq_string .= $1; }
3631             }
3632 78893         158174 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
3633             }
3634             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3635             }
3636              
3637 0         0 # elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq [ ]
3638 0         0 elsif (/\G (\[) /oxgc) { # qq [ ]
3639 0         0 my $qq_string = '';
3640 0 0       0 local $nest = 1;
  0 0       0  
    0          
    0          
    0          
3641 0         0 while (not /\G \z/oxgc) {
3642 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
  0         0  
3643             elsif (/\G (\\\]) /oxgc) { $qq_string .= $1; }
3644 0 0       0 elsif (/\G (\[) /oxgc) { $qq_string .= $1; $nest++; }
  0         0  
3645 0         0 elsif (/\G (\]) /oxgc) {
3646             if (--$nest == 0) { return $e . e_qq($ope,'[',']',$qq_string); }
3647 0         0 else { $qq_string .= $1; }
3648             }
3649 0         0 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
3650             }
3651             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3652             }
3653              
3654 0         0 # elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq < >
3655 30         56 elsif (/\G (\<) /oxgc) { # qq < >
3656 30         57 my $qq_string = '';
3657 30 100       96 local $nest = 1;
  1166 50       4115  
    50          
    100          
    50          
3658 22         63 while (not /\G \z/oxgc) {
3659 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
  0         0  
3660             elsif (/\G (\\\>) /oxgc) { $qq_string .= $1; }
3661 0 50       0 elsif (/\G (\<) /oxgc) { $qq_string .= $1; $nest++; }
  30         73  
3662 30         75 elsif (/\G (\>) /oxgc) {
3663             if (--$nest == 0) { return $e . e_qq($ope,'<','>',$qq_string); }
3664 0         0 else { $qq_string .= $1; }
3665             }
3666 1114         2339 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
3667             }
3668             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3669             }
3670              
3671 0         0 # elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq * *
3672 0         0 elsif (/\G (\S) /oxgc) { # qq * *
3673 0         0 my $delimiter = $1;
3674 0 0       0 my $qq_string = '';
  0 0       0  
    0          
    0          
3675 0         0 while (not /\G \z/oxgc) {
3676 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
3677 0         0 elsif (/\G (\\\Q$delimiter\E) /oxgc) { $qq_string .= $1; }
3678             elsif (/\G (\Q$delimiter\E) /oxgc) { return $e . e_qq($ope,$delimiter,$delimiter,$qq_string); }
3679 0         0 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
3680             }
3681             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3682 0         0 }
3683             }
3684             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3685             }
3686             }
3687              
3688 0         0 # qr//
3689 0 0       0 elsif (/\G \b (qr) \b /oxgc) {
3690 0         0 my $ope = $1;
3691             if (/\G (\#) ((?:$qq_char)*?) (\#) ([imosxpadlunbB]*) /oxgc) { # qr# # #
3692             return e_qr($ope,$1,$3,$2,$4);
3693 0         0 }
3694 0         0 else {
3695 0 0       0 my $e = '';
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
3696 0         0 while (not /\G \z/oxgc) {
3697 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3698 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr ( )
3699 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr { }
3700 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr [ ]
3701 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr < >
3702 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([imosxpadlunbB]*) /oxgc) { return $e . e_qr_q($ope,$1, $3, $2,$4); } # qr ' '
3703             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,'{','}',$2,$4); } # qr | | --> qr { }
3704 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr * *
3705             }
3706             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3707             }
3708             }
3709              
3710 0         0 # qw//
3711 16 50       51 elsif (/\G \b (qw) \b /oxgc) {
3712 16         85 my $ope = $1;
3713             if (/\G (\#) (.*?) (\#) /oxmsgc) { # qw# #
3714             return e_qw($ope,$1,$3,$2);
3715 0         0 }
3716 16         33 else {
3717 16 50       55 my $e = '';
  16 50       95  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
3718             while (not /\G \z/oxgc) {
3719 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3720 16         60  
3721             elsif (/\G (\() ([^(]*?) (\)) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw ( )
3722 0         0 elsif (/\G (\() ((?:$q_paren)*?) (\)) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw ( )
3723 0         0  
3724             elsif (/\G (\{) ([^{]*?) (\}) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw { }
3725 0         0 elsif (/\G (\{) ((?:$q_brace)*?) (\}) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw { }
3726 0         0  
3727             elsif (/\G (\[) ([^[]*?) (\]) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw [ ]
3728 0         0 elsif (/\G (\[) ((?:$q_bracket)*?) (\]) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw [ ]
3729 0         0  
3730             elsif (/\G (\<) ([^<]*?) (\>) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw < >
3731 0         0 elsif (/\G (\<) ((?:$q_angle)*?) (\>) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw < >
3732 0         0  
3733             elsif (/\G ([\x21-\x3F]) (.*?) (\1) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw * *
3734 0         0 elsif (/\G (\S) ((?:$q_char)*?) (\1) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw * *
3735             }
3736             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3737             }
3738             }
3739              
3740 0         0 # qx//
3741 0 0       0 elsif (/\G \b (qx) \b /oxgc) {
3742 0         0 my $ope = $1;
3743             if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { # qx# #
3744             return e_qq($ope,$1,$3,$2);
3745 0         0 }
3746 0         0 else {
3747 0 0       0 my $e = '';
  0 0       0  
    0          
    0          
    0          
    0          
    0          
3748 0         0 while (not /\G \z/oxgc) {
3749 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3750 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx ( )
3751 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx { }
3752 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx [ ]
3753 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx < >
3754             elsif (/\G (\') ((?:$qq_char)*?) (\') /oxgc) { return $e . e_q ($ope,$1,$3,$2); } # qx ' '
3755 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx * *
3756             }
3757             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3758             }
3759             }
3760              
3761 0         0 # q//
3762             elsif (/\G \b (q) \b /oxgc) {
3763             my $ope = $1;
3764              
3765             # if (/\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { return e_q($ope,$1,$3,$2); } # q# #
3766              
3767             # avoid "Error: Runtime exception" of perl version 5.005_03
3768 410 50       1153 # (and so on)
3769 410         1032  
3770 0         0 if (/\G (\#) /oxgc) { # q# #
3771 0 0       0 my $q_string = '';
  0 0       0  
    0          
    0          
3772 0         0 while (not /\G \z/oxgc) {
3773 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
3774 0         0 elsif (/\G (\\\#) /oxgc) { $q_string .= $1; }
3775             elsif (/\G (\#) /oxgc) { return e_q($ope,'#','#',$q_string); }
3776 0         0 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
3777             }
3778             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3779             }
3780 0         0  
3781 410         752 else {
3782 410 50       1267 my $e = '';
  410 50       2187  
    100          
    50          
    100          
    50          
3783             while (not /\G \z/oxgc) {
3784             if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3785              
3786 0         0 # elsif (/\G (\() ((?:\\\)|\\\\|$q_paren)*?) (\)) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q ( )
3787 0         0 elsif (/\G (\() /oxgc) { # q ( )
3788 0         0 my $q_string = '';
3789 0 0       0 local $nest = 1;
  0 0       0  
    0          
    0          
    0          
    0          
3790 0         0 while (not /\G \z/oxgc) {
3791 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
3792 0         0 elsif (/\G (\\\)) /oxgc) { $q_string .= $1; }
  0         0  
3793             elsif (/\G (\\\() /oxgc) { $q_string .= $1; }
3794 0 0       0 elsif (/\G (\() /oxgc) { $q_string .= $1; $nest++; }
  0         0  
3795 0         0 elsif (/\G (\)) /oxgc) {
3796             if (--$nest == 0) { return $e . e_q($ope,'(',')',$q_string); }
3797 0         0 else { $q_string .= $1; }
3798             }
3799 0         0 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
3800             }
3801             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3802             }
3803              
3804 0         0 # elsif (/\G (\{) ((?:\\\}|\\\\|$q_brace)*?) (\}) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q { }
3805 404         682 elsif (/\G (\{) /oxgc) { # q { }
3806 404         727 my $q_string = '';
3807 404 50       1088 local $nest = 1;
  6835 50       24712  
    50          
    100          
    100          
    50          
3808 0         0 while (not /\G \z/oxgc) {
3809 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
3810 0         0 elsif (/\G (\\\}) /oxgc) { $q_string .= $1; }
  107         163  
3811             elsif (/\G (\\\{) /oxgc) { $q_string .= $1; }
3812 107 100       227 elsif (/\G (\{) /oxgc) { $q_string .= $1; $nest++; }
  511         1008  
3813 404         1125 elsif (/\G (\}) /oxgc) {
3814             if (--$nest == 0) { return $e . e_q($ope,'{','}',$q_string); }
3815 107         230 else { $q_string .= $1; }
3816             }
3817 6217         11879 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
3818             }
3819             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3820             }
3821              
3822 0         0 # elsif (/\G (\[) ((?:\\\]|\\\\|$q_bracket)*?) (\]) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q [ ]
3823 0         0 elsif (/\G (\[) /oxgc) { # q [ ]
3824 0         0 my $q_string = '';
3825 0 0       0 local $nest = 1;
  0 0       0  
    0          
    0          
    0          
    0          
3826 0         0 while (not /\G \z/oxgc) {
3827 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
3828 0         0 elsif (/\G (\\\]) /oxgc) { $q_string .= $1; }
  0         0  
3829             elsif (/\G (\\\[) /oxgc) { $q_string .= $1; }
3830 0 0       0 elsif (/\G (\[) /oxgc) { $q_string .= $1; $nest++; }
  0         0  
3831 0         0 elsif (/\G (\]) /oxgc) {
3832             if (--$nest == 0) { return $e . e_q($ope,'[',']',$q_string); }
3833 0         0 else { $q_string .= $1; }
3834             }
3835 0         0 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
3836             }
3837             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3838             }
3839              
3840 0         0 # elsif (/\G (\<) ((?:\\\>|\\\\|$q_angle)*?) (\>) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q < >
3841 5         29 elsif (/\G (\<) /oxgc) { # q < >
3842 5         23 my $q_string = '';
3843 5 50       21 local $nest = 1;
  88 50       479  
    50          
    50          
    100          
    50          
3844 0         0 while (not /\G \z/oxgc) {
3845 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
3846 0         0 elsif (/\G (\\\>) /oxgc) { $q_string .= $1; }
  0         0  
3847             elsif (/\G (\\\<) /oxgc) { $q_string .= $1; }
3848 0 50       0 elsif (/\G (\<) /oxgc) { $q_string .= $1; $nest++; }
  5         15  
3849 5         17 elsif (/\G (\>) /oxgc) {
3850             if (--$nest == 0) { return $e . e_q($ope,'<','>',$q_string); }
3851 0         0 else { $q_string .= $1; }
3852             }
3853 83         195 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
3854             }
3855             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3856             }
3857              
3858 0         0 # elsif (/\G (\S) ((?:\\\1|\\\\|$q_char)*?) (\1) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q * *
3859 1         4 elsif (/\G (\S) /oxgc) { # q * *
3860 1         2 my $delimiter = $1;
3861 1 50       3 my $q_string = '';
  14 50       67  
    100          
    50          
3862 0         0 while (not /\G \z/oxgc) {
3863 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
3864 1         3 elsif (/\G (\\\Q$delimiter\E) /oxgc) { $q_string .= $1; }
3865             elsif (/\G (\Q$delimiter\E) /oxgc) { return $e . e_q($ope,$delimiter,$delimiter,$q_string); }
3866 13         28 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
3867             }
3868             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3869 0         0 }
3870             }
3871             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
3872             }
3873             }
3874              
3875 0         0 # m//
3876 209 50       509 elsif (/\G \b (m) \b /oxgc) {
3877 209         1346 my $ope = $1;
3878             if (/\G (\#) ((?:$qq_char)*?) (\#) ([cgimosxpadlunbB]*) /oxgc) { # m# #
3879             return e_qr($ope,$1,$3,$2,$4);
3880 0         0 }
3881 209         330 else {
3882 209 50       619 my $e = '';
  209 50       11181  
    50          
    50          
    50          
    50          
    100          
    50          
    50          
3883 0         0 while (not /\G \z/oxgc) {
3884 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3885 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m ( )
3886 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m { }
3887 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m [ ]
3888 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m < >
3889 10         33 elsif (/\G (\?) ((?:$qq_char)*?) (\?) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m ? ?
3890 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr_q($ope,$1, $3, $2,$4); } # m ' '
3891             elsif (/\G ([*\-:\\^|]) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,'{','}',$2,$4); } # m | | --> m { }
3892 199         712 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m * *
3893             }
3894             die __FILE__, ": Search pattern not terminated\n";
3895             }
3896             }
3897              
3898             # s///
3899              
3900             # about [cegimosxpradlunbB]* (/cg modifier)
3901             #
3902             # P.67 Pattern-Matching Operators
3903             # of ISBN 0-596-00241-6 Perl in a Nutshell, Second Edition.
3904 0         0  
3905             elsif (/\G \b (s) \b /oxgc) {
3906             my $ope = $1;
3907 97 100       280  
3908 97         1733 # $1 $2 $3 $4 $5 $6
3909             if (/\G (\#) ((?:$qq_char)*?) (\#) ((?:$qq_char)*?) (\#) ([cegimosxpradlunbB]*) /oxgc) { # s# # #
3910             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
3911 1         5 }
3912 96         232 else {
3913 96 50       320 my $e = '';
  96 50       12178  
    50          
    50          
    50          
    100          
    50          
    50          
    50          
3914             while (not /\G \z/oxgc) {
3915 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3916 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) {
3917 0 0       0 my @s = ($1,$2,$3);
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
3918             while (not /\G \z/oxgc) {
3919 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3920 0         0 # $1 $2 $3 $4
3921 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3922 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3923 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3924 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3925 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3926 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3927 0         0 elsif (/\G (\:) ((?:$qq_char)*?) (\:) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3928             elsif (/\G (\@) ((?:$qq_char)*?) (\@) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3929 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3930             }
3931             die __FILE__, ": Substitution replacement not terminated\n";
3932 0         0 }
3933 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) {
3934 0 0       0 my @s = ($1,$2,$3);
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
3935             while (not /\G \z/oxgc) {
3936 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3937 0         0 # $1 $2 $3 $4
3938 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3939 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3940 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3941 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3942 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3943 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3944 0         0 elsif (/\G (\:) ((?:$qq_char)*?) (\:) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3945             elsif (/\G (\@) ((?:$qq_char)*?) (\@) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3946 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3947             }
3948             die __FILE__, ": Substitution replacement not terminated\n";
3949 0         0 }
3950 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) {
3951 0 0       0 my @s = ($1,$2,$3);
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
3952             while (not /\G \z/oxgc) {
3953 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3954 0         0 # $1 $2 $3 $4
3955 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3956 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3957 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3958 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3959 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3960             elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3961 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3962             }
3963             die __FILE__, ": Substitution replacement not terminated\n";
3964 0         0 }
3965 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) {
3966 0 0       0 my @s = ($1,$2,$3);
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
3967             while (not /\G \z/oxgc) {
3968 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
3969 0         0 # $1 $2 $3 $4
3970 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3971 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3972 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3973 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3974 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3975 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3976 0         0 elsif (/\G (\:) ((?:$qq_char)*?) (\:) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3977             elsif (/\G (\@) ((?:$qq_char)*?) (\@) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3978 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
3979             }
3980             die __FILE__, ": Substitution replacement not terminated\n";
3981             }
3982 0         0 # $1 $2 $3 $4 $5 $6
3983             elsif (/\G (\') ((?:$qq_char)*?) (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) {
3984             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
3985             }
3986 21         70 # $1 $2 $3 $4 $5 $6
3987             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) {
3988             return e_sub($sub_variable,'{',$2,'}','{',$4,'}',$6); # s | | | --> s { } { }
3989             }
3990 0         0 # $1 $2 $3 $4 $5 $6
3991             elsif (/\G (\$) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) {
3992             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
3993             }
3994 0         0 # $1 $2 $3 $4 $5 $6
3995             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) {
3996             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
3997 75         360 }
3998             }
3999             die __FILE__, ": Substitution pattern not terminated\n";
4000             }
4001             }
4002 0         0  
4003 0         0 # require ignore module
4004 0         0 elsif (/\G \b require ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "# require$1$2"; }
4005             elsif (/\G \b require ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [^#]) /oxmsgc) { return "# require$1\n$2"; }
4006             elsif (/\G \b require ((?>\s+) (?:$ignore_modules)) \b /oxmsgc) { return "# require$1"; }
4007 0         0  
4008 37         330 # use strict; --> use strict; no strict qw(refs);
4009 0         0 elsif (/\G \b use ((?>\s+) strict .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "use$1 no strict qw(refs);$2"; }
4010             elsif (/\G \b use ((?>\s+) strict .*? ;) ([ \t]* [^#]) /oxmsgc) { return "use$1 no strict qw(refs);\n$2"; }
4011             elsif (/\G \b use ((?>\s+) strict) \b /oxmsgc) { return "use$1; no strict qw(refs)"; }
4012              
4013 0 50 33     0 # use 5.12.0; --> use 5.12.0; no strict qw(refs);
      33        
4014 2         28 elsif (/\G \b use (?>\s+) ((?>([1-9][0-9_]*)(?:\.([0-9_]+))*)) (?>\s*) ; /oxmsgc) {
4015             if (($2 >= 6) or (($2 == 5) and ($3 ge '012'))) {
4016             return "use $1; no strict qw(refs);";
4017 0         0 }
4018             else {
4019             return "use $1;";
4020             }
4021 2 0 0     12 }
      0        
4022 0         0 elsif (/\G \b use (?>\s+) ((?>v([0-9][0-9_]*)(?:\.([0-9_]+))*)) (?>\s*) ; /oxmsgc) {
4023             if (($2 >= 6) or (($2 == 5) and ($3 >= 12))) {
4024             return "use $1; no strict qw(refs);";
4025 0         0 }
4026             else {
4027             return "use $1;";
4028             }
4029             }
4030 0         0  
4031 2         14 # ignore use module
4032 0         0 elsif (/\G \b use ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "# use$1$2"; }
4033             elsif (/\G \b use ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [^#]) /oxmsgc) { return "# use$1\n$2"; }
4034             elsif (/\G \b use ((?>\s+) (?:$ignore_modules)) \b /oxmsgc) { return "# use$1"; }
4035 0         0  
4036 0         0 # ignore no module
4037 0         0 elsif (/\G \b no ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "# no$1$2"; }
4038             elsif (/\G \b no ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [^#]) /oxmsgc) { return "# no$1\n$2"; }
4039             elsif (/\G \b no ((?>\s+) (?:$ignore_modules)) \b /oxmsgc) { return "# no$1"; }
4040 0         0  
4041             # use else
4042             elsif (/\G \b use \b /oxmsgc) { return "use"; }
4043 0         0  
4044             # use else
4045             elsif (/\G \b no \b /oxmsgc) { return "no"; }
4046              
4047 2         9 # ''
4048 848         1776 elsif (/\G (?
4049 848 100       2367 my $q_string = '';
  8319 100       27643  
    100          
    50          
4050 4         9 while (not /\G \z/oxgc) {
4051 48         87 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
4052 848         2096 elsif (/\G (\\\') /oxgc) { $q_string .= $1; }
4053             elsif (/\G \' /oxgc) { return e_q('', "'","'",$q_string); }
4054 7419         14947 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
4055             }
4056             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
4057             }
4058              
4059 0         0 # ""
4060 1782         3808 elsif (/\G (\") /oxgc) {
4061 1782 100       4466 my $qq_string = '';
  36056 100       105157  
    100          
    50          
4062 67         167 while (not /\G \z/oxgc) {
4063 12         28 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
4064 1782         4218 elsif (/\G (\\\") /oxgc) { $qq_string .= $1; }
4065             elsif (/\G \" /oxgc) { return e_qq('', '"','"',$qq_string); }
4066 34195         69466 elsif (/\G ($q_char) /oxgc) { $qq_string .= $1; }
4067             }
4068             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
4069             }
4070              
4071 0         0 # ``
4072 1         2 elsif (/\G (\`) /oxgc) {
4073 1 50       5 my $qx_string = '';
  19 50       66  
    100          
    50          
4074 0         0 while (not /\G \z/oxgc) {
4075 0         0 if (/\G (\\\\) /oxgc) { $qx_string .= $1; }
4076 1         2 elsif (/\G (\\\`) /oxgc) { $qx_string .= $1; }
4077             elsif (/\G \` /oxgc) { return e_qq('', '`','`',$qx_string); }
4078 18         35 elsif (/\G ($q_char) /oxgc) { $qx_string .= $1; }
4079             }
4080             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
4081             }
4082              
4083 0         0 # // --- not divide operator (num / num), not defined-or
4084 453         1122 elsif (($slash eq 'm//') and /\G (\/) /oxgc) {
4085 453 50       1411 my $regexp = '';
  4496 50       15853  
    100          
    50          
4086 0         0 while (not /\G \z/oxgc) {
4087 0         0 if (/\G (\\\\) /oxgc) { $regexp .= $1; }
4088 453         1341 elsif (/\G (\\\/) /oxgc) { $regexp .= $1; }
4089             elsif (/\G \/ ([cgimosxpadlunbB]*) /oxgc) { return e_qr('', '/','/',$regexp,$1); }
4090 4043         8679 elsif (/\G ($q_char) /oxgc) { $regexp .= $1; }
4091             }
4092             die __FILE__, ": Search pattern not terminated\n";
4093             }
4094              
4095 0         0 # ?? --- not conditional operator (condition ? then : else)
4096 0         0 elsif (($slash eq 'm//') and /\G (\?) /oxgc) {
4097 0 0       0 my $regexp = '';
  0 0       0  
    0          
    0          
4098 0         0 while (not /\G \z/oxgc) {
4099 0         0 if (/\G (\\\\) /oxgc) { $regexp .= $1; }
4100 0         0 elsif (/\G (\\\?) /oxgc) { $regexp .= $1; }
4101             elsif (/\G \? ([cgimosxpadlunbB]*) /oxgc) { return e_qr('m','?','?',$regexp,$1); }
4102 0         0 elsif (/\G ($q_char) /oxgc) { $regexp .= $1; }
4103             }
4104             die __FILE__, ": Search pattern not terminated\n";
4105             }
4106 0         0  
  0         0  
4107             # <<>> (a safer ARGV)
4108             elsif (/\G ( <<>> ) /oxgc) { $slash = 'm//'; return $1; }
4109 0         0  
  0         0  
4110             # << (bit shift) --- not here document
4111             elsif (/\G ( << (?>\s*) ) (?= [0-9\$\@\&] ) /oxgc) { $slash = 'm//'; return $1; }
4112              
4113 0         0 # <<~'HEREDOC'
4114 6         15 elsif (/\G ( <<~ [\t ]* '([a-zA-Z_0-9]*)' ) /oxgc) {
4115 6         11 $slash = 'm//';
4116             my $here_quote = $1;
4117             my $delimiter = $2;
4118 6 50       10  
4119 6         13 # get here document
4120 6         26 if ($here_script eq '') {
4121             $here_script = CORE::substr $_, pos $_;
4122 6 50       33 $here_script =~ s/.*?\n//oxm;
4123 6         65 }
4124 6         14 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
4125 6         8 my $heredoc = $1;
4126 6         45 my $indent = $2;
4127 6         17 $heredoc =~ s{^$indent}{}msg; # no /ox
4128             push @heredoc, $heredoc . qq{\n$delimiter\n};
4129             push @heredoc_delimiter, qq{\\s*$delimiter};
4130 6         13 }
4131             else {
4132 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4133             }
4134             return qq{<<'$delimiter'};
4135             }
4136              
4137             # <<~\HEREDOC
4138              
4139             # P.66 2.6.6. "Here" Documents
4140             # in Chapter 2: Bits and Pieces
4141             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
4142              
4143             # P.73 "Here" Documents
4144             # in Chapter 2: Bits and Pieces
4145             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
4146 6         24  
4147 3         7 elsif (/\G ( <<~ \\([a-zA-Z_0-9]+) ) /oxgc) {
4148 3         7 $slash = 'm//';
4149             my $here_quote = $1;
4150             my $delimiter = $2;
4151 3 50       6  
4152 3         9 # get here document
4153 3         24 if ($here_script eq '') {
4154             $here_script = CORE::substr $_, pos $_;
4155 3 50       17 $here_script =~ s/.*?\n//oxm;
4156 3         46 }
4157 3         8 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
4158 3         6 my $heredoc = $1;
4159 3         39 my $indent = $2;
4160 3         13 $heredoc =~ s{^$indent}{}msg; # no /ox
4161             push @heredoc, $heredoc . qq{\n$delimiter\n};
4162             push @heredoc_delimiter, qq{\\s*$delimiter};
4163 3         7 }
4164             else {
4165 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4166             }
4167             return qq{<<\\$delimiter};
4168             }
4169              
4170 3         12 # <<~"HEREDOC"
4171 6         13 elsif (/\G ( <<~ [\t ]* "([a-zA-Z_0-9]*)" ) /oxgc) {
4172 6         15 $slash = 'm//';
4173             my $here_quote = $1;
4174             my $delimiter = $2;
4175 6 50       12  
4176 6         14 # get here document
4177 6         31 if ($here_script eq '') {
4178             $here_script = CORE::substr $_, pos $_;
4179 6 50       37 $here_script =~ s/.*?\n//oxm;
4180 6         62 }
4181 6         22 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
4182 6         10 my $heredoc = $1;
4183 6         52 my $indent = $2;
4184 6         18 $heredoc =~ s{^$indent}{}msg; # no /ox
4185             push @heredoc, e_heredoc($heredoc) . qq{\n$delimiter\n};
4186             push @heredoc_delimiter, qq{\\s*$delimiter};
4187 6         17 }
4188             else {
4189 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4190             }
4191             return qq{<<"$delimiter"};
4192             }
4193              
4194 6         26 # <<~HEREDOC
4195 3         12 elsif (/\G ( <<~ ([a-zA-Z_0-9]+) ) /oxgc) {
4196 3         7 $slash = 'm//';
4197             my $here_quote = $1;
4198             my $delimiter = $2;
4199 3 50       7  
4200 3         7 # get here document
4201 3         33 if ($here_script eq '') {
4202             $here_script = CORE::substr $_, pos $_;
4203 3 50       20 $here_script =~ s/.*?\n//oxm;
4204 3         49 }
4205 3         10 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
4206 3         4 my $heredoc = $1;
4207 3         42 my $indent = $2;
4208 3         10 $heredoc =~ s{^$indent}{}msg; # no /ox
4209             push @heredoc, e_heredoc($heredoc) . qq{\n$delimiter\n};
4210             push @heredoc_delimiter, qq{\\s*$delimiter};
4211 3         9 }
4212             else {
4213 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4214             }
4215             return qq{<<$delimiter};
4216             }
4217              
4218 3         15 # <<~`HEREDOC`
4219 6         16 elsif (/\G ( <<~ [\t ]* `([a-zA-Z_0-9]*)` ) /oxgc) {
4220 6         11 $slash = 'm//';
4221             my $here_quote = $1;
4222             my $delimiter = $2;
4223 6 50       25  
4224 6         20 # get here document
4225 6         19 if ($here_script eq '') {
4226             $here_script = CORE::substr $_, pos $_;
4227 6 50       43 $here_script =~ s/.*?\n//oxm;
4228 6         66 }
4229 6         17 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
4230 6         8 my $heredoc = $1;
4231 6         55 my $indent = $2;
4232 6         20 $heredoc =~ s{^$indent}{}msg; # no /ox
4233             push @heredoc, e_heredoc($heredoc) . qq{\n$delimiter\n};
4234             push @heredoc_delimiter, qq{\\s*$delimiter};
4235 6         18 }
4236             else {
4237 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4238             }
4239             return qq{<<`$delimiter`};
4240             }
4241              
4242 6         36 # <<'HEREDOC'
4243 72         147 elsif (/\G ( << '([a-zA-Z_0-9]*)' ) /oxgc) {
4244 72         146 $slash = 'm//';
4245             my $here_quote = $1;
4246             my $delimiter = $2;
4247 72 50       109  
4248 72         149 # get here document
4249 72         412 if ($here_script eq '') {
4250             $here_script = CORE::substr $_, pos $_;
4251 72 50       395 $here_script =~ s/.*?\n//oxm;
4252 72         544 }
4253 72         234 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
4254             push @heredoc, $1 . qq{\n$delimiter\n};
4255             push @heredoc_delimiter, $delimiter;
4256 72         147 }
4257             else {
4258 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4259             }
4260             return $here_quote;
4261             }
4262              
4263             # <<\HEREDOC
4264              
4265             # P.66 2.6.6. "Here" Documents
4266             # in Chapter 2: Bits and Pieces
4267             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
4268              
4269             # P.73 "Here" Documents
4270             # in Chapter 2: Bits and Pieces
4271             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
4272 72         270  
4273 0         0 elsif (/\G ( << \\([a-zA-Z_0-9]+) ) /oxgc) {
4274 0         0 $slash = 'm//';
4275             my $here_quote = $1;
4276             my $delimiter = $2;
4277 0 0       0  
4278 0         0 # get here document
4279 0         0 if ($here_script eq '') {
4280             $here_script = CORE::substr $_, pos $_;
4281 0 0       0 $here_script =~ s/.*?\n//oxm;
4282 0         0 }
4283 0         0 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
4284             push @heredoc, $1 . qq{\n$delimiter\n};
4285             push @heredoc_delimiter, $delimiter;
4286 0         0 }
4287             else {
4288 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4289             }
4290             return $here_quote;
4291             }
4292              
4293 0         0 # <<"HEREDOC"
4294 36         90 elsif (/\G ( << "([a-zA-Z_0-9]*)" ) /oxgc) {
4295 36         81 $slash = 'm//';
4296             my $here_quote = $1;
4297             my $delimiter = $2;
4298 36 50       490  
4299 36         108 # get here document
4300 36         240 if ($here_script eq '') {
4301             $here_script = CORE::substr $_, pos $_;
4302 36 50       214 $here_script =~ s/.*?\n//oxm;
4303 36         858 }
4304 36         124 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
4305             push @heredoc, e_heredoc($1) . qq{\n$delimiter\n};
4306             push @heredoc_delimiter, $delimiter;
4307 36         150 }
4308             else {
4309 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4310             }
4311             return $here_quote;
4312             }
4313              
4314 36         155 # <
4315 42         101 elsif (/\G ( << ([a-zA-Z_0-9]+) ) /oxgc) {
4316 42         90 $slash = 'm//';
4317             my $here_quote = $1;
4318             my $delimiter = $2;
4319 42 50       109  
4320 42         107 # get here document
4321 42         299 if ($here_script eq '') {
4322             $here_script = CORE::substr $_, pos $_;
4323 42 50       313 $here_script =~ s/.*?\n//oxm;
4324 42         623 }
4325 42         152 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
4326             push @heredoc, e_heredoc($1) . qq{\n$delimiter\n};
4327             push @heredoc_delimiter, $delimiter;
4328 42         100 }
4329             else {
4330 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4331             }
4332             return $here_quote;
4333             }
4334              
4335 42         180 # <<`HEREDOC`
4336 0         0 elsif (/\G ( << `([a-zA-Z_0-9]*)` ) /oxgc) {
4337 0         0 $slash = 'm//';
4338             my $here_quote = $1;
4339             my $delimiter = $2;
4340 0 0       0  
4341 0         0 # get here document
4342 0         0 if ($here_script eq '') {
4343             $here_script = CORE::substr $_, pos $_;
4344 0 0       0 $here_script =~ s/.*?\n//oxm;
4345 0         0 }
4346 0         0 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
4347             push @heredoc, e_heredoc($1) . qq{\n$delimiter\n};
4348             push @heredoc_delimiter, $delimiter;
4349 0         0 }
4350             else {
4351 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
4352             }
4353             return $here_quote;
4354             }
4355              
4356 0         0 # <<= <=> <= < operator
4357             elsif (/\G ( <<= | <=> | <= | < ) (?= (?>\s*) [A-Za-z_0-9'"`\$\@\&\*\(\+\-] )/oxgc) {
4358             return $1;
4359             }
4360              
4361 12         62 #
4362             elsif (/\G (<[\$]?[A-Za-z_][A-Za-z_0-9]*>) /oxgc) {
4363             return $1;
4364             }
4365              
4366             # --- glob
4367              
4368             # avoid "Error: Runtime exception" of perl version 5.005_03
4369 0         0  
4370             elsif (/\G < ((?:[^>\0\a\e\f\n\r\t])+?) > /oxgc) {
4371             return 'Ewindows1254::glob("' . $1 . '")';
4372             }
4373 0         0  
4374             # __DATA__
4375             elsif (/\G ^ ( __DATA__ \n .*) \z /oxmsgc) { return $1; }
4376 0         0  
4377             # __END__
4378             elsif (/\G ^ ( __END__ \n .*) \z /oxmsgc) { return $1; }
4379              
4380             # \cD Control-D
4381              
4382             # P.68 2.6.8. Other Literal Tokens
4383             # in Chapter 2: Bits and Pieces
4384             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
4385              
4386             # P.76 Other Literal Tokens
4387             # in Chapter 2: Bits and Pieces
4388 204         1581 # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
4389              
4390             elsif (/\G ( \cD .*) \z /oxmsgc) { return $1; }
4391 0         0  
4392             # \cZ Control-Z
4393             elsif (/\G ( \cZ .*) \z /oxmsgc) { return $1; }
4394              
4395             # any operator before div
4396             elsif (/\G (
4397             -- | \+\+ |
4398 0         0 [\)\}\]]
  5083         10639  
4399              
4400             ) /oxgc) { $slash = 'div'; return $1; }
4401              
4402             # yada-yada or triple-dot operator
4403             elsif (/\G (
4404 5083         23334 \.\.\.
  7         18  
4405              
4406             ) /oxgc) { $slash = 'm//'; return q{die('Unimplemented')}; }
4407              
4408             # any operator before m//
4409              
4410             # //, //= (defined-or)
4411              
4412             # P.164 Logical Operators
4413             # in Chapter 10: More Control Structures
4414             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
4415              
4416             # P.119 C-Style Logical (Short-Circuit) Operators
4417             # in Chapter 3: Unary and Binary Operators
4418             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
4419              
4420             # (and so on)
4421              
4422             # ~~
4423              
4424             # P.221 The Smart Match Operator
4425             # in Chapter 15: Smart Matching and given-when
4426             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
4427              
4428             # P.112 Smartmatch Operator
4429             # in Chapter 3: Unary and Binary Operators
4430             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
4431              
4432             # (and so on)
4433              
4434             elsif (/\G ((?>
4435              
4436             !~~ | !~ | != | ! |
4437             %= | % |
4438             &&= | && | &= | &\.= | &\. | & |
4439             -= | -> | - |
4440             :(?>\s*)= |
4441             : |
4442             <<>> |
4443             <<= | <=> | <= | < |
4444             == | => | =~ | = |
4445             >>= | >> | >= | > |
4446             \*\*= | \*\* | \*= | \* |
4447             \+= | \+ |
4448             \.\. | \.= | \. |
4449             \/\/= | \/\/ |
4450             \/= | \/ |
4451             \? |
4452             \\ |
4453             \^= | \^\.= | \^\. | \^ |
4454             \b x= |
4455             \|\|= | \|\| | \|= | \|\.= | \|\. | \| |
4456             ~~ | ~\. | ~ |
4457             \b(?: and | cmp | eq | ge | gt | le | lt | ne | not | or | xor | x )\b |
4458             \b(?: print )\b |
4459              
4460 7         24 [,;\(\{\[]
  8845         17636  
4461              
4462             )) /oxgc) { $slash = 'm//'; return $1; }
4463 8845         39968  
  15785         29925  
4464             # other any character
4465             elsif (/\G ($q_char) /oxgc) { $slash = 'div'; return $1; }
4466              
4467 15785         72084 # system error
4468             else {
4469             die __FILE__, ": Oops, this shouldn't happen!\n";
4470             }
4471             }
4472              
4473 0     1788 0 0 # escape Windows-1254 string
4474 1788         4356 sub e_string {
4475             my($string) = @_;
4476 1788         2721 my $e_string = '';
4477              
4478             local $slash = 'm//';
4479              
4480             # P.1024 Appendix W.10 Multibyte Processing
4481             # of ISBN 1-56592-224-7 CJKV Information Processing
4482 1788         2851 # (and so on)
4483              
4484             my @char = $string =~ / \G (?>[^\\]|\\$q_char|$q_char) /oxmsg;
4485 1788 100 66     13994  
4486 1788 50       7946 # without { ... }
4487 1769         3958 if (not (grep(/\A \{ \z/xms, @char) and grep(/\A \} \z/xms, @char))) {
4488             if ($string !~ /<
4489             return $string;
4490             }
4491             }
4492 1769         4476  
4493 19 50       64 E_STRING_LOOP:
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
4494             while ($string !~ /\G \z/oxgc) {
4495             if (0) {
4496             }
4497 223         4186  
4498 0         0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> @{[Ewindows1254::PREMATCH()]}
4499 0         0 elsif ($string =~ /\G ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH \b | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) /oxmsgc) {
4500             $e_string .= q{Ewindows1254::PREMATCH()};
4501             $slash = 'div';
4502             }
4503              
4504 0         0 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> @{[Ewindows1254::MATCH()]}
4505 0         0 elsif ($string =~ /\G ( \$& | \$\{&\} | \$ (?>\s*) MATCH \b | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) /oxmsgc) {
4506             $e_string .= q{Ewindows1254::MATCH()};
4507             $slash = 'div';
4508             }
4509              
4510 0         0 # $', ${'} --> $', ${'}
4511 0         0 elsif ($string =~ /\G ( \$' | \$\{'\} ) /oxmsgc) {
4512             $e_string .= $1;
4513             $slash = 'div';
4514             }
4515              
4516 0         0 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> @{[Ewindows1254::POSTMATCH()]}
4517 0         0 elsif ($string =~ /\G ( \$ (?>\s*) POSTMATCH \b | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) /oxmsgc) {
4518             $e_string .= q{Ewindows1254::POSTMATCH()};
4519             $slash = 'div';
4520             }
4521              
4522 0         0 # bareword
4523 0         0 elsif ($string =~ /\G ( \{ (?>\s*) (?: tr | index | rindex | reverse ) (?>\s*) \} ) /oxmsgc) {
4524             $e_string .= $1;
4525             $slash = 'div';
4526             }
4527              
4528 0         0 # $0 --> $0
4529 0         0 elsif ($string =~ /\G ( \$ 0 ) /oxmsgc) {
4530             $e_string .= $1;
4531             $slash = 'div';
4532 0         0 }
4533 0         0 elsif ($string =~ /\G ( \$ \{ (?>\s*) 0 (?>\s*) \} ) /oxmsgc) {
4534             $e_string .= $1;
4535             $slash = 'div';
4536             }
4537              
4538 0         0 # $$ --> $$
4539 0         0 elsif ($string =~ /\G ( \$ \$ ) (?![\w\{]) /oxmsgc) {
4540             $e_string .= $1;
4541             $slash = 'div';
4542             }
4543              
4544             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
4545 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
4546 0         0 elsif ($string =~ /\G \$ ((?>[1-9][0-9]*)) /oxmsgc) {
4547             $e_string .= e_capture($1);
4548             $slash = 'div';
4549 0         0 }
4550 0         0 elsif ($string =~ /\G \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} /oxmsgc) {
4551             $e_string .= e_capture($1);
4552             $slash = 'div';
4553             }
4554              
4555 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
4556 0         0 elsif ($string =~ /\G \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ .+? \] ) /oxmsgc) {
4557             $e_string .= e_capture($1.'->'.$2);
4558             $slash = 'div';
4559             }
4560              
4561 0         0 # $$foo{ ... } --> $ $foo->{ ... }
4562 0         0 elsif ($string =~ /\G \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ .+? \} ) /oxmsgc) {
4563             $e_string .= e_capture($1.'->'.$2);
4564             $slash = 'div';
4565             }
4566              
4567 0         0 # $$foo
4568 0         0 elsif ($string =~ /\G \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) /oxmsgc) {
4569             $e_string .= e_capture($1);
4570             $slash = 'div';
4571             }
4572              
4573 0         0 # ${ foo }
4574 0         0 elsif ($string =~ /\G \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} /oxmsgc) {
4575             $e_string .= '${' . $1 . '}';
4576             $slash = 'div';
4577             }
4578              
4579 0         0 # ${ ... }
4580 3         13 elsif ($string =~ /\G \$ (?>\s*) \{ (?>\s*) ( $qq_brace ) (?>\s*) \} /oxmsgc) {
4581             $e_string .= e_capture($1);
4582             $slash = 'div';
4583             }
4584              
4585             # variable or function
4586 3         17 # $ @ % & * $ #
4587 7         20 elsif ($string =~ /\G ( (?: [\$\@\%\&\*] | \$\# | -> | \b sub \b) (?>\s*) (?: split | chop | index | rindex | lc | uc | fc | chr | ord | reverse | getc | tr | y | q | qq | qx | qw | m | s | qr | glob | lstat | opendir | stat | unlink | chdir ) ) \b /oxmsgc) {
4588             $e_string .= $1;
4589             $slash = 'div';
4590             }
4591             # $ $ $ $ $ $ $ $ $ $ $ $ $ $
4592 7         24 # $ @ # \ ' " / ? ( ) [ ] < >
4593 0         0 elsif ($string =~ /\G ( \$[\$\@\#\\\'\"\/\?\(\)\[\]\<\>] ) /oxmsgc) {
4594             $e_string .= $1;
4595             $slash = 'div';
4596             }
4597              
4598 0         0 # qq//
4599 0 0       0 elsif ($string =~ /\G \b (qq) \b /oxgc) {
4600 0         0 my $ope = $1;
4601             if ($string =~ /\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { # qq# #
4602             $e_string .= e_qq($ope,$1,$3,$2);
4603 0         0 }
4604 0         0 else {
4605 0 0       0 my $e = '';
  0 0       0  
    0          
    0          
    0          
    0          
4606 0         0 while ($string !~ /\G \z/oxgc) {
  0         0  
4607 0         0 if ($string =~ /\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
  0         0  
4608 0         0 elsif ($string =~ /\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq ( )
  0         0  
4609 0         0 elsif ($string =~ /\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq { }
  0         0  
4610 0         0 elsif ($string =~ /\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq [ ]
  0         0  
4611             elsif ($string =~ /\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq < >
4612 0         0 elsif ($string =~ /\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq * *
4613             }
4614             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
4615             }
4616             }
4617              
4618 0         0 # qx//
4619 0 0       0 elsif ($string =~ /\G \b (qx) \b /oxgc) {
4620 0         0 my $ope = $1;
4621             if ($string =~ /\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { # qx# #
4622             $e_string .= e_qq($ope,$1,$3,$2);
4623 0         0 }
4624 0         0 else {
4625 0 0       0 my $e = '';
  0 0       0  
    0          
    0          
    0          
    0          
    0          
4626 0         0 while ($string !~ /\G \z/oxgc) {
  0         0  
4627 0         0 if ($string =~ /\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
  0         0  
4628 0         0 elsif ($string =~ /\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx ( )
  0         0  
4629 0         0 elsif ($string =~ /\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx { }
  0         0  
4630 0         0 elsif ($string =~ /\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx [ ]
  0         0  
4631 0         0 elsif ($string =~ /\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx < >
  0         0  
4632             elsif ($string =~ /\G (\') ((?:$qq_char)*?) (\') /oxgc) { $e_string .= $e . e_q ($ope,$1,$3,$2); next E_STRING_LOOP; } # qx ' '
4633 0         0 elsif ($string =~ /\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx * *
4634             }
4635             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
4636             }
4637             }
4638              
4639 0         0 # q//
4640 0 0       0 elsif ($string =~ /\G \b (q) \b /oxgc) {
4641 0         0 my $ope = $1;
4642             if ($string =~ /\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { # q# #
4643             $e_string .= e_q($ope,$1,$3,$2);
4644 0         0 }
4645 0         0 else {
4646 0 0       0 my $e = '';
  0 0       0  
    0          
    0          
    0          
    0          
4647 0         0 while ($string !~ /\G \z/oxgc) {
  0         0  
4648 0         0 if ($string =~ /\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
  0         0  
4649 0         0 elsif ($string =~ /\G (\() ((?:\\\\|\\\)|\\\(|$q_paren)*?) (\)) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q ( )
  0         0  
4650 0         0 elsif ($string =~ /\G (\{) ((?:\\\\|\\\}|\\\{|$q_brace)*?) (\}) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q { }
  0         0  
4651 0         0 elsif ($string =~ /\G (\[) ((?:\\\\|\\\]|\\\[|$q_bracket)*?) (\]) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q [ ]
  0         0  
4652             elsif ($string =~ /\G (\<) ((?:\\\\|\\\>|\\\<|$q_angle)*?) (\>) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q < >
4653 0         0 elsif ($string =~ /\G (\S) ((?:\\\\|\\\1| $q_char)*?) (\1) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q * *
4654             }
4655             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
4656             }
4657             }
4658 0         0  
4659             # ''
4660             elsif ($string =~ /\G (?
4661 0         0  
4662             # ""
4663             elsif ($string =~ /\G (\") ((?:$qq_char)*?) (\") /oxgc) { $e_string .= e_qq('',$1,$3,$2); }
4664 0         0  
4665             # ``
4666             elsif ($string =~ /\G (\`) ((?:$qq_char)*?) (\`) /oxgc) { $e_string .= e_qq('',$1,$3,$2); }
4667 0         0  
4668             # other any character
4669             elsif ($string =~ /\G ($q_char) /oxgc) { $e_string .= $1; }
4670              
4671 213         544 # system error
4672             else {
4673             die __FILE__, ": Oops, this shouldn't happen!\n";
4674             }
4675 0         0 }
4676              
4677             return $e_string;
4678             }
4679              
4680             #
4681             # character class
4682 19     1919 0 79 #
4683             sub character_class {
4684 1919 100       3536 my($char,$modifier) = @_;
4685 1919 100       3148  
4686 52         109 if ($char eq '.') {
4687             if ($modifier =~ /s/) {
4688             return '${Ewindows1254::dot_s}';
4689 17         39 }
4690             else {
4691             return '${Ewindows1254::dot}';
4692             }
4693 35         83 }
4694             else {
4695             return Ewindows1254::classic_character_class($char);
4696             }
4697             }
4698              
4699             #
4700             # escape capture ($1, $2, $3, ...)
4701             #
4702 1867     212 0 3462 sub e_capture {
4703              
4704             return join '', '${', $_[0], '}';
4705             }
4706              
4707             #
4708             # escape transliteration (tr/// or y///)
4709 212     3 0 791 #
4710 3         18 sub e_tr {
4711 3   50     7 my($variable,$charclass,$e,$charclass2,$modifier) = @_;
4712             my $e_tr = '';
4713 3         7 $modifier ||= '';
4714              
4715             $slash = 'div';
4716 3         4  
4717             # quote character class 1
4718             $charclass = q_tr($charclass);
4719 3         9  
4720             # quote character class 2
4721             $charclass2 = q_tr($charclass2);
4722 3 50       6  
4723 3 0       10 # /b /B modifier
4724 0         0 if ($modifier =~ tr/bB//d) {
4725             if ($variable eq '') {
4726             $e_tr = qq{tr$charclass$e$charclass2$modifier};
4727 0         0 }
4728             else {
4729             $e_tr = qq{$variable${bind_operator}tr$charclass$e$charclass2$modifier};
4730             }
4731 0 100       0 }
4732 3         7 else {
4733             if ($variable eq '') {
4734             $e_tr = qq{Ewindows1254::tr(\$_,' =~ ',$charclass,$e$charclass2,'$modifier')};
4735 2         6 }
4736             else {
4737             $e_tr = qq{Ewindows1254::tr($variable,'$bind_operator',$charclass,$e$charclass2,'$modifier')};
4738             }
4739             }
4740 1         5  
4741 3         5 # clear tr/// variable
4742             $tr_variable = '';
4743 3         4 $bind_operator = '';
4744              
4745             return $e_tr;
4746             }
4747              
4748             #
4749             # quote for escape transliteration (tr/// or y///)
4750 3     6 0 17 #
4751             sub q_tr {
4752             my($charclass) = @_;
4753 6 50       9  
    0          
    0          
    0          
    0          
    0          
4754 6         12 # quote character class
4755             if ($charclass !~ /'/oxms) {
4756             return e_q('', "'", "'", $charclass); # --> q' '
4757 6         11 }
4758             elsif ($charclass !~ /\//oxms) {
4759             return e_q('q', '/', '/', $charclass); # --> q/ /
4760 0         0 }
4761             elsif ($charclass !~ /\#/oxms) {
4762             return e_q('q', '#', '#', $charclass); # --> q# #
4763 0         0 }
4764             elsif ($charclass !~ /[\<\>]/oxms) {
4765             return e_q('q', '<', '>', $charclass); # --> q< >
4766 0         0 }
4767             elsif ($charclass !~ /[\(\)]/oxms) {
4768             return e_q('q', '(', ')', $charclass); # --> q( )
4769 0         0 }
4770             elsif ($charclass !~ /[\{\}]/oxms) {
4771             return e_q('q', '{', '}', $charclass); # --> q{ }
4772 0         0 }
4773 0 0       0 else {
4774 0         0 for my $char (qw( ! " $ % & * + . : = ? @ ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
4775             if ($charclass !~ /\Q$char\E/xms) {
4776             return e_q('q', $char, $char, $charclass);
4777             }
4778             }
4779 0         0 }
4780              
4781             return e_q('q', '{', '}', $charclass);
4782             }
4783              
4784             #
4785             # escape q string (q//, '')
4786 0     1264 0 0 #
4787             sub e_q {
4788 1264         3138 my($ope,$delimiter,$end_delimiter,$string) = @_;
4789              
4790 1264         1842 $slash = 'div';
4791              
4792             return join '', $ope, $delimiter, $string, $end_delimiter;
4793             }
4794              
4795             #
4796             # escape qq string (qq//, "", qx//, ``)
4797 1264     4044 0 6462 #
4798             sub e_qq {
4799 4044         9473 my($ope,$delimiter,$end_delimiter,$string) = @_;
4800              
4801 4044         5536 $slash = 'div';
4802 4044         4993  
4803             my $left_e = 0;
4804             my $right_e = 0;
4805 4044         4697  
4806             # split regexp
4807             my @char = $string =~ /\G((?>
4808             [^\\\$] |
4809             \\x\{ (?>[0-9A-Fa-f]+) \} |
4810             \\o\{ (?>[0-7]+) \} |
4811             \\N\{ (?>[^0-9\}][^\}]*) \} |
4812             \\ $q_char |
4813             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
4814             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
4815             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
4816             \$ (?>\s* [0-9]+) |
4817             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
4818             \$ \$ (?![\w\{]) |
4819             \$ (?>\s*) \$ (?>\s*) $qq_variable |
4820             $q_char
4821 4044         138539 ))/oxmsg;
4822              
4823             for (my $i=0; $i <= $#char; $i++) {
4824 4044 50 33     12770  
    50 33        
    100          
    100          
    50          
4825 114817         370135 # "\L\u" --> "\u\L"
4826             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
4827             @char[$i,$i+1] = @char[$i+1,$i];
4828             }
4829              
4830 0         0 # "\U\l" --> "\l\U"
4831             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
4832             @char[$i,$i+1] = @char[$i+1,$i];
4833             }
4834              
4835 0         0 # octal escape sequence
4836             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
4837             $char[$i] = Ewindows1254::octchr($1);
4838             }
4839              
4840 1         4 # hexadecimal escape sequence
4841             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
4842             $char[$i] = Ewindows1254::hexchr($1);
4843             }
4844              
4845 1         4 # \N{CHARNAME} --> N{CHARNAME}
4846             elsif ($char[$i] =~ /\A \\ ( N\{ ([^0-9\}][^\}]*) \} ) \z/oxms) {
4847             $char[$i] = $1;
4848 0 100       0 }
    50          
    50          
    50          
    50          
    100          
    50          
    100          
    50          
    50          
    100          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
4849              
4850             if (0) {
4851             }
4852              
4853             # \F
4854             #
4855             # P.69 Table 2-6. Translation escapes
4856             # in Chapter 2: Bits and Pieces
4857             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
4858             # (and so on)
4859 114817         913074  
4860 0 50       0 # \u \l \U \L \F \Q \E
4861 484         1064 elsif ($char[$i] =~ /\A ([<>]) \z/oxms) {
4862             if ($right_e < $left_e) {
4863             $char[$i] = '\\' . $char[$i];
4864             }
4865             }
4866             elsif ($char[$i] eq '\u') {
4867              
4868             # "STRING @{[ LIST EXPR ]} MORE STRING"
4869              
4870             # P.257 Other Tricks You Can Do with Hard References
4871             # in Chapter 8: References
4872             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
4873              
4874             # P.353 Other Tricks You Can Do with Hard References
4875             # in Chapter 8: References
4876             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
4877              
4878 0         0 # (and so on)
4879 0         0  
4880             $char[$i] = '@{[Ewindows1254::ucfirst qq<';
4881             $left_e++;
4882 0         0 }
4883 0         0 elsif ($char[$i] eq '\l') {
4884             $char[$i] = '@{[Ewindows1254::lcfirst qq<';
4885             $left_e++;
4886 0         0 }
4887 0         0 elsif ($char[$i] eq '\U') {
4888             $char[$i] = '@{[Ewindows1254::uc qq<';
4889             $left_e++;
4890 0         0 }
4891 0         0 elsif ($char[$i] eq '\L') {
4892             $char[$i] = '@{[Ewindows1254::lc qq<';
4893             $left_e++;
4894 0         0 }
4895 24         33 elsif ($char[$i] eq '\F') {
4896             $char[$i] = '@{[Ewindows1254::fc qq<';
4897             $left_e++;
4898 24         43 }
4899 0         0 elsif ($char[$i] eq '\Q') {
4900             $char[$i] = '@{[CORE::quotemeta qq<';
4901             $left_e++;
4902 0 50       0 }
4903 24         65 elsif ($char[$i] eq '\E') {
4904 24         31 if ($right_e < $left_e) {
4905             $char[$i] = '>]}';
4906             $right_e++;
4907 24         43 }
4908             else {
4909             $char[$i] = '';
4910             }
4911 0         0 }
4912 0 0       0 elsif ($char[$i] eq '\Q') {
4913 0         0 while (1) {
4914             if (++$i > $#char) {
4915 0 0       0 last;
4916 0         0 }
4917             if ($char[$i] eq '\E') {
4918             last;
4919             }
4920             }
4921             }
4922             elsif ($char[$i] eq '\E') {
4923             }
4924              
4925             # $0 --> $0
4926             elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
4927             }
4928             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
4929             }
4930              
4931             # $$ --> $$
4932             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
4933             }
4934              
4935             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
4936 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
4937             elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
4938             $char[$i] = e_capture($1);
4939 205         399 }
4940             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
4941             $char[$i] = e_capture($1);
4942             }
4943              
4944 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
4945             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
4946             $char[$i] = e_capture($1.'->'.$2);
4947             }
4948              
4949 0         0 # $$foo{ ... } --> $ $foo->{ ... }
4950             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
4951             $char[$i] = e_capture($1.'->'.$2);
4952             }
4953              
4954 0         0 # $$foo
4955             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
4956             $char[$i] = e_capture($1);
4957             }
4958              
4959 0         0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ewindows1254::PREMATCH()
4960             elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
4961             $char[$i] = '@{[Ewindows1254::PREMATCH()]}';
4962             }
4963              
4964 44         134 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ewindows1254::MATCH()
4965             elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
4966             $char[$i] = '@{[Ewindows1254::MATCH()]}';
4967             }
4968              
4969 45         134 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ewindows1254::POSTMATCH()
4970             elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
4971             $char[$i] = '@{[Ewindows1254::POSTMATCH()]}';
4972             }
4973              
4974             # ${ foo } --> ${ foo }
4975             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ (?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* ) \} \z/oxms) {
4976             }
4977              
4978 33         87 # ${ ... }
4979             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
4980             $char[$i] = e_capture($1);
4981             }
4982             }
4983 0 50       0  
4984 4044         8049 # return string
4985             if ($left_e > $right_e) {
4986 0         0 return join '', $ope, $delimiter, @char, '>]}' x ($left_e - $right_e), $end_delimiter;
4987             }
4988             return join '', $ope, $delimiter, @char, $end_delimiter;
4989             }
4990              
4991             #
4992             # escape qw string (qw//)
4993 4044     16 0 32805 #
4994             sub e_qw {
4995 16         160 my($ope,$delimiter,$end_delimiter,$string) = @_;
4996              
4997             $slash = 'div';
4998 16         58  
  16         224  
4999 483 50       794 # choice again delimiter
    0          
    0          
    0          
    0          
5000 16         101 my %octet = map {$_ => 1} ($string =~ /\G ([\x00-\xFF]) /oxmsg);
5001             if (not $octet{$end_delimiter}) {
5002             return join '', $ope, $delimiter, $string, $end_delimiter;
5003 16         142 }
5004             elsif (not $octet{')'}) {
5005             return join '', $ope, '(', $string, ')';
5006 0         0 }
5007             elsif (not $octet{'}'}) {
5008             return join '', $ope, '{', $string, '}';
5009 0         0 }
5010             elsif (not $octet{']'}) {
5011             return join '', $ope, '[', $string, ']';
5012 0         0 }
5013             elsif (not $octet{'>'}) {
5014             return join '', $ope, '<', $string, '>';
5015 0         0 }
5016 0 0       0 else {
5017 0         0 for my $char (qw( ! " $ % & * + - . / : = ? @ ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
5018             if (not $octet{$char}) {
5019             return join '', $ope, $char, $string, $char;
5020             }
5021             }
5022             }
5023 0         0  
5024 0         0 # qw/AAA BBB C'CC/ --> ('AAA', 'BBB', 'C\'CC')
5025 0         0 my @string = CORE::split(/\s+/, $string);
5026 0         0 for my $string (@string) {
5027 0 0       0 my @octet = $string =~ /\G ([\x00-\xFF]) /oxmsg;
5028 0         0 for my $octet (@octet) {
5029             if ($octet =~ /\A (['\\]) \z/oxms) {
5030             $octet = '\\' . $1;
5031 0         0 }
5032             }
5033 0         0 $string = join '', @octet;
  0         0  
5034             }
5035             return join '', '(', (join ', ', map { "'$_'" } @string), ')';
5036             }
5037              
5038             #
5039             # escape here document (<<"HEREDOC", <
5040 0     93 0 0 #
5041             sub e_heredoc {
5042 93         255 my($string) = @_;
5043              
5044 93         157 $slash = 'm//';
5045              
5046 93         298 my $metachar = qr/[\@\\|]/oxms; # '|' is for <<`HEREDOC`
5047 93         149  
5048             my $left_e = 0;
5049             my $right_e = 0;
5050 93         138  
5051             # split regexp
5052             my @char = $string =~ /\G((?>
5053             [^\\\$] |
5054             \\x\{ (?>[0-9A-Fa-f]+) \} |
5055             \\o\{ (?>[0-7]+) \} |
5056             \\N\{ (?>[^0-9\}][^\}]*) \} |
5057             \\ $q_char |
5058             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
5059             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
5060             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
5061             \$ (?>\s* [0-9]+) |
5062             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
5063             \$ \$ (?![\w\{]) |
5064             \$ (?>\s*) \$ (?>\s*) $qq_variable |
5065             $q_char
5066 93         8296 ))/oxmsg;
5067              
5068             for (my $i=0; $i <= $#char; $i++) {
5069 93 50 33     406  
    50 33        
    100          
    100          
    50          
5070 3307         9714 # "\L\u" --> "\u\L"
5071             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
5072             @char[$i,$i+1] = @char[$i+1,$i];
5073             }
5074              
5075 0         0 # "\U\l" --> "\l\U"
5076             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
5077             @char[$i,$i+1] = @char[$i+1,$i];
5078             }
5079              
5080 0         0 # octal escape sequence
5081             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
5082             $char[$i] = Ewindows1254::octchr($1);
5083             }
5084              
5085 1         3 # hexadecimal escape sequence
5086             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
5087             $char[$i] = Ewindows1254::hexchr($1);
5088             }
5089              
5090 1         4 # \N{CHARNAME} --> N{CHARNAME}
5091             elsif ($char[$i] =~ /\A \\ ( N\{ ([^0-9\}][^\}]*) \} ) \z/oxms) {
5092             $char[$i] = $1;
5093 0 50       0 }
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
5094              
5095             if (0) {
5096             }
5097 3307         27134  
5098 0 0       0 # \u \l \U \L \F \Q \E
5099 0         0 elsif ($char[$i] =~ /\A ([<>]) \z/oxms) {
5100             if ($right_e < $left_e) {
5101             $char[$i] = '\\' . $char[$i];
5102             }
5103 0         0 }
5104 0         0 elsif ($char[$i] eq '\u') {
5105             $char[$i] = '@{[Ewindows1254::ucfirst qq<';
5106             $left_e++;
5107 0         0 }
5108 0         0 elsif ($char[$i] eq '\l') {
5109             $char[$i] = '@{[Ewindows1254::lcfirst qq<';
5110             $left_e++;
5111 0         0 }
5112 0         0 elsif ($char[$i] eq '\U') {
5113             $char[$i] = '@{[Ewindows1254::uc qq<';
5114             $left_e++;
5115 0         0 }
5116 0         0 elsif ($char[$i] eq '\L') {
5117             $char[$i] = '@{[Ewindows1254::lc qq<';
5118             $left_e++;
5119 0         0 }
5120 0         0 elsif ($char[$i] eq '\F') {
5121             $char[$i] = '@{[Ewindows1254::fc qq<';
5122             $left_e++;
5123 0         0 }
5124 0         0 elsif ($char[$i] eq '\Q') {
5125             $char[$i] = '@{[CORE::quotemeta qq<';
5126             $left_e++;
5127 0 0       0 }
5128 0         0 elsif ($char[$i] eq '\E') {
5129 0         0 if ($right_e < $left_e) {
5130             $char[$i] = '>]}';
5131             $right_e++;
5132 0         0 }
5133             else {
5134             $char[$i] = '';
5135             }
5136 0         0 }
5137 0 0       0 elsif ($char[$i] eq '\Q') {
5138 0         0 while (1) {
5139             if (++$i > $#char) {
5140 0 0       0 last;
5141 0         0 }
5142             if ($char[$i] eq '\E') {
5143             last;
5144             }
5145             }
5146             }
5147             elsif ($char[$i] eq '\E') {
5148             }
5149              
5150             # $0 --> $0
5151             elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
5152             }
5153             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
5154             }
5155              
5156             # $$ --> $$
5157             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
5158             }
5159              
5160             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
5161 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
5162             elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
5163             $char[$i] = e_capture($1);
5164 0         0 }
5165             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
5166             $char[$i] = e_capture($1);
5167             }
5168              
5169 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
5170             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
5171             $char[$i] = e_capture($1.'->'.$2);
5172             }
5173              
5174 0         0 # $$foo{ ... } --> $ $foo->{ ... }
5175             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
5176             $char[$i] = e_capture($1.'->'.$2);
5177             }
5178              
5179 0         0 # $$foo
5180             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
5181             $char[$i] = e_capture($1);
5182             }
5183              
5184 0         0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ewindows1254::PREMATCH()
5185             elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
5186             $char[$i] = '@{[Ewindows1254::PREMATCH()]}';
5187             }
5188              
5189 8         53 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ewindows1254::MATCH()
5190             elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
5191             $char[$i] = '@{[Ewindows1254::MATCH()]}';
5192             }
5193              
5194 8         43 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ewindows1254::POSTMATCH()
5195             elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
5196             $char[$i] = '@{[Ewindows1254::POSTMATCH()]}';
5197             }
5198              
5199             # ${ foo } --> ${ foo }
5200             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ (?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* ) \} \z/oxms) {
5201             }
5202              
5203 6         37 # ${ ... }
5204             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
5205             $char[$i] = e_capture($1);
5206             }
5207             }
5208 0 50       0  
5209 93         223 # return string
5210             if ($left_e > $right_e) {
5211 0         0 return join '', @char, '>]}' x ($left_e - $right_e);
5212             }
5213             return join '', @char;
5214             }
5215              
5216             #
5217             # escape regexp (m//, qr//)
5218 93     652 0 729 #
5219 652   100     2865 sub e_qr {
5220             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
5221 652         2757 $modifier ||= '';
5222 652 50       1280  
5223 652         1655 $modifier =~ tr/p//d;
5224 0         0 if ($modifier =~ /([adlu])/oxms) {
5225 0 0       0 my $line = 0;
5226 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
5227 0         0 if ($filename ne __FILE__) {
5228             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
5229             last;
5230 0         0 }
5231             }
5232             die qq{Unsupported modifier "$1" used at line $line.\n};
5233 0         0 }
5234              
5235             $slash = 'div';
5236 652 100       1154  
    100          
5237 652         2009 # literal null string pattern
5238 8         14 if ($string eq '') {
5239 8         10 $modifier =~ tr/bB//d;
5240             $modifier =~ tr/i//d;
5241             return join '', $ope, $delimiter, $end_delimiter, $modifier;
5242             }
5243              
5244             # /b /B modifier
5245             elsif ($modifier =~ tr/bB//d) {
5246 8 50       46  
5247 2         7 # choice again delimiter
5248 0         0 if ($delimiter =~ / [\@:] /oxms) {
  0         0  
5249 0 0       0 my @char = $string =~ /\G ([\x00-\xFF]) /oxmsg;
    0          
    0          
    0          
5250 0         0 my %octet = map {$_ => 1} @char;
5251 0         0 if (not $octet{')'}) {
5252             $delimiter = '(';
5253             $end_delimiter = ')';
5254 0         0 }
5255 0         0 elsif (not $octet{'}'}) {
5256             $delimiter = '{';
5257             $end_delimiter = '}';
5258 0         0 }
5259 0         0 elsif (not $octet{']'}) {
5260             $delimiter = '[';
5261             $end_delimiter = ']';
5262 0         0 }
5263 0         0 elsif (not $octet{'>'}) {
5264             $delimiter = '<';
5265             $end_delimiter = '>';
5266 0         0 }
5267 0 0       0 else {
5268 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
5269 0         0 if (not $octet{$char}) {
5270 0         0 $delimiter = $char;
5271             $end_delimiter = $char;
5272             last;
5273             }
5274             }
5275             }
5276 0 50 33     0 }
5277 2         14  
5278             if (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
5279             return join '', $ope, $delimiter, $string, $matched, $end_delimiter, $modifier;
5280 0         0 }
5281             else {
5282             return join '', $ope, $delimiter, '(?:', $string, ')', $matched, $end_delimiter, $modifier;
5283             }
5284 2 100       15 }
5285 642         1507  
5286             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
5287             my $metachar = qr/[\@\\|[\]{^]/oxms;
5288 642         2409  
5289             # split regexp
5290             my @char = $string =~ /\G((?>
5291             [^\\\$\@\[\(] |
5292             \\x (?>[0-9A-Fa-f]{1,2}) |
5293             \\ (?>[0-7]{2,3}) |
5294             \\c [\x40-\x5F] |
5295             \\x\{ (?>[0-9A-Fa-f]+) \} |
5296             \\o\{ (?>[0-7]+) \} |
5297             \\[bBNpP]\{ (?>[^0-9\}][^\}]*) \} |
5298             \\ $q_char |
5299             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
5300             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
5301             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
5302             [\$\@] $qq_variable |
5303             \$ (?>\s* [0-9]+) |
5304             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
5305             \$ \$ (?![\w\{]) |
5306             \$ (?>\s*) \$ (?>\s*) $qq_variable |
5307             \[\^ |
5308             \[\: (?>[a-z]+) :\] |
5309             \[\:\^ (?>[a-z]+) :\] |
5310             \(\? |
5311             $q_char
5312             ))/oxmsg;
5313 642 50       67309  
5314 642         2934 # choice again delimiter
  0         0  
5315 0 0       0 if ($delimiter =~ / [\@:] /oxms) {
    0          
    0          
    0          
5316 0         0 my %octet = map {$_ => 1} @char;
5317 0         0 if (not $octet{')'}) {
5318             $delimiter = '(';
5319             $end_delimiter = ')';
5320 0         0 }
5321 0         0 elsif (not $octet{'}'}) {
5322             $delimiter = '{';
5323             $end_delimiter = '}';
5324 0         0 }
5325 0         0 elsif (not $octet{']'}) {
5326             $delimiter = '[';
5327             $end_delimiter = ']';
5328 0         0 }
5329 0         0 elsif (not $octet{'>'}) {
5330             $delimiter = '<';
5331             $end_delimiter = '>';
5332 0         0 }
5333 0 0       0 else {
5334 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
5335 0         0 if (not $octet{$char}) {
5336 0         0 $delimiter = $char;
5337             $end_delimiter = $char;
5338             last;
5339             }
5340             }
5341             }
5342 0         0 }
5343 642         1072  
5344 642         914 my $left_e = 0;
5345             my $right_e = 0;
5346             for (my $i=0; $i <= $#char; $i++) {
5347 642 50 66     2064  
    50 66        
    100          
    100          
    100          
    100          
5348 1872         9902 # "\L\u" --> "\u\L"
5349             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
5350             @char[$i,$i+1] = @char[$i+1,$i];
5351             }
5352              
5353 0         0 # "\U\l" --> "\l\U"
5354             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
5355             @char[$i,$i+1] = @char[$i+1,$i];
5356             }
5357              
5358 0         0 # octal escape sequence
5359             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
5360             $char[$i] = Ewindows1254::octchr($1);
5361             }
5362              
5363 1         4 # hexadecimal escape sequence
5364             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
5365             $char[$i] = Ewindows1254::hexchr($1);
5366             }
5367              
5368             # \b{...} --> b\{...}
5369             # \B{...} --> B\{...}
5370             # \N{CHARNAME} --> N\{CHARNAME}
5371             # \p{PROPERTY} --> p\{PROPERTY}
5372 1         5 # \P{PROPERTY} --> P\{PROPERTY}
5373             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^0-9\}][^\}]*) \} ) \z/oxms) {
5374             $char[$i] = $1 . '\\' . $2;
5375             }
5376              
5377 6         17 # \p, \P, \X --> p, P, X
5378             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
5379             $char[$i] = $1;
5380 4 100 100     11 }
    100 100        
    100 100        
    100          
    100          
    100          
    50          
    50          
    100          
    100          
    100          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
    100          
    100          
5381              
5382             if (0) {
5383             }
5384 1872         5545  
5385 0 50 33     0 # join separated multiple-octet
    50 33        
    50 33        
      33        
      66        
      33        
5386 6         96 elsif ($char[$i] =~ /\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms) {
5387             if ( ($i+3 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+3]) == 3) and (CORE::eval(sprintf '"%s%s%s%s"', @char[$i..$i+3]) =~ /\A $q_char \z/oxms)) {
5388             $char[$i] .= join '', splice @char, $i+1, 3;
5389 0         0 }
5390             elsif (($i+2 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+2]) == 2) and (CORE::eval(sprintf '"%s%s%s"', @char[$i..$i+2]) =~ /\A $q_char \z/oxms)) {
5391             $char[$i] .= join '', splice @char, $i+1, 2;
5392 0         0 }
5393             elsif (($i+1 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, $char[$i+1 ]) == 1) and (CORE::eval(sprintf '"%s%s"', @char[$i..$i+1]) =~ /\A $q_char \z/oxms)) {
5394             $char[$i] .= join '', splice @char, $i+1, 1;
5395             }
5396             }
5397              
5398 0         0 # open character class [...]
5399             elsif ($char[$i] eq '[') {
5400             my $left = $i;
5401              
5402             # [] make die "Unmatched [] in regexp ...\n"
5403 328 100       456 # (and so on)
5404 328         763  
5405             if ($char[$i+1] eq ']') {
5406             $i++;
5407 3         6 }
5408 328 50       480  
5409 1379         2177 while (1) {
5410             if (++$i > $#char) {
5411 0 100       0 die __FILE__, ": Unmatched [] in regexp\n";
5412 1379         2417 }
5413             if ($char[$i] eq ']') {
5414             my $right = $i;
5415 328 100       434  
5416 328         1949 # [...]
  30         83  
5417             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
5418             splice @char, $left, $right-$left+1, sprintf(q{@{[Ewindows1254::charlist_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
5419 90         174 }
5420             else {
5421             splice @char, $left, $right-$left+1, Ewindows1254::charlist_qr(@char[$left+1..$right-1], $modifier);
5422 298         1157 }
5423 328         599  
5424             $i = $left;
5425             last;
5426             }
5427             }
5428             }
5429              
5430 328         888 # open character class [^...]
5431             elsif ($char[$i] eq '[^') {
5432             my $left = $i;
5433              
5434             # [^] make die "Unmatched [] in regexp ...\n"
5435 74 100       153 # (and so on)
5436 74         182  
5437             if ($char[$i+1] eq ']') {
5438             $i++;
5439 4         8 }
5440 74 50       99  
5441 272         449 while (1) {
5442             if (++$i > $#char) {
5443 0 100       0 die __FILE__, ": Unmatched [] in regexp\n";
5444 272         567 }
5445             if ($char[$i] eq ']') {
5446             my $right = $i;
5447 74 100       103  
5448 74         415 # [^...]
  30         76  
5449             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
5450             splice @char, $left, $right-$left+1, sprintf(q{@{[Ewindows1254::charlist_not_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
5451 90         162 }
5452             else {
5453             splice @char, $left, $right-$left+1, Ewindows1254::charlist_not_qr(@char[$left+1..$right-1], $modifier);
5454 44         188 }
5455 74         156  
5456             $i = $left;
5457             last;
5458             }
5459             }
5460             }
5461              
5462 74         209 # rewrite character class or escape character
5463             elsif (my $char = character_class($char[$i],$modifier)) {
5464             $char[$i] = $char;
5465             }
5466              
5467 139 50       359 # /i modifier
5468 20         36 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ewindows1254::uc($char[$i]) ne Ewindows1254::fc($char[$i]))) {
5469             if (CORE::length(Ewindows1254::fc($char[$i])) == 1) {
5470             $char[$i] = '[' . Ewindows1254::uc($char[$i]) . Ewindows1254::fc($char[$i]) . ']';
5471 20         39 }
5472             else {
5473             $char[$i] = '(?:' . Ewindows1254::uc($char[$i]) . '|' . Ewindows1254::fc($char[$i]) . ')';
5474             }
5475             }
5476              
5477 0 50       0 # \u \l \U \L \F \Q \E
5478 1         5 elsif ($char[$i] =~ /\A [<>] \z/oxms) {
5479             if ($right_e < $left_e) {
5480             $char[$i] = '\\' . $char[$i];
5481             }
5482 0         0 }
5483 0         0 elsif ($char[$i] eq '\u') {
5484             $char[$i] = '@{[Ewindows1254::ucfirst qq<';
5485             $left_e++;
5486 0         0 }
5487 0         0 elsif ($char[$i] eq '\l') {
5488             $char[$i] = '@{[Ewindows1254::lcfirst qq<';
5489             $left_e++;
5490 0         0 }
5491 1         2 elsif ($char[$i] eq '\U') {
5492             $char[$i] = '@{[Ewindows1254::uc qq<';
5493             $left_e++;
5494 1         13 }
5495 1         3 elsif ($char[$i] eq '\L') {
5496             $char[$i] = '@{[Ewindows1254::lc qq<';
5497             $left_e++;
5498 1         4 }
5499 18         31 elsif ($char[$i] eq '\F') {
5500             $char[$i] = '@{[Ewindows1254::fc qq<';
5501             $left_e++;
5502 18         38 }
5503 1         2 elsif ($char[$i] eq '\Q') {
5504             $char[$i] = '@{[CORE::quotemeta qq<';
5505             $left_e++;
5506 1 50       3 }
5507 21         41 elsif ($char[$i] eq '\E') {
5508 21         27 if ($right_e < $left_e) {
5509             $char[$i] = '>]}';
5510             $right_e++;
5511 21         47 }
5512             else {
5513             $char[$i] = '';
5514             }
5515 0         0 }
5516 0 0       0 elsif ($char[$i] eq '\Q') {
5517 0         0 while (1) {
5518             if (++$i > $#char) {
5519 0 0       0 last;
5520 0         0 }
5521             if ($char[$i] eq '\E') {
5522             last;
5523             }
5524             }
5525             }
5526             elsif ($char[$i] eq '\E') {
5527             }
5528              
5529 0 0       0 # $0 --> $0
5530 0         0 elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
5531             if ($ignorecase) {
5532             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5533             }
5534 0 0       0 }
5535 0         0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
5536             if ($ignorecase) {
5537             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5538             }
5539             }
5540              
5541             # $$ --> $$
5542             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
5543             }
5544              
5545             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
5546 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
5547 0 0       0 elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
5548 0         0 $char[$i] = e_capture($1);
5549             if ($ignorecase) {
5550             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5551             }
5552 0         0 }
5553 0 0       0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
5554 0         0 $char[$i] = e_capture($1);
5555             if ($ignorecase) {
5556             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5557             }
5558             }
5559              
5560 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
5561 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
5562 0         0 $char[$i] = e_capture($1.'->'.$2);
5563             if ($ignorecase) {
5564             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5565             }
5566             }
5567              
5568 0         0 # $$foo{ ... } --> $ $foo->{ ... }
5569 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
5570 0         0 $char[$i] = e_capture($1.'->'.$2);
5571             if ($ignorecase) {
5572             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5573             }
5574             }
5575              
5576 0         0 # $$foo
5577 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
5578 0         0 $char[$i] = e_capture($1);
5579             if ($ignorecase) {
5580             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5581             }
5582             }
5583              
5584 0 50       0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ewindows1254::PREMATCH()
5585 8         25 elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
5586             if ($ignorecase) {
5587             $char[$i] = '@{[Ewindows1254::ignorecase(Ewindows1254::PREMATCH())]}';
5588 0         0 }
5589             else {
5590             $char[$i] = '@{[Ewindows1254::PREMATCH()]}';
5591             }
5592             }
5593              
5594 8 50       28 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ewindows1254::MATCH()
5595 8         19 elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
5596             if ($ignorecase) {
5597             $char[$i] = '@{[Ewindows1254::ignorecase(Ewindows1254::MATCH())]}';
5598 0         0 }
5599             else {
5600             $char[$i] = '@{[Ewindows1254::MATCH()]}';
5601             }
5602             }
5603              
5604 8 50       24 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ewindows1254::POSTMATCH()
5605 6         17 elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
5606             if ($ignorecase) {
5607             $char[$i] = '@{[Ewindows1254::ignorecase(Ewindows1254::POSTMATCH())]}';
5608 0         0 }
5609             else {
5610             $char[$i] = '@{[Ewindows1254::POSTMATCH()]}';
5611             }
5612             }
5613              
5614 6 0       16 # ${ foo }
5615 0         0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} \z/oxms) {
5616             if ($ignorecase) {
5617             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5618             }
5619             }
5620              
5621 0         0 # ${ ... }
5622 0 0       0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
5623 0         0 $char[$i] = e_capture($1);
5624             if ($ignorecase) {
5625             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5626             }
5627             }
5628              
5629 0         0 # $scalar or @array
5630 21 100       52 elsif ($char[$i] =~ /\A [\$\@].+ /oxms) {
5631 21         65 $char[$i] = e_string($char[$i]);
5632             if ($ignorecase) {
5633             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
5634             }
5635             }
5636              
5637 11 100 33     36 # quote character before ? + * {
    50          
5638             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
5639             if ($char[$i-1] =~ /\A (?:[\x00-\xFF]|\\[0-7]{2,3}|\\x[0-9-A-Fa-f]{1,2}) \z/oxms) {
5640 138         1027 }
5641 0 0       0 elsif (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
5642 0         0 my $char = $char[$i-1];
5643             if ($char[$i] eq '{') {
5644             die __FILE__, qq{: "MULTIBYTE{n}" should be "(MULTIBYTE){n}" in m?? (and shift \$1,\$2,\$3,...) ($char){n}\n};
5645 0         0 }
5646             else {
5647             die __FILE__, qq{: "MULTIBYTE$char[$i]" should be "(MULTIBYTE)$char[$i]" in m?? (and shift \$1,\$2,\$3,...) ($char)$char[$i]\n};
5648             }
5649 0         0 }
5650             else {
5651             $char[$i-1] = '(?:' . $char[$i-1] . ')';
5652             }
5653             }
5654             }
5655 127         502  
5656 642 50       1231 # make regexp string
5657 642 0 0     1371 $modifier =~ tr/i//d;
5658 0         0 if ($left_e > $right_e) {
5659             if (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
5660             return join '', $ope, $delimiter, $anchor, @char, '>]}' x ($left_e - $right_e), $matched, $end_delimiter, $modifier;
5661 0         0 }
5662             else {
5663             return join '', $ope, $delimiter, $anchor, '(?:', @char, '>]}' x ($left_e - $right_e), ')', $matched, $end_delimiter, $modifier;
5664 0 50 33     0 }
5665 642         3616 }
5666             if (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
5667             return join '', $ope, $delimiter, $anchor, @char, $matched, $end_delimiter, $modifier;
5668 0         0 }
5669             else {
5670             return join '', $ope, $delimiter, $anchor, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
5671             }
5672             }
5673              
5674             #
5675             # double quote stuff
5676 642     180 0 5474 #
5677             sub qq_stuff {
5678             my($delimiter,$end_delimiter,$stuff) = @_;
5679 180 100       326  
5680 180         416 # scalar variable or array variable
5681             if ($stuff =~ /\A [\$\@] /oxms) {
5682             return $stuff;
5683             }
5684 100         390  
  80         213  
5685 80         264 # quote by delimiter
5686 80 50       226 my %octet = map {$_ => 1} ($stuff =~ /\G ([\x00-\xFF]) /oxmsg);
5687 80 50       170 for my $char (qw( ! " $ % & * + - . / : = ? @ ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
5688 80 50       143 next if $char eq $delimiter;
5689 80         155 next if $char eq $end_delimiter;
5690             if (not $octet{$char}) {
5691             return join '', 'qq', $char, $stuff, $char;
5692 80         462 }
5693             }
5694             return join '', 'qq', '<', $stuff, '>';
5695             }
5696              
5697             #
5698             # escape regexp (m'', qr'', and m''b, qr''b)
5699 0     10 0 0 #
5700 10   50     47 sub e_qr_q {
5701             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
5702 10         50 $modifier ||= '';
5703 10 50       14  
5704 10         23 $modifier =~ tr/p//d;
5705 0         0 if ($modifier =~ /([adlu])/oxms) {
5706 0 0       0 my $line = 0;
5707 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
5708 0         0 if ($filename ne __FILE__) {
5709             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
5710             last;
5711 0         0 }
5712             }
5713             die qq{Unsupported modifier "$1" used at line $line.\n};
5714 0         0 }
5715              
5716             $slash = 'div';
5717 10 100       14  
    50          
5718 10         23 # literal null string pattern
5719 8         15 if ($string eq '') {
5720 8         11 $modifier =~ tr/bB//d;
5721             $modifier =~ tr/i//d;
5722             return join '', $ope, $delimiter, $end_delimiter, $modifier;
5723             }
5724              
5725 8         46 # with /b /B modifier
5726             elsif ($modifier =~ tr/bB//d) {
5727             return e_qr_qb($ope,$delimiter,$end_delimiter,$string,$modifier);
5728             }
5729              
5730 0         0 # without /b /B modifier
5731             else {
5732             return e_qr_qt($ope,$delimiter,$end_delimiter,$string,$modifier);
5733             }
5734             }
5735              
5736             #
5737             # escape regexp (m'', qr'')
5738 2     2 0 9 #
5739             sub e_qr_qt {
5740 2 50       7 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
5741              
5742             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
5743 2         5  
5744             # split regexp
5745             my @char = $string =~ /\G((?>
5746             [^\\\[\$\@\/] |
5747             [\x00-\xFF] |
5748             \[\^ |
5749             \[\: (?>[a-z]+) \:\] |
5750             \[\:\^ (?>[a-z]+) \:\] |
5751             [\$\@\/] |
5752             \\ (?:$q_char) |
5753             (?:$q_char)
5754             ))/oxmsg;
5755 2         74  
5756 2 50 33     11 # unescape character
    50 33        
    50 33        
    50          
    50          
    50          
5757             for (my $i=0; $i <= $#char; $i++) {
5758             if (0) {
5759             }
5760 2         16  
5761 0         0 # open character class [...]
5762 0 0       0 elsif ($char[$i] eq '[') {
5763 0         0 my $left = $i;
5764             if ($char[$i+1] eq ']') {
5765 0         0 $i++;
5766 0 0       0 }
5767 0         0 while (1) {
5768             if (++$i > $#char) {
5769 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
5770 0         0 }
5771             if ($char[$i] eq ']') {
5772             my $right = $i;
5773 0         0  
5774             # [...]
5775 0         0 splice @char, $left, $right-$left+1, Ewindows1254::charlist_qr(@char[$left+1..$right-1], $modifier);
5776 0         0  
5777             $i = $left;
5778             last;
5779             }
5780             }
5781             }
5782              
5783 0         0 # open character class [^...]
5784 0 0       0 elsif ($char[$i] eq '[^') {
5785 0         0 my $left = $i;
5786             if ($char[$i+1] eq ']') {
5787 0         0 $i++;
5788 0 0       0 }
5789 0         0 while (1) {
5790             if (++$i > $#char) {
5791 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
5792 0         0 }
5793             if ($char[$i] eq ']') {
5794             my $right = $i;
5795 0         0  
5796             # [^...]
5797 0         0 splice @char, $left, $right-$left+1, Ewindows1254::charlist_not_qr(@char[$left+1..$right-1], $modifier);
5798 0         0  
5799             $i = $left;
5800             last;
5801             }
5802             }
5803             }
5804              
5805 0         0 # escape $ @ / and \
5806             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
5807             $char[$i] = '\\' . $char[$i];
5808             }
5809              
5810 0         0 # rewrite character class or escape character
5811             elsif (my $char = character_class($char[$i],$modifier)) {
5812             $char[$i] = $char;
5813             }
5814              
5815 0 0       0 # /i modifier
5816 0         0 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ewindows1254::uc($char[$i]) ne Ewindows1254::fc($char[$i]))) {
5817             if (CORE::length(Ewindows1254::fc($char[$i])) == 1) {
5818             $char[$i] = '[' . Ewindows1254::uc($char[$i]) . Ewindows1254::fc($char[$i]) . ']';
5819 0         0 }
5820             else {
5821             $char[$i] = '(?:' . Ewindows1254::uc($char[$i]) . '|' . Ewindows1254::fc($char[$i]) . ')';
5822             }
5823             }
5824              
5825 0 0       0 # quote character before ? + * {
5826             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
5827             if ($char[$i-1] =~ /\A [\x00-\xFF] \z/oxms) {
5828 0         0 }
5829             else {
5830             $char[$i-1] = '(?:' . $char[$i-1] . ')';
5831             }
5832             }
5833 0         0 }
5834 2         6  
5835             $delimiter = '/';
5836 2         5 $end_delimiter = '/';
5837 2         3  
5838             $modifier =~ tr/i//d;
5839             return join '', $ope, $delimiter, $anchor, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
5840             }
5841              
5842             #
5843             # escape regexp (m''b, qr''b)
5844 2     0 0 18 #
5845             sub e_qr_qb {
5846             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
5847 0         0  
5848             # split regexp
5849             my @char = $string =~ /\G ((?>[^\\]|\\\\)) /oxmsg;
5850 0         0  
5851 0 0       0 # unescape character
    0          
5852             for (my $i=0; $i <= $#char; $i++) {
5853             if (0) {
5854             }
5855 0         0  
5856             # remain \\
5857             elsif ($char[$i] eq '\\\\') {
5858             }
5859              
5860 0         0 # escape $ @ / and \
5861             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
5862             $char[$i] = '\\' . $char[$i];
5863             }
5864 0         0 }
5865 0         0  
5866 0         0 $delimiter = '/';
5867             $end_delimiter = '/';
5868             return join '', $ope, $delimiter, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
5869             }
5870              
5871             #
5872             # escape regexp (s/here//)
5873 0     76 0 0 #
5874 76   100     231 sub e_s1 {
5875             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
5876 76         409 $modifier ||= '';
5877 76 50       122  
5878 76         228 $modifier =~ tr/p//d;
5879 0         0 if ($modifier =~ /([adlu])/oxms) {
5880 0 0       0 my $line = 0;
5881 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
5882 0         0 if ($filename ne __FILE__) {
5883             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
5884             last;
5885 0         0 }
5886             }
5887             die qq{Unsupported modifier "$1" used at line $line.\n};
5888 0         0 }
5889              
5890             $slash = 'div';
5891 76 100       163  
    50          
5892 76         271 # literal null string pattern
5893 8         10 if ($string eq '') {
5894 8         24 $modifier =~ tr/bB//d;
5895             $modifier =~ tr/i//d;
5896             return join '', $ope, $delimiter, $end_delimiter, $modifier;
5897             }
5898              
5899             # /b /B modifier
5900             elsif ($modifier =~ tr/bB//d) {
5901 8 0       56  
5902 0         0 # choice again delimiter
5903 0         0 if ($delimiter =~ / [\@:] /oxms) {
  0         0  
5904 0 0       0 my @char = $string =~ /\G ([\x00-\xFF]) /oxmsg;
    0          
    0          
    0          
5905 0         0 my %octet = map {$_ => 1} @char;
5906 0         0 if (not $octet{')'}) {
5907             $delimiter = '(';
5908             $end_delimiter = ')';
5909 0         0 }
5910 0         0 elsif (not $octet{'}'}) {
5911             $delimiter = '{';
5912             $end_delimiter = '}';
5913 0         0 }
5914 0         0 elsif (not $octet{']'}) {
5915             $delimiter = '[';
5916             $end_delimiter = ']';
5917 0         0 }
5918 0         0 elsif (not $octet{'>'}) {
5919             $delimiter = '<';
5920             $end_delimiter = '>';
5921 0         0 }
5922 0 0       0 else {
5923 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
5924 0         0 if (not $octet{$char}) {
5925 0         0 $delimiter = $char;
5926             $end_delimiter = $char;
5927             last;
5928             }
5929             }
5930             }
5931 0         0 }
5932 0         0  
5933             my $prematch = '';
5934             return join '', $ope, $delimiter, $prematch, '(?:', $string, ')', $matched, $end_delimiter, $modifier;
5935 0 100       0 }
5936 68         203  
5937             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
5938             my $metachar = qr/[\@\\|[\]{^]/oxms;
5939 68         286  
5940             # split regexp
5941             my @char = $string =~ /\G((?>
5942             [^\\\$\@\[\(] |
5943             \\ (?>[1-9][0-9]*) |
5944             \\g (?>\s*) (?>[1-9][0-9]*) |
5945             \\g (?>\s*) \{ (?>\s*) (?>[1-9][0-9]*) (?>\s*) \} |
5946             \\g (?>\s*) \{ (?>\s*) - (?>\s*) (?>[1-9][0-9]*) (?>\s*) \} |
5947             \\x (?>[0-9A-Fa-f]{1,2}) |
5948             \\ (?>[0-7]{2,3}) |
5949             \\c [\x40-\x5F] |
5950             \\x\{ (?>[0-9A-Fa-f]+) \} |
5951             \\o\{ (?>[0-7]+) \} |
5952             \\[bBNpP]\{ (?>[^0-9\}][^\}]*) \} |
5953             \\ $q_char |
5954             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
5955             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
5956             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
5957             [\$\@] $qq_variable |
5958             \$ (?>\s* [0-9]+) |
5959             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
5960             \$ \$ (?![\w\{]) |
5961             \$ (?>\s*) \$ (?>\s*) $qq_variable |
5962             \[\^ |
5963             \[\: (?>[a-z]+) :\] |
5964             \[\:\^ (?>[a-z]+) :\] |
5965             \(\? |
5966             $q_char
5967             ))/oxmsg;
5968 68 50       16313  
5969 68         476 # choice again delimiter
  0         0  
5970 0 0       0 if ($delimiter =~ / [\@:] /oxms) {
    0          
    0          
    0          
5971 0         0 my %octet = map {$_ => 1} @char;
5972 0         0 if (not $octet{')'}) {
5973             $delimiter = '(';
5974             $end_delimiter = ')';
5975 0         0 }
5976 0         0 elsif (not $octet{'}'}) {
5977             $delimiter = '{';
5978             $end_delimiter = '}';
5979 0         0 }
5980 0         0 elsif (not $octet{']'}) {
5981             $delimiter = '[';
5982             $end_delimiter = ']';
5983 0         0 }
5984 0         0 elsif (not $octet{'>'}) {
5985             $delimiter = '<';
5986             $end_delimiter = '>';
5987 0         0 }
5988 0 0       0 else {
5989 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
5990 0         0 if (not $octet{$char}) {
5991 0         0 $delimiter = $char;
5992             $end_delimiter = $char;
5993             last;
5994             }
5995             }
5996             }
5997             }
5998 0         0  
  68         149  
5999             # count '('
6000 253         505 my $parens = grep { $_ eq '(' } @char;
6001 68         114  
6002 68         109 my $left_e = 0;
6003             my $right_e = 0;
6004             for (my $i=0; $i <= $#char; $i++) {
6005 68 50 33     199  
    50 33        
    100          
    100          
    50          
    50          
6006 195         1232 # "\L\u" --> "\u\L"
6007             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
6008             @char[$i,$i+1] = @char[$i+1,$i];
6009             }
6010              
6011 0         0 # "\U\l" --> "\l\U"
6012             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
6013             @char[$i,$i+1] = @char[$i+1,$i];
6014             }
6015              
6016 0         0 # octal escape sequence
6017             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
6018             $char[$i] = Ewindows1254::octchr($1);
6019             }
6020              
6021 1         3 # hexadecimal escape sequence
6022             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
6023             $char[$i] = Ewindows1254::hexchr($1);
6024             }
6025              
6026             # \b{...} --> b\{...}
6027             # \B{...} --> B\{...}
6028             # \N{CHARNAME} --> N\{CHARNAME}
6029             # \p{PROPERTY} --> p\{PROPERTY}
6030 1         3 # \P{PROPERTY} --> P\{PROPERTY}
6031             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^0-9\}][^\}]*) \} ) \z/oxms) {
6032             $char[$i] = $1 . '\\' . $2;
6033             }
6034              
6035 0         0 # \p, \P, \X --> p, P, X
6036             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
6037             $char[$i] = $1;
6038 0 50 66     0 }
    100 66        
    50 100        
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
    100          
    100          
6039              
6040             if (0) {
6041             }
6042 195         876  
6043 0 0 0     0 # join separated multiple-octet
    0 0        
    0 0        
      0        
      0        
      0        
6044 0         0 elsif ($char[$i] =~ /\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms) {
6045             if ( ($i+3 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+3]) == 3) and (CORE::eval(sprintf '"%s%s%s%s"', @char[$i..$i+3]) =~ /\A $q_char \z/oxms)) {
6046             $char[$i] .= join '', splice @char, $i+1, 3;
6047 0         0 }
6048             elsif (($i+2 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+2]) == 2) and (CORE::eval(sprintf '"%s%s%s"', @char[$i..$i+2]) =~ /\A $q_char \z/oxms)) {
6049             $char[$i] .= join '', splice @char, $i+1, 2;
6050 0         0 }
6051             elsif (($i+1 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, $char[$i+1 ]) == 1) and (CORE::eval(sprintf '"%s%s"', @char[$i..$i+1]) =~ /\A $q_char \z/oxms)) {
6052             $char[$i] .= join '', splice @char, $i+1, 1;
6053             }
6054             }
6055              
6056 0         0 # open character class [...]
6057 13 50       38 elsif ($char[$i] eq '[') {
6058 13         52 my $left = $i;
6059             if ($char[$i+1] eq ']') {
6060 0         0 $i++;
6061 13 50       20 }
6062 58         101 while (1) {
6063             if (++$i > $#char) {
6064 0 100       0 die __FILE__, ": Unmatched [] in regexp\n";
6065 58         115 }
6066             if ($char[$i] eq ']') {
6067             my $right = $i;
6068 13 50       23  
6069 13         86 # [...]
  0         0  
6070             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
6071             splice @char, $left, $right-$left+1, sprintf(q{@{[Ewindows1254::charlist_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
6072 0         0 }
6073             else {
6074             splice @char, $left, $right-$left+1, Ewindows1254::charlist_qr(@char[$left+1..$right-1], $modifier);
6075 13         59 }
6076 13         26  
6077             $i = $left;
6078             last;
6079             }
6080             }
6081             }
6082              
6083 13         50 # open character class [^...]
6084 0 0       0 elsif ($char[$i] eq '[^') {
6085 0         0 my $left = $i;
6086             if ($char[$i+1] eq ']') {
6087 0         0 $i++;
6088 0 0       0 }
6089 0         0 while (1) {
6090             if (++$i > $#char) {
6091 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
6092 0         0 }
6093             if ($char[$i] eq ']') {
6094             my $right = $i;
6095 0 0       0  
6096 0         0 # [^...]
  0         0  
6097             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
6098             splice @char, $left, $right-$left+1, sprintf(q{@{[Ewindows1254::charlist_not_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
6099 0         0 }
6100             else {
6101             splice @char, $left, $right-$left+1, Ewindows1254::charlist_not_qr(@char[$left+1..$right-1], $modifier);
6102 0         0 }
6103 0         0  
6104             $i = $left;
6105             last;
6106             }
6107             }
6108             }
6109              
6110 0         0 # rewrite character class or escape character
6111             elsif (my $char = character_class($char[$i],$modifier)) {
6112             $char[$i] = $char;
6113             }
6114              
6115 7 50       16 # /i modifier
6116 3         6 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ewindows1254::uc($char[$i]) ne Ewindows1254::fc($char[$i]))) {
6117             if (CORE::length(Ewindows1254::fc($char[$i])) == 1) {
6118             $char[$i] = '[' . Ewindows1254::uc($char[$i]) . Ewindows1254::fc($char[$i]) . ']';
6119 3         8 }
6120             else {
6121             $char[$i] = '(?:' . Ewindows1254::uc($char[$i]) . '|' . Ewindows1254::fc($char[$i]) . ')';
6122             }
6123             }
6124              
6125 0 0       0 # \u \l \U \L \F \Q \E
6126 0         0 elsif ($char[$i] =~ /\A [<>] \z/oxms) {
6127             if ($right_e < $left_e) {
6128             $char[$i] = '\\' . $char[$i];
6129             }
6130 0         0 }
6131 0         0 elsif ($char[$i] eq '\u') {
6132             $char[$i] = '@{[Ewindows1254::ucfirst qq<';
6133             $left_e++;
6134 0         0 }
6135 0         0 elsif ($char[$i] eq '\l') {
6136             $char[$i] = '@{[Ewindows1254::lcfirst qq<';
6137             $left_e++;
6138 0         0 }
6139 0         0 elsif ($char[$i] eq '\U') {
6140             $char[$i] = '@{[Ewindows1254::uc qq<';
6141             $left_e++;
6142 0         0 }
6143 0         0 elsif ($char[$i] eq '\L') {
6144             $char[$i] = '@{[Ewindows1254::lc qq<';
6145             $left_e++;
6146 0         0 }
6147 0         0 elsif ($char[$i] eq '\F') {
6148             $char[$i] = '@{[Ewindows1254::fc qq<';
6149             $left_e++;
6150 0         0 }
6151 0         0 elsif ($char[$i] eq '\Q') {
6152             $char[$i] = '@{[CORE::quotemeta qq<';
6153             $left_e++;
6154 0 0       0 }
6155 0         0 elsif ($char[$i] eq '\E') {
6156 0         0 if ($right_e < $left_e) {
6157             $char[$i] = '>]}';
6158             $right_e++;
6159 0         0 }
6160             else {
6161             $char[$i] = '';
6162             }
6163 0         0 }
6164 0 0       0 elsif ($char[$i] eq '\Q') {
6165 0         0 while (1) {
6166             if (++$i > $#char) {
6167 0 0       0 last;
6168 0         0 }
6169             if ($char[$i] eq '\E') {
6170             last;
6171             }
6172             }
6173             }
6174             elsif ($char[$i] eq '\E') {
6175             }
6176              
6177             # \0 --> \0
6178             elsif ($char[$i] =~ /\A \\ (?>\s*) 0 \z/oxms) {
6179             }
6180              
6181             # \g{N}, \g{-N}
6182              
6183             # P.108 Using Simple Patterns
6184             # in Chapter 7: In the World of Regular Expressions
6185             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
6186              
6187             # P.221 Capturing
6188             # in Chapter 5: Pattern Matching
6189             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
6190              
6191             # \g{-1}, \g{-2}, \g{-3} --> \g{-1}, \g{-2}, \g{-3}
6192             elsif ($char[$i] =~ /\A \\g (?>\s*) \{ (?>\s*) - (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
6193             }
6194              
6195             # \g{1}, \g{2}, \g{3} --> \g{2}, \g{3}, \g{4} (only when multibyte anchoring is enable)
6196             elsif ($char[$i] =~ /\A \\g (?>\s*) \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
6197             }
6198              
6199             # \g1, \g2, \g3 --> \g2, \g3, \g4 (only when multibyte anchoring is enable)
6200             elsif ($char[$i] =~ /\A \\g (?>\s*) ((?>[1-9][0-9]*)) \z/oxms) {
6201             }
6202              
6203             # \1, \2, \3 --> \2, \3, \4 (only when multibyte anchoring is enable)
6204             elsif ($char[$i] =~ /\A \\ (?>\s*) ((?>[1-9][0-9]*)) \z/oxms) {
6205             }
6206              
6207 0 0       0 # $0 --> $0
6208 0         0 elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
6209             if ($ignorecase) {
6210             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6211             }
6212 0 0       0 }
6213 0         0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
6214             if ($ignorecase) {
6215             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6216             }
6217             }
6218              
6219             # $$ --> $$
6220             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
6221             }
6222              
6223             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
6224 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
6225 0 0       0 elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
6226 0         0 $char[$i] = e_capture($1);
6227             if ($ignorecase) {
6228             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6229             }
6230 0         0 }
6231 0 0       0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
6232 0         0 $char[$i] = e_capture($1);
6233             if ($ignorecase) {
6234             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6235             }
6236             }
6237              
6238 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
6239 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
6240 0         0 $char[$i] = e_capture($1.'->'.$2);
6241             if ($ignorecase) {
6242             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6243             }
6244             }
6245              
6246 0         0 # $$foo{ ... } --> $ $foo->{ ... }
6247 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
6248 0         0 $char[$i] = e_capture($1.'->'.$2);
6249             if ($ignorecase) {
6250             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6251             }
6252             }
6253              
6254 0         0 # $$foo
6255 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
6256 0         0 $char[$i] = e_capture($1);
6257             if ($ignorecase) {
6258             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6259             }
6260             }
6261              
6262 0 50       0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ewindows1254::PREMATCH()
6263 4         15 elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
6264             if ($ignorecase) {
6265             $char[$i] = '@{[Ewindows1254::ignorecase(Ewindows1254::PREMATCH())]}';
6266 0         0 }
6267             else {
6268             $char[$i] = '@{[Ewindows1254::PREMATCH()]}';
6269             }
6270             }
6271              
6272 4 50       17 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ewindows1254::MATCH()
6273 4         14 elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
6274             if ($ignorecase) {
6275             $char[$i] = '@{[Ewindows1254::ignorecase(Ewindows1254::MATCH())]}';
6276 0         0 }
6277             else {
6278             $char[$i] = '@{[Ewindows1254::MATCH()]}';
6279             }
6280             }
6281              
6282 4 50       15 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ewindows1254::POSTMATCH()
6283 3         9 elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
6284             if ($ignorecase) {
6285             $char[$i] = '@{[Ewindows1254::ignorecase(Ewindows1254::POSTMATCH())]}';
6286 0         0 }
6287             else {
6288             $char[$i] = '@{[Ewindows1254::POSTMATCH()]}';
6289             }
6290             }
6291              
6292 3 0       10 # ${ foo }
6293 0         0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} \z/oxms) {
6294             if ($ignorecase) {
6295             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6296             }
6297             }
6298              
6299 0         0 # ${ ... }
6300 0 0       0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
6301 0         0 $char[$i] = e_capture($1);
6302             if ($ignorecase) {
6303             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6304             }
6305             }
6306              
6307 0         0 # $scalar or @array
6308 4 50       15 elsif ($char[$i] =~ /\A [\$\@].+ /oxms) {
6309 4         25 $char[$i] = e_string($char[$i]);
6310             if ($ignorecase) {
6311             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6312             }
6313             }
6314              
6315 0 50       0 # quote character before ? + * {
6316             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
6317             if ($char[$i-1] =~ /\A (?:[\x00-\xFF]|\\[0-7]{2,3}|\\x[0-9-A-Fa-f]{1,2}) \z/oxms) {
6318 13         74 }
6319             else {
6320             $char[$i-1] = '(?:' . $char[$i-1] . ')';
6321             }
6322             }
6323             }
6324 13         62  
6325 68         164 # make regexp string
6326 68 50       126 my $prematch = '';
6327 68         216 $modifier =~ tr/i//d;
6328             if ($left_e > $right_e) {
6329 0         0 return join '', $ope, $delimiter, $prematch, '(?:', @char, '>]}' x ($left_e - $right_e), ')', $matched, $end_delimiter, $modifier;
6330             }
6331             return join '', $ope, $delimiter, $prematch, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
6332             }
6333              
6334             #
6335             # escape regexp (s'here'' or s'here''b)
6336 68     21 0 857 #
6337 21   100     51 sub e_s1_q {
6338             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
6339 21         77 $modifier ||= '';
6340 21 50       31  
6341 21         46 $modifier =~ tr/p//d;
6342 0         0 if ($modifier =~ /([adlu])/oxms) {
6343 0 0       0 my $line = 0;
6344 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
6345 0         0 if ($filename ne __FILE__) {
6346             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
6347             last;
6348 0         0 }
6349             }
6350             die qq{Unsupported modifier "$1" used at line $line.\n};
6351 0         0 }
6352              
6353             $slash = 'div';
6354 21 100       35  
    50          
6355 21         57 # literal null string pattern
6356 8         13 if ($string eq '') {
6357 8         9 $modifier =~ tr/bB//d;
6358             $modifier =~ tr/i//d;
6359             return join '', $ope, $delimiter, $end_delimiter, $modifier;
6360             }
6361              
6362 8         50 # with /b /B modifier
6363             elsif ($modifier =~ tr/bB//d) {
6364             return e_s1_qb($ope,$delimiter,$end_delimiter,$string,$modifier);
6365             }
6366              
6367 0         0 # without /b /B modifier
6368             else {
6369             return e_s1_qt($ope,$delimiter,$end_delimiter,$string,$modifier);
6370             }
6371             }
6372              
6373             #
6374             # escape regexp (s'here'')
6375 13     13 0 35 #
6376             sub e_s1_qt {
6377 13 50       32 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
6378              
6379             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
6380 13         27  
6381             # split regexp
6382             my @char = $string =~ /\G((?>
6383             [^\\\[\$\@\/] |
6384             [\x00-\xFF] |
6385             \[\^ |
6386             \[\: (?>[a-z]+) \:\] |
6387             \[\:\^ (?>[a-z]+) \:\] |
6388             [\$\@\/] |
6389             \\ (?:$q_char) |
6390             (?:$q_char)
6391             ))/oxmsg;
6392 13         225  
6393 13 50 33     78 # unescape character
    50 33        
    50 66        
    100          
    50          
    50          
6394             for (my $i=0; $i <= $#char; $i++) {
6395             if (0) {
6396             }
6397 25         117  
6398 0         0 # open character class [...]
6399 0 0       0 elsif ($char[$i] eq '[') {
6400 0         0 my $left = $i;
6401             if ($char[$i+1] eq ']') {
6402 0         0 $i++;
6403 0 0       0 }
6404 0         0 while (1) {
6405             if (++$i > $#char) {
6406 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
6407 0         0 }
6408             if ($char[$i] eq ']') {
6409             my $right = $i;
6410 0         0  
6411             # [...]
6412 0         0 splice @char, $left, $right-$left+1, Ewindows1254::charlist_qr(@char[$left+1..$right-1], $modifier);
6413 0         0  
6414             $i = $left;
6415             last;
6416             }
6417             }
6418             }
6419              
6420 0         0 # open character class [^...]
6421 0 0       0 elsif ($char[$i] eq '[^') {
6422 0         0 my $left = $i;
6423             if ($char[$i+1] eq ']') {
6424 0         0 $i++;
6425 0 0       0 }
6426 0         0 while (1) {
6427             if (++$i > $#char) {
6428 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
6429 0         0 }
6430             if ($char[$i] eq ']') {
6431             my $right = $i;
6432 0         0  
6433             # [^...]
6434 0         0 splice @char, $left, $right-$left+1, Ewindows1254::charlist_not_qr(@char[$left+1..$right-1], $modifier);
6435 0         0  
6436             $i = $left;
6437             last;
6438             }
6439             }
6440             }
6441              
6442 0         0 # escape $ @ / and \
6443             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
6444             $char[$i] = '\\' . $char[$i];
6445             }
6446              
6447 0         0 # rewrite character class or escape character
6448             elsif (my $char = character_class($char[$i],$modifier)) {
6449             $char[$i] = $char;
6450             }
6451              
6452 6 0       14 # /i modifier
6453 0         0 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ewindows1254::uc($char[$i]) ne Ewindows1254::fc($char[$i]))) {
6454             if (CORE::length(Ewindows1254::fc($char[$i])) == 1) {
6455             $char[$i] = '[' . Ewindows1254::uc($char[$i]) . Ewindows1254::fc($char[$i]) . ']';
6456 0         0 }
6457             else {
6458             $char[$i] = '(?:' . Ewindows1254::uc($char[$i]) . '|' . Ewindows1254::fc($char[$i]) . ')';
6459             }
6460             }
6461              
6462 0 0       0 # quote character before ? + * {
6463             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
6464             if ($char[$i-1] =~ /\A [\x00-\xFF] \z/oxms) {
6465 0         0 }
6466             else {
6467             $char[$i-1] = '(?:' . $char[$i-1] . ')';
6468             }
6469             }
6470 0         0 }
6471 13         30  
6472 13         23 $modifier =~ tr/i//d;
6473 13         16 $delimiter = '/';
6474 13         23 $end_delimiter = '/';
6475             my $prematch = '';
6476             return join '', $ope, $delimiter, $prematch, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
6477             }
6478              
6479             #
6480             # escape regexp (s'here''b)
6481 13     0 0 107 #
6482             sub e_s1_qb {
6483             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
6484 0         0  
6485             # split regexp
6486             my @char = $string =~ /\G (?>[^\\]|\\\\) /oxmsg;
6487 0         0  
6488 0 0       0 # unescape character
    0          
6489             for (my $i=0; $i <= $#char; $i++) {
6490             if (0) {
6491             }
6492 0         0  
6493             # remain \\
6494             elsif ($char[$i] eq '\\\\') {
6495             }
6496              
6497 0         0 # escape $ @ / and \
6498             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
6499             $char[$i] = '\\' . $char[$i];
6500             }
6501 0         0 }
6502 0         0  
6503 0         0 $delimiter = '/';
6504 0         0 $end_delimiter = '/';
6505             my $prematch = '';
6506             return join '', $ope, $delimiter, $prematch, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
6507             }
6508              
6509             #
6510             # escape regexp (s''here')
6511 0     16 0 0 #
6512             sub e_s2_q {
6513 16         36 my($ope,$delimiter,$end_delimiter,$string) = @_;
6514              
6515 16         20 $slash = 'div';
6516 16         109  
6517 16 100       46 my @char = $string =~ / \G (?>[^\\]|\\\\|$q_char) /oxmsg;
    100          
6518             for (my $i=0; $i <= $#char; $i++) {
6519             if (0) {
6520             }
6521 9         50  
6522             # not escape \\
6523             elsif ($char[$i] =~ /\A \\\\ \z/oxms) {
6524             }
6525              
6526 0         0 # escape $ @ / and \
6527             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
6528             $char[$i] = '\\' . $char[$i];
6529             }
6530 5         19 }
6531              
6532             return join '', $ope, $delimiter, @char, $end_delimiter;
6533             }
6534              
6535             #
6536             # escape regexp (s/here/and here/modifier)
6537 16     97 0 55 #
6538 97   100     760 sub e_sub {
6539             my($variable,$delimiter1,$pattern,$end_delimiter1,$delimiter2,$replacement,$end_delimiter2,$modifier) = @_;
6540 97         437 $modifier ||= '';
6541 97 50       215  
6542 97         262 $modifier =~ tr/p//d;
6543 0         0 if ($modifier =~ /([adlu])/oxms) {
6544 0 0       0 my $line = 0;
6545 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
6546 0         0 if ($filename ne __FILE__) {
6547             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
6548             last;
6549 0         0 }
6550             }
6551             die qq{Unsupported modifier "$1" used at line $line.\n};
6552 0 100       0 }
6553 97         267  
6554 36         50 if ($variable eq '') {
6555             $variable = '$_';
6556             $bind_operator = ' =~ ';
6557 36         54 }
6558              
6559             $slash = 'div';
6560              
6561             # P.128 Start of match (or end of previous match): \G
6562             # P.130 Advanced Use of \G with Perl
6563             # in Chapter 3: Overview of Regular Expression Features and Flavors
6564             # P.312 Iterative Matching: Scalar Context, with /g
6565             # in Chapter 7: Perl
6566             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
6567              
6568             # P.181 Where You Left Off: The \G Assertion
6569             # in Chapter 5: Pattern Matching
6570             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
6571              
6572             # P.220 Where You Left Off: The \G Assertion
6573             # in Chapter 5: Pattern Matching
6574 97         168 # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
6575 97         167  
6576             my $e_modifier = $modifier =~ tr/e//d;
6577 97         158 my $r_modifier = $modifier =~ tr/r//d;
6578 97 50       168  
6579 97         298 my $my = '';
6580 0         0 if ($variable =~ s/\A \( (?>\s*) ( (?>(?: local \b | my \b | our \b | state \b )?) .+ ) \) \z/$1/oxms) {
6581 0         0 $my = $variable;
6582             $variable =~ s/ (?: local \b | my \b | our \b | state \b ) (?>\s*) //oxms;
6583             $variable =~ s/ = .+ \z//oxms;
6584 0         0 }
6585 97         268  
6586             (my $variable_basename = $variable) =~ s/ [\[\{].* \z//oxms;
6587             $variable_basename =~ s/ \s+ \z//oxms;
6588 97         185  
6589 97 100       188 # quote replacement string
6590 97         273 my $e_replacement = '';
6591 17         36 if ($e_modifier >= 1) {
6592             $e_replacement = e_qq('', '', '', $replacement);
6593             $e_modifier--;
6594 17 100       26 }
6595 80         196 else {
6596             if ($delimiter2 eq "'") {
6597             $e_replacement = e_s2_q('qq', '/', '/', $replacement);
6598 16         38 }
6599             else {
6600             $e_replacement = e_qq ('qq', $delimiter2, $end_delimiter2, $replacement);
6601             }
6602 64         177 }
6603              
6604             my $sub = '';
6605 97 100       205  
6606 97 100       281 # with /r
6607             if ($r_modifier) {
6608             if (0) {
6609             }
6610 8         22  
6611 0 50       0 # s///gr without multibyte anchoring
6612             elsif ($modifier =~ /g/oxms) {
6613             $sub = sprintf(
6614             # 1 2 3 4 5
6615             q,
6616              
6617             $variable, # 1
6618             ($delimiter1 eq "'") ? # 2
6619             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
6620             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
6621             $s_matched, # 3
6622             $e_replacement, # 4
6623             '$Ewindows1254::re_r=CORE::eval $Ewindows1254::re_r; ' x $e_modifier, # 5
6624             );
6625             }
6626              
6627             # s///r
6628 4         18 else {
6629              
6630 4 50       7 my $prematch = q{$`};
6631              
6632             $sub = sprintf(
6633             # 1 2 3 4 5 6 7
6634             q<(%s =~ %s) ? CORE::eval{%s local $^W=0; local $Ewindows1254::re_r=%s; %s"%s$Ewindows1254::re_r$'" } : %s>,
6635              
6636             $variable, # 1
6637             ($delimiter1 eq "'") ? # 2
6638             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
6639             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
6640             $s_matched, # 3
6641             $e_replacement, # 4
6642             '$Ewindows1254::re_r=CORE::eval $Ewindows1254::re_r; ' x $e_modifier, # 5
6643             $prematch, # 6
6644             $variable, # 7
6645             );
6646             }
6647 4 50       17  
6648 8         22 # $var !~ s///r doesn't make sense
6649             if ($bind_operator =~ / !~ /oxms) {
6650             $sub = q{die("$0: Using !~ with s///r doesn't make sense"), } . $sub;
6651             }
6652             }
6653              
6654 0 100       0 # without /r
6655             else {
6656             if (0) {
6657             }
6658 89         254  
6659 0 100       0 # s///g without multibyte anchoring
    100          
6660             elsif ($modifier =~ /g/oxms) {
6661             $sub = sprintf(
6662             # 1 2 3 4 5 6 7 8
6663             q,
6664              
6665             $variable, # 1
6666             ($delimiter1 eq "'") ? # 2
6667             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
6668             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
6669             $s_matched, # 3
6670             $e_replacement, # 4
6671             '$Ewindows1254::re_r=CORE::eval $Ewindows1254::re_r; ' x $e_modifier, # 5
6672             $variable, # 6
6673             $variable, # 7
6674             ($bind_operator =~ / !~ /oxms) ? '!' : '', # 8
6675             );
6676             }
6677              
6678             # s///
6679 22         95 else {
6680              
6681 67 100       154 my $prematch = q{$`};
    100          
6682              
6683             $sub = sprintf(
6684              
6685             ($bind_operator =~ / =~ /oxms) ?
6686              
6687             # 1 2 3 4 5 6 7 8
6688             q<(%s%s%s) ? CORE::eval{%s local $^W=0; local $Ewindows1254::re_r=%s; %s%s="%s$Ewindows1254::re_r$'"; 1 } : undef> :
6689              
6690             # 1 2 3 4 5 6 7 8
6691             q<(%s%s%s) ? 1 : CORE::eval{%s local $^W=0; local $Ewindows1254::re_r=%s; %s%s="%s$Ewindows1254::re_r$'"; undef }>,
6692              
6693             $variable, # 1
6694             $bind_operator, # 2
6695             ($delimiter1 eq "'") ? # 3
6696             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
6697             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
6698             $s_matched, # 4
6699             $e_replacement, # 5
6700             '$Ewindows1254::re_r=CORE::eval $Ewindows1254::re_r; ' x $e_modifier, # 6
6701             $variable, # 7
6702             $prematch, # 8
6703             );
6704             }
6705             }
6706 67 50       397  
6707 97         296 # (my $foo = $bar) =~ s/// --> (my $foo = $bar, CORE::eval { ... })[1]
6708             if ($my ne '') {
6709             $sub = "($my, $sub)[1]";
6710             }
6711 0         0  
6712 97         170 # clear s/// variable
6713             $sub_variable = '';
6714 97         141 $bind_operator = '';
6715              
6716             return $sub;
6717             }
6718              
6719             #
6720             # escape regexp of split qr//
6721 97     74 0 831 #
6722 74   100     360 sub e_split {
6723             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
6724 74         345 $modifier ||= '';
6725 74 50       131  
6726 74         350 $modifier =~ tr/p//d;
6727 0         0 if ($modifier =~ /([adlu])/oxms) {
6728 0 0       0 my $line = 0;
6729 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
6730 0         0 if ($filename ne __FILE__) {
6731             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
6732             last;
6733 0         0 }
6734             }
6735             die qq{Unsupported modifier "$1" used at line $line.\n};
6736 0         0 }
6737              
6738             $slash = 'div';
6739 74 50       135  
6740 74         189 # /b /B modifier
6741             if ($modifier =~ tr/bB//d) {
6742             return join '', 'split', $ope, $delimiter, $string, $end_delimiter, $modifier;
6743 0 50       0 }
6744 74         202  
6745             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
6746             my $metachar = qr/[\@\\|[\]{^]/oxms;
6747 74         395  
6748             # split regexp
6749             my @char = $string =~ /\G((?>
6750             [^\\\$\@\[\(] |
6751             \\x (?>[0-9A-Fa-f]{1,2}) |
6752             \\ (?>[0-7]{2,3}) |
6753             \\c [\x40-\x5F] |
6754             \\x\{ (?>[0-9A-Fa-f]+) \} |
6755             \\o\{ (?>[0-7]+) \} |
6756             \\[bBNpP]\{ (?>[^0-9\}][^\}]*) \} |
6757             \\ $q_char |
6758             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
6759             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
6760             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
6761             [\$\@] $qq_variable |
6762             \$ (?>\s* [0-9]+) |
6763             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
6764             \$ \$ (?![\w\{]) |
6765             \$ (?>\s*) \$ (?>\s*) $qq_variable |
6766             \[\^ |
6767             \[\: (?>[a-z]+) :\] |
6768             \[\:\^ (?>[a-z]+) :\] |
6769             \(\? |
6770             $q_char
6771 74         9812 ))/oxmsg;
6772 74         268  
6773 74         105 my $left_e = 0;
6774             my $right_e = 0;
6775             for (my $i=0; $i <= $#char; $i++) {
6776 74 50 33     329  
    50 33        
    100          
    100          
    50          
    50          
6777 249         1416 # "\L\u" --> "\u\L"
6778             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
6779             @char[$i,$i+1] = @char[$i+1,$i];
6780             }
6781              
6782 0         0 # "\U\l" --> "\l\U"
6783             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
6784             @char[$i,$i+1] = @char[$i+1,$i];
6785             }
6786              
6787 0         0 # octal escape sequence
6788             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
6789             $char[$i] = Ewindows1254::octchr($1);
6790             }
6791              
6792 1         3 # hexadecimal escape sequence
6793             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
6794             $char[$i] = Ewindows1254::hexchr($1);
6795             }
6796              
6797             # \b{...} --> b\{...}
6798             # \B{...} --> B\{...}
6799             # \N{CHARNAME} --> N\{CHARNAME}
6800             # \p{PROPERTY} --> p\{PROPERTY}
6801 1         4 # \P{PROPERTY} --> P\{PROPERTY}
6802             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^0-9\}][^\}]*) \} ) \z/oxms) {
6803             $char[$i] = $1 . '\\' . $2;
6804             }
6805              
6806 0         0 # \p, \P, \X --> p, P, X
6807             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
6808             $char[$i] = $1;
6809 0 50 100     0 }
    100 33        
    50 33        
    100 100        
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
    100          
    100          
6810              
6811             if (0) {
6812             }
6813 249         931  
6814 0 0 0     0 # join separated multiple-octet
    0 0        
    0 0        
      0        
      0        
      0        
6815 0         0 elsif ($char[$i] =~ /\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms) {
6816             if ( ($i+3 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+3]) == 3) and (CORE::eval(sprintf '"%s%s%s%s"', @char[$i..$i+3]) =~ /\A $q_char \z/oxms)) {
6817             $char[$i] .= join '', splice @char, $i+1, 3;
6818 0         0 }
6819             elsif (($i+2 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+2]) == 2) and (CORE::eval(sprintf '"%s%s%s"', @char[$i..$i+2]) =~ /\A $q_char \z/oxms)) {
6820             $char[$i] .= join '', splice @char, $i+1, 2;
6821 0         0 }
6822             elsif (($i+1 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, $char[$i+1 ]) == 1) and (CORE::eval(sprintf '"%s%s"', @char[$i..$i+1]) =~ /\A $q_char \z/oxms)) {
6823             $char[$i] .= join '', splice @char, $i+1, 1;
6824             }
6825             }
6826              
6827 0         0 # open character class [...]
6828 3 50       6 elsif ($char[$i] eq '[') {
6829 3         15 my $left = $i;
6830             if ($char[$i+1] eq ']') {
6831 0         0 $i++;
6832 3 50       5 }
6833 7         17 while (1) {
6834             if (++$i > $#char) {
6835 0 100       0 die __FILE__, ": Unmatched [] in regexp\n";
6836 7         11 }
6837             if ($char[$i] eq ']') {
6838             my $right = $i;
6839 3 50       5  
6840 3         19 # [...]
  0         0  
6841             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
6842             splice @char, $left, $right-$left+1, sprintf(q{@{[Ewindows1254::charlist_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
6843 0         0 }
6844             else {
6845             splice @char, $left, $right-$left+1, Ewindows1254::charlist_qr(@char[$left+1..$right-1], $modifier);
6846 3         14 }
6847 3         7  
6848             $i = $left;
6849             last;
6850             }
6851             }
6852             }
6853              
6854 3         10 # open character class [^...]
6855 0 0       0 elsif ($char[$i] eq '[^') {
6856 0         0 my $left = $i;
6857             if ($char[$i+1] eq ']') {
6858 0         0 $i++;
6859 0 0       0 }
6860 0         0 while (1) {
6861             if (++$i > $#char) {
6862 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
6863 0         0 }
6864             if ($char[$i] eq ']') {
6865             my $right = $i;
6866 0 0       0  
6867 0         0 # [^...]
  0         0  
6868             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
6869             splice @char, $left, $right-$left+1, sprintf(q{@{[Ewindows1254::charlist_not_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
6870 0         0 }
6871             else {
6872             splice @char, $left, $right-$left+1, Ewindows1254::charlist_not_qr(@char[$left+1..$right-1], $modifier);
6873 0         0 }
6874 0         0  
6875             $i = $left;
6876             last;
6877             }
6878             }
6879             }
6880              
6881 0         0 # rewrite character class or escape character
6882             elsif (my $char = character_class($char[$i],$modifier)) {
6883             $char[$i] = $char;
6884             }
6885              
6886             # P.794 29.2.161. split
6887             # in Chapter 29: Functions
6888             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
6889              
6890             # P.951 split
6891             # in Chapter 27: Functions
6892             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
6893              
6894             # said "The //m modifier is assumed when you split on the pattern /^/",
6895             # but perl5.008 is not so. Therefore, this software adds //m.
6896             # (and so on)
6897              
6898 1         3 # split(m/^/) --> split(m/^/m)
6899             elsif (($char[$i] eq '^') and ($modifier !~ /m/oxms)) {
6900             $modifier .= 'm';
6901             }
6902              
6903 7 0       28 # /i modifier
6904 0         0 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ewindows1254::uc($char[$i]) ne Ewindows1254::fc($char[$i]))) {
6905             if (CORE::length(Ewindows1254::fc($char[$i])) == 1) {
6906             $char[$i] = '[' . Ewindows1254::uc($char[$i]) . Ewindows1254::fc($char[$i]) . ']';
6907 0         0 }
6908             else {
6909             $char[$i] = '(?:' . Ewindows1254::uc($char[$i]) . '|' . Ewindows1254::fc($char[$i]) . ')';
6910             }
6911             }
6912              
6913 0 0       0 # \u \l \U \L \F \Q \E
6914 0         0 elsif ($char[$i] =~ /\A ([<>]) \z/oxms) {
6915             if ($right_e < $left_e) {
6916             $char[$i] = '\\' . $char[$i];
6917             }
6918 0         0 }
6919 0         0 elsif ($char[$i] eq '\u') {
6920             $char[$i] = '@{[Ewindows1254::ucfirst qq<';
6921             $left_e++;
6922 0         0 }
6923 0         0 elsif ($char[$i] eq '\l') {
6924             $char[$i] = '@{[Ewindows1254::lcfirst qq<';
6925             $left_e++;
6926 0         0 }
6927 0         0 elsif ($char[$i] eq '\U') {
6928             $char[$i] = '@{[Ewindows1254::uc qq<';
6929             $left_e++;
6930 0         0 }
6931 0         0 elsif ($char[$i] eq '\L') {
6932             $char[$i] = '@{[Ewindows1254::lc qq<';
6933             $left_e++;
6934 0         0 }
6935 0         0 elsif ($char[$i] eq '\F') {
6936             $char[$i] = '@{[Ewindows1254::fc qq<';
6937             $left_e++;
6938 0         0 }
6939 0         0 elsif ($char[$i] eq '\Q') {
6940             $char[$i] = '@{[CORE::quotemeta qq<';
6941             $left_e++;
6942 0 0       0 }
6943 0         0 elsif ($char[$i] eq '\E') {
6944 0         0 if ($right_e < $left_e) {
6945             $char[$i] = '>]}';
6946             $right_e++;
6947 0         0 }
6948             else {
6949             $char[$i] = '';
6950             }
6951 0         0 }
6952 0 0       0 elsif ($char[$i] eq '\Q') {
6953 0         0 while (1) {
6954             if (++$i > $#char) {
6955 0 0       0 last;
6956 0         0 }
6957             if ($char[$i] eq '\E') {
6958             last;
6959             }
6960             }
6961             }
6962             elsif ($char[$i] eq '\E') {
6963             }
6964              
6965 0 0       0 # $0 --> $0
6966 0         0 elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
6967             if ($ignorecase) {
6968             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6969             }
6970 0 0       0 }
6971 0         0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
6972             if ($ignorecase) {
6973             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6974             }
6975             }
6976              
6977             # $$ --> $$
6978             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
6979             }
6980              
6981             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
6982 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
6983 0 0       0 elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
6984 0         0 $char[$i] = e_capture($1);
6985             if ($ignorecase) {
6986             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6987             }
6988 0         0 }
6989 0 0       0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
6990 0         0 $char[$i] = e_capture($1);
6991             if ($ignorecase) {
6992             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
6993             }
6994             }
6995              
6996 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
6997 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
6998 0         0 $char[$i] = e_capture($1.'->'.$2);
6999             if ($ignorecase) {
7000             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
7001             }
7002             }
7003              
7004 0         0 # $$foo{ ... } --> $ $foo->{ ... }
7005 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
7006 0         0 $char[$i] = e_capture($1.'->'.$2);
7007             if ($ignorecase) {
7008             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
7009             }
7010             }
7011              
7012 0         0 # $$foo
7013 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
7014 0         0 $char[$i] = e_capture($1);
7015             if ($ignorecase) {
7016             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
7017             }
7018             }
7019              
7020 0 50       0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ewindows1254::PREMATCH()
7021 12         36 elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
7022             if ($ignorecase) {
7023             $char[$i] = '@{[Ewindows1254::ignorecase(Ewindows1254::PREMATCH())]}';
7024 0         0 }
7025             else {
7026             $char[$i] = '@{[Ewindows1254::PREMATCH()]}';
7027             }
7028             }
7029              
7030 12 50       60 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ewindows1254::MATCH()
7031 12         32 elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
7032             if ($ignorecase) {
7033             $char[$i] = '@{[Ewindows1254::ignorecase(Ewindows1254::MATCH())]}';
7034 0         0 }
7035             else {
7036             $char[$i] = '@{[Ewindows1254::MATCH()]}';
7037             }
7038             }
7039              
7040 12 50       50 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ewindows1254::POSTMATCH()
7041 9         23 elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
7042             if ($ignorecase) {
7043             $char[$i] = '@{[Ewindows1254::ignorecase(Ewindows1254::POSTMATCH())]}';
7044 0         0 }
7045             else {
7046             $char[$i] = '@{[Ewindows1254::POSTMATCH()]}';
7047             }
7048             }
7049              
7050 9 0       40 # ${ foo }
7051 0         0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} \z/oxms) {
7052             if ($ignorecase) {
7053             $char[$i] = '@{[Ewindows1254::ignorecase(' . $1 . ')]}';
7054             }
7055             }
7056              
7057 0         0 # ${ ... }
7058 0 0       0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
7059 0         0 $char[$i] = e_capture($1);
7060             if ($ignorecase) {
7061             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
7062             }
7063             }
7064              
7065 0         0 # $scalar or @array
7066 3 50       13 elsif ($char[$i] =~ /\A [\$\@].+ /oxms) {
7067 3         17 $char[$i] = e_string($char[$i]);
7068             if ($ignorecase) {
7069             $char[$i] = '@{[Ewindows1254::ignorecase(' . $char[$i] . ')]}';
7070             }
7071             }
7072              
7073 0 50       0 # quote character before ? + * {
7074             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
7075             if ($char[$i-1] =~ /\A (?:[\x00-\xFF]|\\[0-7]{2,3}|\\x[0-9-A-Fa-f]{1,2}) \z/oxms) {
7076 1         8 }
7077             else {
7078             $char[$i-1] = '(?:' . $char[$i-1] . ')';
7079             }
7080             }
7081             }
7082 0         0  
7083 74 50       154 # make regexp string
7084 74         167 $modifier =~ tr/i//d;
7085             if ($left_e > $right_e) {
7086 0         0 return join '', 'Ewindows1254::split', $ope, $delimiter, @char, '>]}' x ($left_e - $right_e), $end_delimiter, $modifier;
7087             }
7088             return join '', 'Ewindows1254::split', $ope, $delimiter, @char, $end_delimiter, $modifier;
7089             }
7090              
7091             #
7092             # escape regexp of split qr''
7093 74     0 0 768 #
7094 0   0       sub e_split_q {
7095             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
7096 0           $modifier ||= '';
7097 0 0          
7098 0           $modifier =~ tr/p//d;
7099 0           if ($modifier =~ /([adlu])/oxms) {
7100 0 0         my $line = 0;
7101 0           for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
7102 0           if ($filename ne __FILE__) {
7103             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
7104             last;
7105 0           }
7106             }
7107             die qq{Unsupported modifier "$1" used at line $line.\n};
7108 0           }
7109              
7110             $slash = 'div';
7111 0 0          
7112 0           # /b /B modifier
7113             if ($modifier =~ tr/bB//d) {
7114             return join '', 'split', $ope, $delimiter, $string, $end_delimiter, $modifier;
7115 0 0         }
7116              
7117             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
7118 0            
7119             # split regexp
7120             my @char = $string =~ /\G((?>
7121             [^\\\[] |
7122             [\x00-\xFF] |
7123             \[\^ |
7124             \[\: (?>[a-z]+) \:\] |
7125             \[\:\^ (?>[a-z]+) \:\] |
7126             \\ (?:$q_char) |
7127             (?:$q_char)
7128             ))/oxmsg;
7129 0            
7130 0 0 0       # unescape character
    0 0        
    0 0        
    0 0        
    0          
    0          
7131             for (my $i=0; $i <= $#char; $i++) {
7132             if (0) {
7133             }
7134 0            
7135 0           # open character class [...]
7136 0 0         elsif ($char[$i] eq '[') {
7137 0           my $left = $i;
7138             if ($char[$i+1] eq ']') {
7139 0           $i++;
7140 0 0         }
7141 0           while (1) {
7142             if (++$i > $#char) {
7143 0 0         die __FILE__, ": Unmatched [] in regexp\n";
7144 0           }
7145             if ($char[$i] eq ']') {
7146             my $right = $i;
7147 0            
7148             # [...]
7149 0           splice @char, $left, $right-$left+1, Ewindows1254::charlist_qr(@char[$left+1..$right-1], $modifier);
7150 0            
7151             $i = $left;
7152             last;
7153             }
7154             }
7155             }
7156              
7157 0           # open character class [^...]
7158 0 0         elsif ($char[$i] eq '[^') {
7159 0           my $left = $i;
7160             if ($char[$i+1] eq ']') {
7161 0           $i++;
7162 0 0         }
7163 0           while (1) {
7164             if (++$i > $#char) {
7165 0 0         die __FILE__, ": Unmatched [] in regexp\n";
7166 0           }
7167             if ($char[$i] eq ']') {
7168             my $right = $i;
7169 0            
7170             # [^...]
7171 0           splice @char, $left, $right-$left+1, Ewindows1254::charlist_not_qr(@char[$left+1..$right-1], $modifier);
7172 0            
7173             $i = $left;
7174             last;
7175             }
7176             }
7177             }
7178              
7179 0           # rewrite character class or escape character
7180             elsif (my $char = character_class($char[$i],$modifier)) {
7181             $char[$i] = $char;
7182             }
7183              
7184 0           # split(m/^/) --> split(m/^/m)
7185             elsif (($char[$i] eq '^') and ($modifier !~ /m/oxms)) {
7186             $modifier .= 'm';
7187             }
7188              
7189 0 0         # /i modifier
7190 0           elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ewindows1254::uc($char[$i]) ne Ewindows1254::fc($char[$i]))) {
7191             if (CORE::length(Ewindows1254::fc($char[$i])) == 1) {
7192             $char[$i] = '[' . Ewindows1254::uc($char[$i]) . Ewindows1254::fc($char[$i]) . ']';
7193 0           }
7194             else {
7195             $char[$i] = '(?:' . Ewindows1254::uc($char[$i]) . '|' . Ewindows1254::fc($char[$i]) . ')';
7196             }
7197             }
7198              
7199 0 0         # quote character before ? + * {
7200             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
7201             if ($char[$i-1] =~ /\A [\x00-\xFF] \z/oxms) {
7202 0           }
7203             else {
7204             $char[$i-1] = '(?:' . $char[$i-1] . ')';
7205             }
7206             }
7207 0           }
7208 0            
7209             $modifier =~ tr/i//d;
7210             return join '', 'Ewindows1254::split', $ope, $delimiter, @char, $end_delimiter, $modifier;
7211             }
7212              
7213             #
7214             # instead of Carp::carp
7215 0     0 0   #
7216 0           sub carp {
7217             my($package,$filename,$line) = caller(1);
7218             print STDERR "@_ at $filename line $line.\n";
7219             }
7220              
7221             #
7222             # instead of Carp::croak
7223 0     0 0   #
7224 0           sub croak {
7225 0           my($package,$filename,$line) = caller(1);
7226             print STDERR "@_ at $filename line $line.\n";
7227             die "\n";
7228             }
7229              
7230             #
7231             # instead of Carp::cluck
7232 0     0 0   #
7233 0           sub cluck {
7234 0           my $i = 0;
7235 0           my @cluck = ();
7236 0           while (my($package,$filename,$line,$subroutine) = caller($i)) {
7237             push @cluck, "[$i] $filename($line) $package::$subroutine\n";
7238 0           $i++;
7239 0           }
7240 0           print STDERR CORE::reverse @cluck;
7241             print STDERR "\n";
7242             print STDERR @_;
7243             }
7244              
7245             #
7246             # instead of Carp::confess
7247 0     0 0   #
7248 0           sub confess {
7249 0           my $i = 0;
7250 0           my @confess = ();
7251 0           while (my($package,$filename,$line,$subroutine) = caller($i)) {
7252             push @confess, "[$i] $filename($line) $package::$subroutine\n";
7253 0           $i++;
7254 0           }
7255 0           print STDERR CORE::reverse @confess;
7256 0           print STDERR "\n";
7257             print STDERR @_;
7258             die "\n";
7259             }
7260              
7261             1;
7262              
7263             __END__