Update ooo320-m1
[ooovba.git] / solenv / bin / modules / par2script / converter.pm
blobbef2fddc8fce72948e5edf3a760b754c00bd8bb4
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: converter.pm,v $
11 # $Revision: 1.5 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
33 package par2script::converter;
35 use par2script::remover;
37 #############################
38 # Converter
39 #############################
41 sub convert_array_to_hash
43 my ($arrayref) = @_;
45 my ($line, $key, $value);
47 my %newhash = ();
49 for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
51 $line = ${$arrayref}[$i];
53 if ( $line =~ /^\s*(\w+?)\s+(.*?)\s*$/ )
55 $key = $1;
56 $value = $2;
57 $newhash{$key} = $value;
61 return \%newhash;
64 sub convert_hash_into_array
66 my ($hashref) = @_;
68 my @array = ();
69 my ($key, $value, $input);
71 foreach $key (keys %{$hashref})
73 $value = $hashref->{$key};
74 $input = "$key = $value\n";
75 push(@array ,$input);
78 return \@array
81 sub convert_stringlist_into_array_2
83 my ( $input, $separator ) = @_;
85 my @newarray = ();
86 my $first = "";
87 my $last = "";
89 $last = $input;
91 while ( $last =~ /^\s*(.+?)\s*\Q$separator\E\s*(.+)\s*$/) # "$" for minimal matching
93 $first = $1;
94 $last = $2;
95 par2script::remover::remove_leading_and_ending_whitespaces(\$first);
96 if ( $first ) { push(@newarray, $first); }
99 par2script::remover::remove_leading_and_ending_whitespaces(\$last);
100 if ( $last ) { push(@newarray, $last); }
102 return \@newarray;
105 sub convert_stringlist_into_array
107 my ( $includestringref, $separator ) = @_;
109 my @newarray = ();
110 my ($first, $last);
112 $last = ${$includestringref};
114 while ( $last =~ /^\s*(.+?)\s*\Q$separator\E\s*(.+)\s*$/) # "$" for minimal matching
116 $first = $1;
117 $last = $2;
118 par2script::remover::remove_leading_and_ending_whitespaces(\$first);
119 push(@newarray, $first);
122 par2script::remover::remove_leading_and_ending_whitespaces(\$last);
123 push(@newarray, $last);
125 return \@newarray;
128 #############################################################################
129 # The file name contains for some files "/". If this programs runs on
130 # a windows platform, this has to be converted to "\".
131 #############################################################################
133 sub convert_slash_to_backslash
135 my ($filesarrayref) = @_;
137 my ($onefile, $filename);
139 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
141 $onefile = ${$filesarrayref}[$i];
142 $onefile->{'Name'} =~ s/\//\\/g;