tizen beta release
[framework/web/wrt-installer.git] / src / wrt-installer / option_parser.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    option_parser.cpp
18  * @author  Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  * @brief   Implementation file for OptionParser.
20  */
21
22 #include <vector>
23 #include <algorithm>
24 #include <dpl/string.h>
25 #include "option_parser.h"
26
27 DPL::OptionalString OptionParser::QueryOption(int argc,
28                                               char* argv[],
29                                               const std::string& name)
30 {
31     DPL::OptionalString result;
32
33     std::vector<std::string> args(argv, (argv + argc));
34
35     auto it = std::find_if(args.begin(),
36                            args.end(),
37                            [&name](const std::string& option){
38                                 return (option == name);
39                            });
40
41     if (it != args.end())
42     {
43         std::string value;
44         while ((++it != args.end()) && !IsOption(*it))
45         {
46             value += *it + " ";
47         }
48         result = DPL::FromUTF8String(value);
49     }
50
51     return result;
52 }
53
54 bool OptionParser::IsOption(const std::string& name)
55 {
56     return (name.find('-') == 0);
57 }