GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/OptionParser/src/get_argument_list.cpp Lines: 36 36 100.0 %
Date: 2024-12-09 15:30:52 Branches: 32 34 94.1 %

Line Branch Exec Source
1
/***************************************
2
	Auteur : Pierre Aubert
3
	Mail : pierre.aubert@lapp.in2p3.fr
4
	Licence : CeCILL-C
5
****************************************/
6
7
#include "string_function.h"
8
#include "get_argument_list.h"
9
10
11
///Convert the list of given arguments to the program into a list of string
12
/**	@param argc : number of arguments passed to the program
13
 * 	@param argv : table of arguments passed to the program
14
 * 	@return corresponding list of string
15
*/
16
3
std::list<std::string> phoenix_getArgumentList(int argc, char** argv){
17
3
	std::list<std::string> argList;
18
8
	for(int i(0); i < argc; ++i){
19
5
		argList.push_back(std::string(argv[i]));
20
	}
21
3
	return argList;
22
}
23
24
///Check if one of the two passed arguments are in the list of arguments
25
/**	@param listArg : list of arguments given to the program
26
 * 	@param argCheckList : list of argument to be searched
27
 * 	@return true if one element of argCheckList has been found in listArg, false otherwise
28
*/
29
6
bool phoenix_isOptionExist(const std::list<std::string> & listArg, const std::list<std::string> & argCheckList){
30
6
	bool isSearch(true);
31
6
	std::list<std::string>::const_iterator itArg(listArg.begin());
32

16
	while(itArg != listArg.end() && isSearch){
33
10
		std::list<std::string>::const_iterator itCheck(argCheckList.begin());
34

24
		while(itCheck != argCheckList.end() && isSearch){
35
14
			isSearch = *itArg != *itCheck;
36
14
			++itCheck;
37
		}
38
10
		++itArg;
39
	}
40
6
	return !isSearch;
41
}
42
43
///Check if one of the two passed arguments are in the list of arguments
44
/**	@param listArg : list of arguments given to the program
45
 * 	@param arg1 : argument to be searched
46
 * 	@return true if arg1 or arg2 is in listArg, false otherwise
47
*/
48
3
bool phoenix_isOptionExist(const std::list<std::string> & listArg, const std::string & arg1){
49
6
	std::list<std::string> argCheckList;
50
3
	argCheckList.push_back(arg1);
51
6
	return phoenix_isOptionExist(listArg, argCheckList);
52
}
53
54
///Check if one of the two passed arguments are in the list of arguments
55
/**	@param listArg : list of arguments given to the program
56
 * 	@param arg1 : argument to be searched
57
 * 	@param arg2 : argument to be searched
58
 * 	@return true if arg1 or arg2 is in listArg, false otherwise
59
*/
60
3
bool phoenix_isOptionExist(const std::list<std::string> & listArg, const std::string & arg1, const std::string & arg2){
61
6
	std::list<std::string> argCheckList;
62
3
	argCheckList.push_back(arg1);
63
3
	argCheckList.push_back(arg2);
64
6
	return phoenix_isOptionExist(listArg, argCheckList);
65
}
66
67
///Convert the given list of arguement into a string
68
/**	@param listArg : list of argument to be converted into a string
69
 * 	@return corresponding string
70
*/
71
6
std::string phoenix_listArgToString(const std::list<std::string> & listArg){
72
6
	std::string body("");
73
13
	for(std::list<std::string>::const_iterator itArg(listArg.begin()); itArg != listArg.end(); ++itArg){
74

7
		body += phoenix_escapeStr(*itArg, " '\"", "\\") + " ";
75
	}
76
6
	return body;
77
}
78
79
///Get the program call
80
/**	@param listArg : list of argument passed to the program
81
 * 	@return program call, or empty string if list of argument is empty
82
*/
83
6
std::string phoenix_getProgramCall(const std::list<std::string> & listArg){
84
6
	if(listArg.size() != 0lu){return listArg.front();}
85
1
	else{return "";}
86
}
87
88
///Remove the program call from the list of argument
89
/**	@param[out] listArg : list or argument to be modified
90
*/
91
3
void phoenix_rmProgramCall(std::list<std::string> & listArg){
92
3
	if(listArg.size() != 0lu){
93
3
		listArg.pop_front();
94
	}
95
3
}
96
97
98