1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24
25package par2script::converter;
26
27use par2script::remover;
28
29#############################
30# Converter
31#############################
32
33sub convert_array_to_hash
34{
35	my ($arrayref) = @_;
36
37	my ($line, $key, $value);
38
39	my %newhash = ();
40
41	for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
42	{
43		$line = ${$arrayref}[$i];
44
45		if ( $line =~ /^\s*(\w+?)\s+(.*?)\s*$/ )
46		{
47			$key = $1;
48			$value = $2;
49			$newhash{$key} = $value;
50		}
51	}
52
53	return \%newhash;
54}
55
56sub convert_hash_into_array
57{
58	my ($hashref) = @_;
59
60	my @array = ();
61	my ($key, $value, $input);
62
63	foreach $key (keys %{$hashref})
64	{
65		$value = $hashref->{$key};
66		$input = "$key = $value\n";
67		push(@array ,$input);
68	}
69
70	return \@array
71}
72
73sub convert_stringlist_into_array_2
74{
75	my ( $input, $separator ) = @_;
76
77	my @newarray = ();
78	my $first = "";
79	my $last = "";
80
81	$last = $input;
82
83	while ( $last =~ /^\s*(.+?)\s*\Q$separator\E\s*(.+)\s*$/)	# "$" for minimal matching
84	{
85		$first = $1;
86		$last = $2;
87		par2script::remover::remove_leading_and_ending_whitespaces(\$first);
88		if ( $first ) { push(@newarray, $first); }
89	}
90
91	par2script::remover::remove_leading_and_ending_whitespaces(\$last);
92	if ( $last ) { push(@newarray, $last); }
93
94	return \@newarray;
95}
96
97sub convert_stringlist_into_array
98{
99	my ( $includestringref, $separator ) = @_;
100
101	my @newarray = ();
102	my ($first, $last);
103
104	$last = ${$includestringref};
105
106	while ( $last =~ /^\s*(.+?)\s*\Q$separator\E\s*(.+)\s*$/)	# "$" for minimal matching
107	{
108		$first = $1;
109		$last = $2;
110		par2script::remover::remove_leading_and_ending_whitespaces(\$first);
111		push(@newarray, $first);
112	}
113
114	par2script::remover::remove_leading_and_ending_whitespaces(\$last);
115	push(@newarray, $last);
116
117	return \@newarray;
118}
119
120#############################################################################
121# The file name contains for some files "/". If this programs runs on
122# a windows platform, this has to be converted to "\".
123#############################################################################
124
125sub convert_slash_to_backslash
126{
127	my ($filesarrayref) = @_;
128
129	my ($onefile, $filename);
130
131	for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
132	{
133		$onefile = ${$filesarrayref}[$i];
134		$onefile->{'Name'} =~ s/\//\\/g;
135	}
136}
137
1381;
139