pidl: merge multiple 'genpad' implementations into one.
[kai/samba.git] / pidl / lib / Parse / Pidl / Util.pm
index 006718d139acb819fd245735fdee3cdfc5a9d949..83e23937a87723f89b44d4b85141fbb5acaa9dc9 100644 (file)
@@ -6,7 +6,7 @@ package Parse::Pidl::Util;
 
 require Exporter;
 @ISA = qw(Exporter);
-@EXPORT = qw(has_property property_matches ParseExpr ParseExprExt is_constant make_str unmake_str print_uuid MyDumper);
+@EXPORT = qw(has_property property_matches ParseExpr ParseExprExt is_constant make_str unmake_str print_uuid MyDumper genpad);
 use vars qw($VERSION);
 $VERSION = '0.01';
 
@@ -43,6 +43,7 @@ unless we actually need it
 sub MyDumper($)
 {
        require Data::Dumper;
+       $Data::Dumper::Sortkeys = 1;
        my $s = shift;
        return Data::Dumper::Dumper($s);
 }
@@ -175,6 +176,20 @@ sub ParseExprExt($$$$$)
                $deref, $use);
 }
 
+=item B<genpad>
+return an empty string consisting of tabs and spaces suitable for proper indent
+of C-functions.
+
+=cut
+sub genpad($)
+{
+       my ($s) = @_;
+       my $nt = int((length($s)+1)/8);
+       my $lt = ($nt*8)-1;
+       my $ns = (length($s)-$lt);
+       return "\t"x($nt)." "x($ns);
+}
+
 =back
 
 =cut