| 1 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use v5.15.7; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | package Regexp::CharClasses::Helper; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Helper for creating user defined character class strings | ||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.005'; # VERSION | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use charnames ':full'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =pod | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =encoding utf8 | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | Regexp::CharClasses::Helper - User defined character class strings by unicode name or literals | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | use Regexp::CharClasses::Helper; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub IsAorPlus { | ||||||||||||||||||||||||||||
| 27 | return Regexp::CharClasses::Helper::fmt( | ||||||||||||||||||||||||||||
| 28 | 'A', | ||||||||||||||||||||||||||||
| 29 | 'LATIN SMALL LETTER A' | ||||||||||||||||||||||||||||
| 30 | '+', | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | say 'matches' if 'A+' =~ /^\p{IsAorPlus}+$/; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub InCapitalsButNot42 { | ||||||||||||||||||||||||||||
| 36 | return Regexp::CharClasses::Helper::fmt( | ||||||||||||||||||||||||||||
| 37 | "+A\tZ", # from A till Z | ||||||||||||||||||||||||||||
| 38 | "-\x42" # except \x42 | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | say "doesn't" if 'ABC' =~ /\p{InCapitalsButNot42}+/; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 METHODS AND ARGUMENTS | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =over 4 | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1101 | ▶ | sub _parse { | ||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 51 | 1101 | ▶ | my $in = $_[0] || $_; | ||||||||||||||||||||||||||
|
Condition66%2/3
$_[0] || $_
MC/DC50%1/2
$_[0] || $_
$_[0]
$_
Truth table66%2/3
A || B
A= $_[0]B= $_
| |||||||||||||||||||||||||||||
| 52 | 1101 | ▶ | croak "Unknown charname '$in'" if $in =~ /^U\+/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 1100 | ▶ | return $in if $in =~ /In|Is|::/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 1100 | ▶ | my $code = length $in == 1 ? ord $in | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | : charnames::vianame $in; | ||||||||||||||||||||||||||||
| 56 | 1100 | ▶ | croak "Unknown charname '$in'" unless defined $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1078 | return sprintf '%04x', $code; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item fmt() | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Takes in a list and turns it into the format specified by L<User-Defined Character Properties|http://perldoc.perl.org/perlunicode.html#User-Defined-Character-Properties> | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 580 | ▶ | sub fmt { | ||||||||||||||||||||||||||
|
Subroutine
fmt: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | return join '', map { | ||||||||||||||||||||||||||||
| 68 | 580 | ▶ | croak 'undef unexpected' unless defined $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 594 | my ($prefix, @out) = ('', $_); | |||||||||||||||||||||||||||
| 70 | 594 | ▶ | if (/^[-+!&]/ && !/^[-+!&]($|\t[^\t]|\t\t$)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^[-+!&]/u and not /^[-+!&]($|\t[^\t]|\t\t$)/u
MC/DC100%2/2
/^[-+!&]/u and not /^[-+!&]($|\t[^\t]|\t\t$)/u
/^[-+!&]/u
not /^[-+!&]($|\t[^\t]|\t\t$)/u
Truth table100%3/3
A and not(B)
A= /^[-+!&]/uB= not /^[-+!&]($|\t[^\t]|\t\t$)/u
| |||||||||||||||||||||||||||||
| 71 | 452 | $out[0] =~ s/^([-+!&])//; | |||||||||||||||||||||||||||
| 72 | 452 | $prefix = $1; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 594 | ▶ | @out = ($1, $2) if $out[0] =~ /^(.+)\t(.+)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 594 | $prefix . join("\t", map {_parse $_} @out) . "\n"; | |||||||||||||||||||||||||||
| 76 | } @_; | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 3 | 1; | |||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||