NAME
Parse::Padding -
SYNOPSIS
EXPORTS
Nothing exported by default
DEPENDENCIES
This module requires these other modules and libraries:
Error::Programatic
Perl::Module
Perl::Options
DESCRIPTION
PUBLIC INTERFACE
padding
- Get number of surrounding whitespace characters
-
options:
-crlf Just count surrounding cr/lf characters
Returns an array of widths: ($w1, $w2)
$w1 = Number of preceeding whitespace characters $w2 = Number of trailing whitespace characters
Returns (0, 0) if non-whitespace characters are immediately found in the preceeding or trailing regions.
Returns
undef
if$pos
is less than$[
This example will not abort:
use Parse::Padding qw(padding);
This example:
my $str = " a "; join ';', padding(\$str, 4, 5);
will return:
4;3
This example:
my $str = " \na\r\n "; join ';', padding(\$str, 2, 3);
will return:
2;3
This example:
my $str = " \na\r\n "; join ';', padding(\$str, 2, 3, -crlf);
will return:
1;2
This example:
my $str = " \n\na\r\n\r\n "; join ';', padding(\$str, 3, 4, -crlf);
will return:
1;2
This example:
my $str = " a "; join ';', padding(\$str, 1, 2, -crlf);
will return:
0;0
trailing
- Count trailing characters
-
where:
$chars # characters to count \$text # text to search $begin_index # index within $text to start searching $eol # if true, $chars must be at end-of-line
This example will not abort:
use Parse::Padding qw(trailing);
This example will abort:
# invalid index trailing('\r\n', " xxx\r\n", 'abc');
This example will abort:
# invalid chars trailing('', " xxx\r\n", 4);
This example:
trailing('\s', " xxx \r\n", 4);
will return:
3
This example:
trailing('\r\n', " xxx \r\n", 4);
will return:
0
This example:
trailing('\r\n', " xxx\r\n", 4);
will return:
2
This example:
trailing('\r\n', " xxx\r\n", 999);
will return:
0
This example:
trailing('\r\n', " xxx\r\n", -999);
will return:
0
This example:
trailing('\r\n', "\r\n\r\n", 0, 1);
will return:
2
This example:
trailing('\r\n', "\n\n\n", 0, 1);
will return:
1
This example:
# end-of-string == $eol trailing('abcd', "a\na", 2, 1);
will return:
1
leading
- Count leading characters
-
where:
$chars # characters to count \$text # text to search $begin_index # index within $text to start searching $bol # if true, $chars must be at begin-of-line
This example will not abort:
use Parse::Padding qw(leading);
This example:
leading('\s', " xxx", 1);
will return:
1
This example:
leading('\s', "\r \nxxx", 3);
will return:
3
This example:
leading('\r\n', " xxx", 1);
will return:
0
This example:
leading('\r\n', "\r\n\rxxx", 3);
will return:
3
This example:
leading('\r\n', "\r\n\rxxx", -999);
will return:
0
This example:
leading('\r\n', "\r\n\rxxx", 999);
will return:
0
This example will abort:
# invalid chars leading('', "\r\n\rxxx", 3);
This example will abort:
# invalid index leading('\r\n', "\r\n\rxxx", 'abc');
This example:
# begin-of-string == $bol leading('abcd', "axe", 1, 1);
will return:
1
This example:
leading('abcd', "\naxe", 2, 1);
will return:
1
AUTHORS
Ryan Gies <ryangies@cpan.org>
COPYRIGHT
Copyright (C) 2014-2016 by Ryan Gies. All rights reserved.
Copyright (C) 2006-2013 by Livesite Networks, LLC. All rights reserved.
Copyright (C) 2000-2005 by Ryan Gies. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software in a
product, an acknowledgment in the product documentation would be
appreciated but is not required.
* Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
* The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
To the best of our knowledge, no patented algorithms have been used. However, we
do not have the resources to carry out a patent search, and therefore cannot
give any guarantee of the above statement.