The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SVG::Rasterize::Regexes - Commonly used regular expressions

VERSION

Version 0.003007

DESCRIPTION

This package offers a set of regular expressions for export. Many of them are precompiled into downstream expressions, therefore changing them would probably not have the desired outcome. Therefore they are also not documented in full detail, see the code for the details.

A versus P

Floating point number expressions are divided into A (for attribute) and P (for property) versions, e.g. $RE_NUMBER{A_FLOAT} and $RE_NUMBER{P_FLOAT}. The reason for that is that apparently, the CSS specification prohibits floating point numbers in scientific notation (e.g. 3e-7). However, the XML standard allows such numbers in attribute values. Currently, however, SVG::Rasterize does not make use of this distinction and always uses the A version. Therefore, it will not complain if you provide a number in scientific notation within a style attribute although strictly, this is forbidden by the specification. This may or may not change in the future.

p, w, and s

The regular expressions from this package might be used to build more complex expressions, but are also used to validate values which should match the expression fully (not a substring). Therefore, some expressions have p (for pure) and w (for white space) versions. If $RE is an expression then $p_RE will be qr/^$RE$/, and $w_RE will be qr/^$WSP*$RE$WSP*$/.

The validation expressions for path data and points lists of polyline and polygon elements also have a s (for start) version. The background is that they are supposed to be rendered up to the erroneous part. If they match fully is only found out when they are split up into parts.

LIST OF EXPRESSIONS

Two expressions are exported directly as scalars, the other ones are organized in a set of hashes:

  • $WSP = qr/[\x{20}\x{9}\x{D}\x{A}]/

    This is one white space character as defined by the SVG specification (inherited from XML I suppose). The character class consists of SPACE, TAB, CR, and LF.

  • $CWSP = qr/(?:$WSP+\,?$WSP*|\,$WSP*)/

    White space or comma, possibly surrounded by white space.

  • %RE_PACKAGE

    Currently, this hash contains only one entry:

        $RE_PACKAGE{p_PACKAGE_NAME} =
            qr/^$package_part(?:\:\:$package_part)*$/;

    where $package_part is a lexical variable with the value qr/[a-zA-Z][a-zA-Z0-9\_]*/.

    Package names given to some methods in this distribution have to match this regular expression. I am not sure which package names exactly are allowed. If you know where in the Perl manpages or the Camel book this is described, please point me to it. If this pattern is too strict for your favourite package name, you can change this variable.

  • %RE_XML

    Expressions for XML Names and Nmtokens, see http://www.w3.org/TR/2006/REC-xml11-20060816/#xml-names. Currently, only the ASCII subset of allowed characters is allowed here because I do not know how to build efficient regular expressions supporting the huge allowed character class.

  • %RE_URI

    Expressions to parse URIs. Largely inspired by an expression given in RFC2396. These expressions can be used to recognize a URI and split it into its pieces, but not for validation. It is enough for now, though.

  • %RE_NUMBER

    Contains expressions for integer and floating point numbers. The reasons for building own regular expressions are that the format is specified in terms of a Backus Naur form in the SVG specification, e.g. here: http://www.w3.org/TR/SVG11/coords.html#TransformAttribute. Note that these expressions allow leading zeroes like '00030' or '000.123'.

  • %RE_LENGTH

    Lengths in SVG consist of a number and optionally a length unit. See Units in SVG::Rasterize.

  • %RE_PAINT

    Expressions for paint attributes (see http://www.w3.org/TR/SVG11/painting.html#SpecifyingPaint).

  • %RE_TRANSFORM

    Regular expressions required to parse values of the transform attribute. These expressions are constructed according to the Backus Naur form at http://www.w3.org/TR/SVG11/coords.html#TransformAttribute.

  • %RE_VIEW_BOX

    Regular expressions required to parse values of the viewBox and preserveAspectRatio attributes.

  • %RE_PATH

    Regular expressions required to parse path data strings. These expressions are constructed according to the Backus Naur form at http://www.w3.org/TR/SVG11/paths.html#PathDataBNF.

  • %RE_DASHARRAY

    Regular expressions required to parse values of the stroke-dasharray property.

  • %RE_POLY

    Regular expressions required to parse values of the points attribute of polyline and polygon elements. These expressions are constructed according to the Backus Naur form at http://www.w3.org/TR/SVG11/shapes.html#PointsBNF.

  • %RE_TEXT

    Regular expressions required to parse values associated with text that have a more complex structure, e.g. the font-size attribute.

EXPORT_TAGS

The following export tags can be used like

  use SVG::Rasterize::Regexes qw(:whitespace);
  • :all

  • :whitespace

    $WSP and $CWSP.

  • :attributes

    %RE_NUMBER, %RE_LENGTH, %RE_PAINT, %RE_TRANSFORM, %RE_VIEW_BOX, %RE_PATH, %RE_DASHARRAY, %RE_POLY.

SEE ALSO

AUTHOR

Lutz Gehlen, <perl at lutzgehlen.de>

LICENSE AND COPYRIGHT

Copyright 2010 Lutz Gehlen.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.