line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Goo::TabConverter; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
############################################################################### |
6
|
|
|
|
|
|
|
# Nigel Hamilton |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
9
|
|
|
|
|
|
|
# All Rights Reserved |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
12
|
|
|
|
|
|
|
# Filename: Goo::TabConverter.pm |
13
|
|
|
|
|
|
|
# Description: Convert tab characters to four spaces |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Date Change |
16
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
# 27/09/2005 Version 1 |
18
|
|
|
|
|
|
|
# 15/10/2005 Created test file: TabConverterTest.tpm |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
############################################################################### |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
2910
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
167
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#use Smart::Comments; |
25
|
|
|
|
|
|
|
my $default_tab_size = 4; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
############################################################################### |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# tabs_to_spaces - turn any tabs into the right number of characters |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
############################################################################### |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub tabs_to_spaces { |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
0
|
1
|
|
my ($line, $tab_size) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
0
|
|
|
|
$tab_size = $tab_size || $default_tab_size; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $tab_count = 0; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $new_line; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
foreach my $character (split(//, $line)) { |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
### is this a tab char |
46
|
0
|
0
|
|
|
|
|
if ($character =~ /\t/) { |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
### replace the tab with the number of space up to the next tab stop |
49
|
0
|
|
|
|
|
|
$character = ' ' x ($tab_size - $tab_count); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
### we've now filled up a complete tab stop |
52
|
0
|
|
|
|
|
|
$tab_count = $tab_size; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
### increment the tab_count |
57
|
0
|
|
|
|
|
|
$tab_count++; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ($tab_count >= $tab_size) { |
60
|
0
|
|
|
|
|
|
$tab_count = 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
### append the character to the line |
64
|
0
|
|
|
|
|
|
$new_line .= $character; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return $new_line; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Goo::TabConverter - Convert tab characters to four spaces |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SYNOPSIS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
use Goo::TabConverter; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 METHODS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item tabs_to_spaces |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
turn any tabs into n characters |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHOR |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
102
|
|
|
|
|
|
|
|