[plug] Re: Another perl question...
David Buddrige
buddrige at wasp.net.au
Thu Nov 21 17:20:07 WST 2002
Mark Haselden writes:
> At 04:21 PM 21/11/2002 +0800, you wrote:
>>levsky at rave.iinet.net.au writes:
>>>On Thu, Nov 21, 2002 at 04:14:34PM +0800, David Buddrige wrote:
>>>So - lemme get this straight - you're wanting to do something like:
>>>/** @doc this @doc that
>>>into
>>>/**
>>>@doc this
>>>@doc that
>>>Right?
>>
>>Yep, that's pretty much it. 8-)
>
> So, will that code do it for you?
>
Here's the final (working) code. I know its still a bit ugly, and it could
still be made more efficient using join etc, but it does the job, and that's
all I need for the moment. Thanks heaps to everyone for their help. 8-)
# This subroutine takes as input a single array reference, and rearranges
any
# doc++ commands that are split over multiple lines so that each doc++
command
# is on a line of its own, including the /** and */ delimiters which
indicate
# the start and end of a doc++ comment.
sub format_docpp_comment
{
my $doc_comment_array;
my $comment_line;
my $single_comment_line;
$doc_comment_array = $_[0]; # give a friendly name to the array
foreach $comment_line ( @$doc_comment_array )
{
my $temp_string;
$temp_string = $comment_line;
chomp $temp_string;
$single_comment_line .= $temp_string;
}
# clear out the contents of the original array so we can
# replace it with the newly formatted text.
foreach ( @$doc_comment_array )
{
pop;
}
# At this point we have a single string that contains our entire doc++
comment.
# we can now use simple pattern matching to parse it.
$single_comment_line =~ s,^\s*/\*\*,,;
$single_comment_line =~ s,\*/\s*$,,;
my $indent=' ';
$single_comment_line =~ s/\s*(@\w+)\s*/\n$indent$1 /gs;
@$doc_comment_array = split ("\n",$single_comment_line);
unshift @$doc_comment_array, "\*\/\n";
push @$doc_comment_array, "\/\*\*";
}
More information about the plug
mailing list