1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27
28
29package par2script::converter;
30
31use par2script::remover;
32
33#############################
34# Converter
35#############################
36
37sub convert_array_to_hash
38{
39	my ($arrayref) = @_;
40
41	my ($line, $key, $value);
42
43	my %newhash = ();
44
45	for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
46	{
47		$line = ${$arrayref}[$i];
48
49		if ( $line =~ /^\s*(\w+?)\s+(.*?)\s*$/ )
50		{
51			$key = $1;
52			$value = $2;
53			$newhash{$key} = $value;
54		}
55	}
56
57	return \%newhash;
58}
59
60sub convert_hash_into_array
61{
62	my ($hashref) = @_;
63
64	my @array = ();
65	my ($key, $value, $input);
66
67	foreach $key (keys %{$hashref})
68	{
69		$value = $hashref->{$key};
70		$input = "$key = $value\n";
71		push(@array ,$input);
72	}
73
74	return \@array
75}
76
77sub convert_stringlist_into_array_2
78{
79	my ( $input, $separator ) = @_;
80
81	my @newarray = ();
82	my $first = "";
83	my $last = "";
84
85	$last = $input;
86
87	while ( $last =~ /^\s*(.+?)\s*\Q$separator\E\s*(.+)\s*$/)	# "$" for minimal matching
88	{
89		$first = $1;
90		$last = $2;
91		par2script::remover::remove_leading_and_ending_whitespaces(\$first);
92		if ( $first ) { push(@newarray, $first); }
93	}
94
95	par2script::remover::remove_leading_and_ending_whitespaces(\$last);
96	if ( $last ) { push(@newarray, $last); }
97
98	return \@newarray;
99}
100
101sub convert_stringlist_into_array
102{
103	my ( $includestringref, $separator ) = @_;
104
105	my @newarray = ();
106	my ($first, $last);
107
108	$last = ${$includestringref};
109
110	while ( $last =~ /^\s*(.+?)\s*\Q$separator\E\s*(.+)\s*$/)	# "$" for minimal matching
111	{
112		$first = $1;
113		$last = $2;
114		par2script::remover::remove_leading_and_ending_whitespaces(\$first);
115		push(@newarray, $first);
116	}
117
118	par2script::remover::remove_leading_and_ending_whitespaces(\$last);
119	push(@newarray, $last);
120
121	return \@newarray;
122}
123
124#############################################################################
125# The file name contains for some files "/". If this programs runs on
126# a windows platform, this has to be converted to "\".
127#############################################################################
128
129sub convert_slash_to_backslash
130{
131	my ($filesarrayref) = @_;
132
133	my ($onefile, $filename);
134
135	for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
136	{
137		$onefile = ${$filesarrayref}[$i];
138		$onefile->{'Name'} =~ s/\//\\/g;
139	}
140}
141
1421;
143